diff --git a/pkg/bootstrap/isogen/command.go b/pkg/bootstrap/isogen/command.go index adbf19f4a..6b42eb440 100644 --- a/pkg/bootstrap/isogen/command.go +++ b/pkg/bootstrap/isogen/command.go @@ -71,13 +71,15 @@ func GenerateBootstrapIso(settings *environment.AirshipCTLSettings, args []strin func verifyInputs(cfg *config.Bootstrap) error { if cfg.Container.Volume == "" { - log.Print("Specify volume bind for ISO builder container") - return config.ErrWrongConfig{} + return config.ErrMissingConfig{ + What: "Must specify volume bind for ISO builder container", + } } if (cfg.Builder.UserDataFileName == "") || (cfg.Builder.NetworkConfigFileName == "") { - log.Print("UserDataFileName or NetworkConfigFileName are not specified in ISO builder config") - return config.ErrWrongConfig{} + return config.ErrMissingConfig{ + What: "UserDataFileName or NetworkConfigFileName are not specified in ISO builder config", + } } vols := strings.Split(cfg.Container.Volume, ":") @@ -85,8 +87,9 @@ func verifyInputs(cfg *config.Bootstrap) error { case len(vols) == 1: cfg.Container.Volume = fmt.Sprintf("%s:%s", vols[0], vols[0]) case len(vols) > 2: - log.Print("Bad container volume format. Use hostPath:contPath") - return config.ErrWrongConfig{} + return config.ErrInvalidConfig{ + What: "Bad container volume format. Use hostPath:contPath", + } } return nil } diff --git a/pkg/bootstrap/isogen/command_test.go b/pkg/bootstrap/isogen/command_test.go index be6ca95a0..ac81f9b45 100644 --- a/pkg/bootstrap/isogen/command_test.go +++ b/pkg/bootstrap/isogen/command_test.go @@ -130,26 +130,49 @@ func TestVerifyInputs(t *testing.T) { defer cleanup(t) tests := []struct { + name string cfg *config.Bootstrap args []string expectedErr error }{ { + name: "missing-container-field", cfg: &config.Bootstrap{ Container: &config.Container{}, }, - expectedErr: config.ErrWrongConfig{}, + expectedErr: config.ErrMissingConfig{ + What: "Must specify volume bind for ISO builder container", + }, }, { + name: "missing-filenames", cfg: &config.Bootstrap{ Container: &config.Container{ Volume: tempVol + ":/dst", }, Builder: &config.Builder{}, }, - expectedErr: config.ErrWrongConfig{}, + expectedErr: config.ErrMissingConfig{ + What: "UserDataFileName or NetworkConfigFileName are not specified in ISO builder config", + }, }, { + name: "invalid-host-path", + cfg: &config.Bootstrap{ + Container: &config.Container{ + Volume: tempVol + ":/dst:/dst1", + }, + Builder: &config.Builder{ + UserDataFileName: "user-data", + NetworkConfigFileName: "net-conf", + }, + }, + expectedErr: config.ErrInvalidConfig{ + What: "Bad container volume format. Use hostPath:contPath", + }, + }, + { + name: "success", cfg: &config.Bootstrap{ Container: &config.Container{ Volume: tempVol, @@ -161,22 +184,13 @@ func TestVerifyInputs(t *testing.T) { }, expectedErr: nil, }, - { - cfg: &config.Bootstrap{ - Container: &config.Container{ - Volume: tempVol + ":/dst:/dst1", - }, - Builder: &config.Builder{ - UserDataFileName: "user-data", - NetworkConfigFileName: "net-conf", - }, - }, - expectedErr: config.ErrWrongConfig{}, - }, } for _, tt := range tests { - actualErr := verifyInputs(tt.cfg) - assert.Equal(t, tt.expectedErr, actualErr) + tt := tt + t.Run(tt.name, func(subTest *testing.T) { + actualErr := verifyInputs(tt.cfg) + assert.Equal(subTest, tt.expectedErr, actualErr) + }) } } diff --git a/pkg/config/errors.go b/pkg/config/errors.go index a46338cd3..e86c9bc38 100644 --- a/pkg/config/errors.go +++ b/pkg/config/errors.go @@ -60,12 +60,13 @@ func (e ErrBootstrapInfoNotFound) Error() string { return fmt.Sprintf("Bootstrap info %q not found", e.Name) } -// ErrWrongConfig returned in case of incorrect configuration -type ErrWrongConfig struct { +// ErrInvalidConfig returned in case of incorrect configuration +type ErrInvalidConfig struct { + What string } -func (e ErrWrongConfig) Error() string { - return "Wrong configuration" +func (e ErrInvalidConfig) Error() string { + return fmt.Sprintf("Invalid configuration: %s", e.What) } // ErrMissingConfig returned in case of missing configuration