Skip to content

Commit

Permalink
[release-v1.1.0] Add upstream fixes
Browse files Browse the repository at this point in the history
Fix for file not found error message discrepancy in windows (knative#1575) (knative#967)

Co-authored-by: Gunjan Vyas <[email protected]>

change display versions (knative#1601) (knative#985)

Co-authored-by: kobayashi <[email protected]>
  • Loading branch information
dsimansk and kobayashi committed Mar 29, 2022
1 parent 1264d7c commit a542316
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
19 changes: 14 additions & 5 deletions hack/build-flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function build_flags() {
rev="$(git rev-parse --short HEAD)"
local pkg="knative.dev/client/pkg/kn/commands/version"
local version="${TAG:-}"
local major_minor="$(echo "${version}" | cut -f1-2 -d. -n)"
# Use vYYYYMMDD-local-<hash> for the version string, if not passed.
if [[ -z "${version}" ]]; then
# Get the commit, excluding any tags but keeping the "dirty" flag
Expand All @@ -27,13 +28,21 @@ function build_flags() {
[[ -n "${commit}" ]] || abort "error getting the current commit"
version="v$(date +%Y%m%d)-local-${commit}"
fi
# Extract Eventing and Serving versions from go.mod
local version_serving version_eventing
version_serving=$(grep "knative.dev/serving " "${base}/go.mod" \
# For Eventing and Serving versionings,
# major and minor versions are the same as client version
# patch version is from each technical version
technical_version_serving=$(grep "knative.dev/serving " "${base}/go.mod" \
| sed -s 's/.* \(v.[\.0-9]*\).*/\1/')
version_eventing=$(grep "knative.dev/eventing " "${base}/go.mod" \
technical_version_eventing=$(grep "knative.dev/eventing " "${base}/go.mod" \
| sed -s 's/.* \(v.[\.0-9]*\).*/\1/')

local version_serving version_eventing
if [[ -n "${major_minor}" ]]; then
version_serving=${major_minor}.$(echo ${technical_version_serving} |cut -f3 -d.)
version_eventing=${major_minor}.$(echo ${technical_version_eventing} |cut -f3 -d.)
else
version_serving="${technical_version_serving}"
version_eventing="${technical_version_eventing}"
fi
echo "-X '${pkg}.BuildDate=${now}' \
-X ${pkg}.Version=${version} \
-X ${pkg}.GitRevision=${rev} \
Expand Down
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 a542316

Please sign in to comment.