Skip to content

Commit

Permalink
Fix for file not found error message discrepancy in windows (knative#…
Browse files Browse the repository at this point in the history
…1575) (knative#967)

* Fix for file not found error message discrepancy in windows

* Added comment

Co-authored-by: Gunjan Vyas <[email protected]>
  • Loading branch information
dsimansk and vyasgun authored Feb 17, 2022
1 parent 29f05fe commit e43a9fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion test/e2e/service_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"path/filepath"
"testing"

"gotest.tools/v3/assert/cmp"

"gotest.tools/v3/assert"

"knative.dev/client/lib/test"
Expand Down Expand Up @@ -124,11 +126,20 @@ func serviceCreateFromFile(r *test.KnRunResultCollector, serviceName, filePath s
func serviceCreateFromFileError(r *test.KnRunResultCollector, serviceName, filePath string) {
out := r.KnTest().Kn().Run("service", "create", serviceName, "--filename", filePath)
r.AssertError(out)
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stderr, "no", "such", "file", "directory", filePath))
assert.Check(r.T(), fileNotFoundErrorCheck(out, filePath))
}

func serviceCreateFromFileNameMismatch(r *test.KnRunResultCollector, serviceName, filePath string) {
out := r.KnTest().Kn().Run("service", "create", serviceName, "--filename", filePath)
r.AssertError(out)
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stderr, "provided", "'"+serviceName+"'", "name", "match", "from", "file"))
}

func fileNotFoundErrorCheck(out test.KnRunResult, filePath string) cmp.Comparison {
result := util.ContainsAllIgnoreCase(out.Stderr, "no", "such", "file", "directory", filePath)
if result() == cmp.ResultSuccess {
return result
}
// Check for Windows specific error message in case file is not found
return util.ContainsAllIgnoreCase(out.Stderr, "system", "cannot", "find", "file", "specified", filePath)
}
2 changes: 1 addition & 1 deletion test/e2e/service_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ func serviceImportExistsError(r *test.KnRunResultCollector, filename string) {
func serviceImportFileError(r *test.KnRunResultCollector, filePath string) {
out := r.KnTest().Kn().Run("service", "import", filePath)
r.AssertError(out)
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stderr, "no", "such", "file", "directory", filePath))
assert.Check(r.T(), fileNotFoundErrorCheck(out, filePath))
}

0 comments on commit e43a9fb

Please sign in to comment.