Skip to content

Commit

Permalink
adjust newapp/newbuild error messages (arg classification vs. actual …
Browse files Browse the repository at this point in the history
…processing
  • Loading branch information
gabemontero committed Jan 24, 2018
1 parent cf406ea commit a6e71b7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/generate/app/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type ErrNoMatch struct {

func (e ErrNoMatch) Error() string {
if len(e.Qualifier) != 0 {
return fmt.Sprintf("no match for %q: %s", e.Value, e.Qualifier)
return fmt.Sprintf("unable to locate resource for %q: %s", e.Value, e.Qualifier)
}
return fmt.Sprintf("no match for %q", e.Value)
return fmt.Sprintf("unable to locate resource for %q", e.Value)
}

// Suggestion is the usage error message returned when no match is found.
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func handleError(err error, baseName, commandName, commandPath string, config *n
// this print serves as a header for the printing of the errorGroups, but
// only print it if we precede with classification errors, to help distinguish
// between the two
fmt.Fprintln(buf, "Errors occurred during resource creation:")
fmt.Fprintf(buf, "Errors occurred during %s processing of arguments:\n", commandName)
}
for _, group := range groups {
fmt.Fprint(buf, kcmdutil.MultipleErrors("error: ", group.errs))
Expand Down
8 changes: 8 additions & 0 deletions pkg/oc/generate/app/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,17 @@ func (c *AppConfig) AddArguments(args []string) []string {

switch {
case c.tryToAddEnvironmentArguments(s):
// does not update c.ArgumentClassificationErrors
case c.tryToAddSourceArguments(s):
// successful with first classification attempt
case c.tryToAddComponentArguments(s):
// clear out any errors noted for source classification as we are successful with component
// classification
c.ArgumentClassificationErrors = []ArgumentClassificationError{}
case c.tryToAddTemplateArguments(s):
// clear out any errors noted for source/component classification as we are successful with template
// classification
c.ArgumentClassificationErrors = []ArgumentClassificationError{}
default:
glog.V(2).Infof("treating %s as unknown\n", s)
unknown = append(unknown, s)
Expand Down
15 changes: 7 additions & 8 deletions test/cmd/newapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ os::cmd::expect_success 'oc delete is myruby'
os::cmd::expect_failure_and_text 'oc new-app https://github.com/openshift/nodejs-ex --strategy=docker' 'No Dockerfile was found'

# repo related error message validation
os::cmd::expect_failure_and_text 'oc new-app mysql-persisten mysql' 'mysql-persisten as a local directory'
os::cmd::expect_failure_and_text 'oc new-app mysql-persisten mysql' 'mysql as a local directory'
os::cmd::expect_failure_and_text 'oc new-app --strategy=docker https://192.30.253.113/openshift/ruby-hello-world.git' 'as a Git repository URL: '
os::cmd::expect_failure_and_text 'oc new-app https://www.google.com/openshift/nodejs-e' 'as a Git repository URL: '
os::cmd::expect_failure_and_text 'oc new-app https://examplegit.com/openshift/nodejs-e' 'as a Git repository URL: '
os::cmd::expect_failure_and_text 'oc new-build --strategy=docker https://192.30.253.113/openshift/ruby-hello-world.git' 'as a Git repository URL: '
os::cmd::expect_failure_and_text 'oc new-build https://www.google.com/openshift/nodejs-e' 'as a Git repository URL: '
os::cmd::expect_failure_and_text 'oc new-build https://examplegit.com/openshift/nodejs-e' 'as a Git repository URL: '
os::cmd::expect_failure_and_text 'oc new-app mysql-persisten mysql' 'only a partial match was found'
os::cmd::expect_failure_and_text 'oc new-app --strategy=docker https://192.30.253.113/openshift/ruby-hello-world.git' 'only a partial match was found'
os::cmd::expect_failure_and_text 'oc new-app https://www.google.com/openshift/nodejs-e' 'unable to lo'
os::cmd::expect_failure_and_text 'oc new-app https://examplegit.com/openshift/nodejs-e' 'unable to lo '
os::cmd::expect_failure_and_text 'oc new-build --strategy=docker https://192.30.253.113/openshift/ruby-hello-world.git' '--strategy is specified and none of the arguments provided could be classified as a source code location'
os::cmd::expect_failure_and_text 'oc new-build https://www.google.com/openshift/nodejs-e' 'unable to lo'
os::cmd::expect_failure_and_text 'oc new-build https://examplegit.com/openshift/nodejs-e' 'unable to lo'

# setting source secret via the --source-secret flag
os::cmd::expect_success_and_text 'oc new-app https://github.com/openshift/cakephp-ex --source-secret=mysecret -o yaml' 'name: mysecret'
Expand Down
2 changes: 1 addition & 1 deletion test/integration/newapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestNewAppResolve(t *testing.T) {
},
},
})},
expectedErr: `no match for "mysql:invalid`,
expectedErr: `unable to locate resource for "mysql:invalid`,
},
{
name: "Successful mysql builder",
Expand Down

0 comments on commit a6e71b7

Please sign in to comment.