Skip to content

Commit

Permalink
Extract common validate user config
Browse files Browse the repository at this point in the history
Fix test errors and non-checked nil error return vals
  • Loading branch information
jdsutherland committed Jan 2, 2019
1 parent e5c47fe commit ff65f76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
15 changes: 4 additions & 11 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ type submitContext struct {
}

func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
if err := validateUserConfig(cfg.UserViperConfig); err != nil {
return err
}

ctx, err := newSubmitContext(cfg.UserViperConfig, flags, args)
if err != nil {
return err
Expand Down Expand Up @@ -92,17 +96,6 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {

// newSubmitContext creates a submitContext, sanitizing given args.
func newSubmitContext(usrCfg *viper.Viper, flags *pflag.FlagSet, args []string) (*submitContext, error) {
if usrCfg.GetString("token") == "" {
return nil, fmt.Errorf(
msgWelcomePleaseConfigure,
config.SettingsURL(usrCfg.GetString("apibaseurl")),
BinaryName,
)
}
if usrCfg.GetString("workspace") == "" {
return nil, fmt.Errorf(msgRerunConfigure, BinaryName)
}

ctx := &submitContext{usrCfg: usrCfg, flags: flags, args: args}
return ctx, ctx.sanitizeArgs()
}
Expand Down
1 change: 1 addition & 0 deletions cmd/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func TestSubmitFilesAndDir(t *testing.T) {
tmpDir,
filepath.Join(tmpDir, "file-2.txt"),
}

err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), files)
if assert.Error(t, err) {
assert.Regexp(t, "submitting a directory", err.Error())
Expand Down

0 comments on commit ff65f76

Please sign in to comment.