diff --git a/main.go b/main.go index 7fc5fbc..a8bc95c 100644 --- a/main.go +++ b/main.go @@ -173,8 +173,7 @@ func initFlags(flag *pflag.FlagSet) { flag.BoolP(flagVerbose, "v", false, "Print section lines") } -func checkConfig(v *viper.Viper) error { - +func checkRegion(v *viper.Viper) error { region := v.GetString(flagAWSRegion) if len(region) == 0 { return errors.Wrap(&errInvalidRegion{Region: region}, fmt.Sprintf("%q is invalid", flagAWSRegion)) @@ -187,6 +186,16 @@ func checkConfig(v *viper.Viper) error { return fmt.Errorf("%s is invalid: %w", flagAWSRegion, &errInvalidRegion{Region: region}) } + return nil +} + +func checkConfig(v *viper.Viper) error { + + err := checkRegion(v) + if err != nil { + return err + } + logLevel := strings.ToLower(v.GetString(flagLogLevel)) if len(logLevel) > 0 { valid := false diff --git a/main_test.go b/main_test.go index 562d6af..f2d37c5 100644 --- a/main_test.go +++ b/main_test.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "log" "os" + "testing" "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/spf13/viper" @@ -45,14 +46,14 @@ func (suite *cliTestSuite) TestCheckRegion() { } for _, testValue := range testValues { suite.viper.Set(flagAWSRegion, testValue) - suite.NoError(checkConfig(suite.viper)) + suite.NoError(checkRegion(suite.viper)) } testValuesWithErrors := []string{ "AnyOtherRegionName", } for _, testValue := range testValuesWithErrors { suite.viper.Set(flagAWSRegion, testValue) - suite.Error(checkConfig(suite.viper)) + suite.Error(checkRegion(suite.viper)) } } @@ -63,3 +64,7 @@ func (suite *cliTestSuite) SetViper(v *viper.Viper) { func (suite *cliTestSuite) SetLogger(logger *log.Logger) { suite.logger = logger } + +func TestCLISuite(t *testing.T) { + suite.Run(t, &cliTestSuite{}) +}