From 80f7f341bbfc1e1df03f3eed0adbbaf54e285084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Tue, 8 Oct 2019 12:40:40 +0200 Subject: [PATCH 1/3] chore(test): Add a ContainsAllIgnoreCase helper method (#433) --- pkg/util/compare.go | 17 +++++++++++++++++ pkg/util/compare_test.go | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/pkg/util/compare.go b/pkg/util/compare.go index 2c90b4a109..252cc21737 100644 --- a/pkg/util/compare.go +++ b/pkg/util/compare.go @@ -39,6 +39,23 @@ func ContainsAll(target string, substrings ...string) cmp.Comparison { } } +// Like ContainsAll but ignores the case when checking +func ContainsAllIgnoreCase(target string, substrings ...string) cmp.Comparison { + return func() cmp.Result { + var missing []string + lTarget := strings.ToLower(target) + for _, sub := range substrings { + if !strings.Contains(lTarget, strings.ToLower(sub)) { + missing = append(missing, sub) + } + } + if len(missing) > 0 { + return cmp.ResultFailure(fmt.Sprintf("\nActual output (lower-cased): %s\nMissing strings (lower-cased): %s", lTarget, strings.ToLower(strings.Join(missing[:], ", ")))) + } + return cmp.ResultSuccess + } +} + // ContainsNone is a comparison utility, compares given substrings against // target string and returns the gotest.tools/assert/cmp.Comaprison function. // Provide target string as first arg, followed by any number of substring as args diff --git a/pkg/util/compare_test.go b/pkg/util/compare_test.go index 9cb9f7341d..04c1f49496 100644 --- a/pkg/util/compare_test.go +++ b/pkg/util/compare_test.go @@ -62,15 +62,47 @@ func TestContainsAll(t *testing.T) { success: true, }, } { - comparison := ContainsAll(tc.target, tc.substrings...) - result := comparison() + result := ContainsAll(tc.target, tc.substrings...)() if result.Success() != tc.success { t.Errorf("%d: Expecting %s to contain %s", i, tc.target, tc.substrings) } if !tc.success { message := fmt.Sprintf("\nActual output: %s\nMissing strings: %s", tc.target, strings.Join(tc.missing[:], ", ")) if !reflect.DeepEqual(result, cmp.ResultFailure(message)) { - t.Errorf("%d: Incorrect error message returned\nExpecting: %s", i, message) + t.Errorf("%d: Incorrect error message returned\nGot: %v\nExpecting: %s", i, result, message) + } + } + } +} + +func TestContainsIgnoreCase(t *testing.T) { + for i, tc := range []containsAllTestCase{ + { + target: "NAME SERVICE AGE CONDITIONS READY REASON", + substrings: []string{"reason", "age"}, + success: true, + }, + { + "No resources found.", + []string{"NAME", "AGE"}, + false, + []string{"name", "age"}, + }, + { + "NAME SERVICE AGE CONDITIONS READY REASON", + []string{"name", "url", "domain", "ready"}, + false, + []string{"url", "domain"}, + }, + } { + result := ContainsAllIgnoreCase(tc.target, tc.substrings...)() + if result.Success() != tc.success { + t.Errorf("%d: Expecting %s to contain %s", i, tc.target, tc.substrings) + } + if !tc.success { + message := fmt.Sprintf("\nActual output (lower-cased): %s\nMissing strings (lower-cased): %s", strings.ToLower(tc.target), strings.ToLower(strings.Join(tc.missing[:], ", "))) + if !reflect.DeepEqual(result, cmp.ResultFailure(message)) { + t.Errorf("%d: Incorrect error message returned\n. Got: %v\nExpecting: %s", i, result, message) } } } From e67d207d3b1c8c1f6df2e2126193a99d86371425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Tue, 8 Oct 2019 13:34:38 +0200 Subject: [PATCH 2/3] chore(build.sh) Add indicator in watch mode after successful compilation (#432) * chore(build.sh) Add indicator in watch mode after successful compilation * chore(build): Update changelog --- CHANGELOG.adoc | 3 +++ hack/build.sh | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 8b8ee96267..feb98b9a04 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -70,6 +70,9 @@ | Add --annotation flag | https://github.com/knative/client/pull/422[#422] +| 🎁 +| Update build.sh -w to add a message when compilation succeeded +| https://github.com/knative/client/pull/432[#432] |=== ## v0.2.0 (2019-07-10) diff --git a/hack/build.sh b/hack/build.sh index 900bd4638c..37d559033a 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -222,7 +222,7 @@ watch() { set -e echo "🔁 Watch" - fswatch $fswatch_opts | xargs -n1 -I{} $command + fswatch $fswatch_opts | xargs -n1 -I{} sh -c "$command && echo 👌 OK" } # Dir where this script is located From 8ec74e686a23c3f4b9308f9f1b9a2b39817714ab Mon Sep 17 00:00:00 2001 From: Joan Edwards <42442393+joaedwar@users.noreply.github.com> Date: Tue, 8 Oct 2019 13:00:40 +0100 Subject: [PATCH 3/3] Minor grammar corrections (#435) --- docs/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index ca1fde40e0..6b68691a2a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -34,21 +34,21 @@ You'll need a `kubectl`-style config file to connect to your cluster. ## Kn Config -To better customize kn there is a set of configuration parameters you are able to setup and customize. In particular you can specify where your kn plugins are located and how they are found. The kn configuration file is meant to capture these configuration options. Let's explore this file's location, and the options you are able to change with it. +There are a set of configuration parameters you can setup to better customize `kn`. In particular, you can specify where your `kn` plugins are located and how they are found. The `kn` configuration file is meant to capture these configuration options. Let's explore this file's location, and the options you are able to change with it. ### Location -The default location kn looks for config is under the home directory of user at `$HOME/.kn/config.yaml`. It is not created for you part of Kn installation. You can create this file elsewhere and use `--config` flag to specify its path. +The default location `kn` looks for config is under the home directory of the user at `$HOME/.kn/config.yaml`. It is not created for you as part of the `kn` installation. You can create this file elsewhere and use the `--config` flag to specify its path. ### Options -There are two options you can specify in the kn config file and they are related to how kn locates plugins. +There are two options you can specify in the `kn` config file and they are related to how `kn` locates plugins. -1. `pluginsDir` which is the same as the persistent flag `--plugins-dir` and specifies the kn plugins directory. It defaults to: `~/.kn/plugins`. By using the persistent flag (when you issue a command) or by specifying the value in the kn config, a user can select which directory to find kn plugins. It can be any directory that is visible to the user. +1. `pluginsDir` which is the same as the persistent flag `--plugins-dir` and specifies the kn plugins directory. It defaults to: `~/.kn/plugins`. By using the persistent flag (when you issue a command) or by specifying the value in the `kn` config, a user can select which directory to find `kn` plugins. It can be any directory that is visible to the user. -2. `lookupPluginsInPath` which is the same as the persistent flag `--lookup-plugins-in-path` and specficies if kn should look for plugins anywhere in the specified `PATH` environment variable.This is a boolean configuration option and the default value is `false`. +2. `lookupPluginsInPath` which is the same as the persistent flag `--lookup-plugins-in-path` and specficies if `kn` should look for plugins anywhere in the specified `PATH` environment variable. This is a boolean configuration option and the default value is `false`. -For example, the following kn config will look for kn plugins in the user's `PATH` and also execute plugin in `~/.kn/plugins`. +For example, the following `kn` config will look for `kn` plugins in the user's `PATH` and also execute plugin in `~/.kn/plugins`. ```bash cat ~/.kn/config.yaml