From e43a9fbd9815ea34a105bd7c156eaf1769c1b6fa Mon Sep 17 00:00:00 2001 From: David Simansky Date: Thu, 17 Feb 2022 13:24:00 +0100 Subject: [PATCH] Fix for file not found error message discrepancy in windows (#1575) (#967) * Fix for file not found error message discrepancy in windows * Added comment Co-authored-by: Gunjan Vyas --- test/e2e/service_file_test.go | 13 ++++++++++++- test/e2e/service_import_test.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/test/e2e/service_file_test.go b/test/e2e/service_file_test.go index 2b30717fa2..67de276174 100644 --- a/test/e2e/service_file_test.go +++ b/test/e2e/service_file_test.go @@ -24,6 +24,8 @@ import ( "path/filepath" "testing" + "gotest.tools/v3/assert/cmp" + "gotest.tools/v3/assert" "knative.dev/client/lib/test" @@ -124,7 +126,7 @@ 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) { @@ -132,3 +134,12 @@ func serviceCreateFromFileNameMismatch(r *test.KnRunResultCollector, serviceName 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) +} diff --git a/test/e2e/service_import_test.go b/test/e2e/service_import_test.go index 5f37f805d0..536c4ccfb3 100644 --- a/test/e2e/service_import_test.go +++ b/test/e2e/service_import_test.go @@ -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)) }