Commit Graph

1302 Commits

Author SHA1 Message Date
dr.max 32470ac256 fix(bug) correct response for unknown command or plugin fixes(#309) (#322)
```bash
➜  client git:(issue309) ✗ ./kn lol
Manage your Knative building blocks:
* Serving: Manage your services and release new software to them.
* Eventing: Manage event subscriptions and channels. Connect up event sources.

Usage:
...
Use "kn [command] --help" for more information about a command.

unknown sub-command or plugin "lol" for "kn"
```
2019-08-05 01:44:55 -07:00
dr.max 759734d473 Adds Navid (@navidshaikh) to approvers list (#321)
Unanimous vote from current approvers on 07/30/2019

Congrats Navid!
2019-07-31 13:59:43 -07:00
Gong Zhang 8fbb51f92a Report an error if no flag(s) set in service update (#318)
For now if no flag(s) set, service update will still try to
do an update, it should return an error instead.

[issue 286](https://github.com/knative/client/issues/286)
2019-07-31 13:49:44 -07:00
chaodaiG 9f203f2d4d Use knative.dev/test-infra (#319) 2019-07-31 03:20:43 -07:00
Roland Huß 71c39e822d feature(testing): Introduce a mock implementation for KnClient (#306)
* feature(testing): Introduce a Mock implementation for KnClient

Commands must only use the `KnClient` API and their unit tests should also
only use a mock implementation for this interface.

This commit introduces such a Mock implementation and works like in
the example below for creating a simple service in a synchronous
way

```
// New mock client
	client := knclient.NewMockKnClient(t)

	// Recording:
	r := client.Recorder()
	// Check for existing service --> no
	r.GetService("foo", nil, errors.NewNotFound(v1alpha1.Resource("service"), "foo"))
	// Create service (don't validate given service --> "Any()" arg is allowed)
	r.CreateService(knclient.Any(), nil)
	// Wait for service to become ready
	r.WaitForService("foo", knclient.Any(), nil)
	// Get for showing the URL
	r.GetService("foo", getServiceWithUrl("foo", "http://foo.example.com"), nil)

	// Testing:
	output, err := executeCommand(client, "create", "foo", "--image", "gcr.io/foo/bar:baz")
	assert.NilError(t, err)
	assert.Assert(t, util.ContainsAll(output, "created", "foo", "http://foo.example.com", "Waiting"))

	// Validate that all recorded API methods have been called
	r.Validate()
```

Such tests have three phases:

* A recording phase where the mock client is prepared. In this phase a
  recorder is called with the expected arguments and the return values
  it can return. The arguments can be also functions with
  signature `func (t *testing.T, actual interface{}, expected interface{})`
  and will be called to verify a given argument. Such a function should
  `t.Fail()` on its own if the validation fails.
  A convenient `Any()` method is added to allow no validation on an argument
  (see example below).
  Method can be called multiple times, but the order needs to reflect
  the actual calling order
* A playback phase where the test executed which in turn calls out to the
  Mocks
* A validation phase to check the expected output. The recorder can be
  also validated to verify that all recorded mock calls has been
  used during the test.

  See `service_create_mock_test.go` for a full example.

* chore: Test the mock client

* chore: Minor fixes

* chore: Cosmetic fixes
2019-07-30 17:51:42 -07:00
Roland Huß f797fba41b chore(tests): Update latest released version of serving to 0.7.1 (#304) 2019-07-29 11:56:05 -07:00
Martin Gencur b98e45e721 Restructure E2E test suite (#307)
* Restructure E2E test suite

* move out more tests from the basic workflow and put them in separate
files, including tests for routes
* rename revision_workflow_test.go to revision_test.go

* Run all tests in parallel
2019-07-29 06:00:05 -07:00
Naomi Seyfer 34f123c23a Boolean flags by presence (#283) 2019-07-26 17:15:50 -07:00
Roland Huß 7d1594dc1f fix: Fix error when no current namespace is set (#305)
When no current namespace is set in the config file, then using `kn` without -n fails:

```
invalid configuration: no configuration has been provided
```

Instead of failing in this case, assume the default namespace "namespace"
2019-07-26 15:10:49 -07:00
dr.max 59b2855d04 Implements Kn plugins re-using some code from kubectl plugins. (#249)
This version contains the following:

1. wraps the main root Kn command to support plugin
2. plugins are any executable in kn's config new pluginDir
   variable which defaults to $PATH
3. plugins must have name kn-*
4. 'kn plugin list' sub-command to list found kn plugins
5. skips any kn plugins found with name that match core
   commands, e.g., kn-service would be ignored
6. can execute any valid kn plugins found, e.g.,
   `kn valid` where the plugin file `kn-valid` is in path
   specified in 2.
7. unit tests (using gotest.tools)

And is missing:

1. integration tests
2. plugin install command
3. plugin repository command
4. plugin / Knative server version negotiation
5. anything else we agree on in plugin req doc

I plan to create issues for the things missing so we don't
end up with an even bigger PR. It's already big as is but is a
good MVP as per plugins requirement doc.
2019-07-26 13:29:48 -07:00
Navid Shaikh df816e63fe test(service): Add e2e tests for min, max scale options (#300)
* test(service): Add e2e tests for min, max scale options

 add e2e tests for min, max scale options for `service create` and
 `service update` operations.

* Provision in tests for jsonpath to lookup old and new fields
2019-07-26 13:02:49 -07:00
Navid Shaikh 152305f334 improves(e2e): Updates concurrency tests (#302)
- updates the validation of concurrency limits/targets with upcoming change to `service describe` output
 - validation commands now returns specific field in output than returning complete output
 - Renames service name used from hello to svc1
 - Provision in tests for jsonpath to lookup old and new fields
 - Consolidate once used helper method into test itself, as its checking for very specific test-case
2019-07-26 12:04:48 -07:00
Martin Gencur 03ecb36440 Add E2E tests for Service, Revision, Route (#291)
* Add E2E tests for Service, revision, route

* service, revision, route describe and describe with print flags
* route list with print flags
* service create for a duplicate service

* Test serviceDeleteNonexistent and fixes
2019-07-25 23:46:43 -07:00
Naomi Seyfer 93a9610cb7 Move client conventions doc from Serving, adjusted to account for revision names (#299) 2019-07-25 14:57:37 -07:00
Tsubasa Nagasawa b7808b0fa2 Validate scale and container concurrency options when updating configuration resource (#279)
* Validate invalid container concurrency options

* Use assert package

* Use FlagSet.Changed and don't care about default values

* Update dependency

* Follow e2e test changes

* Return error if invalid value is specified by users

* Fix broken e2e test

* Add more unit tests

* Fix error message

* Fix comment statement

* Revert back unrelated changes

* Fix typo
2019-07-25 02:57:35 -07:00
dr.max 9513dedfba Improves(e2e): imrpoves integration tests and to better run locally (#274)
1. refactors basic workflow (move code to common)
2. use different namespace accross test runs to isolate
3. include wait logic in CreateNamespace to allow multiple runs
4. include wait logic in DeleteNamespace to allow multiple runs

This is important since we need more integration tests and some of
these changes should allow `./test/e2e-tests-local.sh` to run on
local clusters (minikube or something other than test-infra) and
correctly behave during mutiple runs.
2019-07-23 10:13:34 -07:00
Roland Huß 75a41def4e chore(revision): Remove unwanted log message in test (#267)
* chore(revision): Remove bogus log message

This showed up in the test run as single log message so I removed that.

* chore(revision): Revert back to wrong API group in test as its unrelated to this PR
2019-07-22 12:00:35 -07:00
Roland Huß 34992aa5a9 chore(build): Refactor to simplify and add dedicated test mode (#268)
Rearranged script a bit to make easier to understand the various run
modes.
Added a `--test` mode which will only run the tests
2019-07-22 11:29:35 -07:00
Roland Huß 875e8da2a5 feature(service): Wait on update for service to become ready. (#271)
* feature(service): Wait on update for service to become ready.

The behaviour is now the same as for `kn service create`. This should also fix some flakiness in the tests again.

* chore: Fixed changelog

* chore(service): Adapt help message for update

* fix(test): Updated renamed method
2019-07-22 10:52:35 -07:00
Adriano Cunha 144ccb875e Point release documentation to knative/test-infra (#281) 2019-07-19 15:52:31 -07:00
Naomi Seyfer 8c27978855 Command conventions doc (#270)
* Command conventions doc copied from https://docs.google.com/document/d/1Or3f51EIrdyuwlJ9IfhQdoe7F7WrjsUPEPa0Ijsv2go/edit#

* Update with comments
2019-07-19 14:11:31 -07:00
Naomi Seyfer 8d7d227785 Rename accessors to be less like methods that get from the server (#275) 2019-07-18 23:19:28 -07:00
Zida (Edward) 0b348d7441 Support multi config files (#222)
* Handle error for multi config files over `--kubeconfig` flag

* Add test cases for multi configs

* Refactor type cases
2019-07-17 02:21:27 -07:00
Roland Huß 55073029b4 fix(build): Minor build optimizations (#265)
* Check that every generated file has been regenerated for CI
* No color when not on a tty which is useful for build logs
* Always do updates when called without args
* Removed -u option and added -c for codegen only (dep update, docs gen, formatting, license check)
2019-07-15 13:21:27 -07:00
Tsubasa Nagasawa fca0a09e86 Clean up e2e test assertion (#264)
* Clean up e2e test assertion

Heavily rely on assert package as well as unit tests

* Iterate over a line for ensuring valid output

* Use subtests for easily spotting the error location
2019-07-15 04:41:26 -07:00
Evan Anderson be24f7b89d Hide completion command from help. (#263) 2019-07-12 15:55:47 -07:00
Tsubasa Nagasawa 406ecd182d Add e2e tests for service with concurrency options (#256)
* Add e2e tests for service with concurrency options

Check the behaviour of creating/updating service with concurrency options

* Move tests into separate test file and fix neats

* Use assert package for error check

* Change test function name
2019-07-12 10:24:41 -07:00
Jordan 385f848cbc add route describe feature and test (#251) 2019-07-12 05:06:37 -07:00
Roland Huß 9fb6a436e8 chore(wait): Fixes for Smoke Tests + help messages (#250)
* Increase wait timeout to 240s (to avoid test failures like in https://storage.googleapis.com/knative-prow/pr-logs/pull/knative_client/244/pull-knative-client-integration-tests-latest-release/1148472118510358531/build-log.txt)
* Fixed duplicate default help message for `kn service create --help`
2019-07-10 13:36:12 -07:00
Roland Huß e1614f95e6 fix(service update): Retry an update in case of a conflict. (#240)
* fix(service update): Retry an update in case of a conflict.

Is related to #224 and should fix one flake.

* chore(service): Fixed retry-loop for kn service create/update
2019-07-10 11:18:10 -07:00
Roland Huß 9f62341dcf fix: Update root docs for removing Build reference. (#244) 2019-07-10 10:48:14 -07:00
Roland Huß 26fb47c1d6 fix(service): Show URL (external) instead of Address (internal) when listing service (#247)
* fix(service): Pick up new field Address instead of Domain when listing service

Starting with 0.7.0 old fields are not populated anymore. Let's switch to the new fields then.

This fix should work with 0.6.0, too as the new fields already have been populated back then.

So we can unconditionally pick status.address.url which is accordance with
our policy to support the latest release and the release before.

Fixes #246.

* fix(service list): Use status.URL instead of status.Address in column

* chore: Rebase and update changelog

* chore: Rebase and test fix
2019-07-10 09:23:09 -07:00
savitaashture 3eb6e41751 get a particular service and revision based on name parameter (#150) 2019-07-10 02:39:05 -07:00
Navid Shaikh 08c6cf33e3 Adds Github issue and pull request templates (#242)
* Adds Github issue and pull request templates

  We might need to add few labels for knative/client repo as mentioned
  in the template.

* Adds nightly build reference and swap client and serving section

* Asks user to paste output of kn version in bug report template
2019-07-10 00:36:03 -07:00
Roland Huß d01e715082 chore(changelog): Add a changelog.adoc (#241)
and added features for 0.2.0
2019-07-09 14:58:57 -07:00
dr.max 9e29ce893f test(commands): backfills gotest.tools tests for version & completion cmds (#223) 2019-07-09 11:44:55 -07:00
Roland Huß 2ae037f3be refactor(service): Removed io.writer from of KnClient.WaitForService() (#248)
This puts all the console output to the command, where it belongs too.
One could add a ProgressHandler for more fine granular feedback (like suggested in #234) but for now this is not needed.
2019-07-08 11:57:34 -07:00
Roland Huß 98184eafbc refactor(serving): KnClient interface for single point of cluster access (#134)
* fix(serving): Remove hardcoded GVK and look it up from schema

Fixes #133.

* chore(serving): Add test for "WaitForService()"

* refactor(service): Add listRoutes() to client + generic way for list options

* chore(serving): Fixing rebase conflicts
2019-07-08 10:08:34 -07:00
Joan Edwards 0cbc4e1b18 Bulleted components in kn.md (#243) 2019-07-08 03:25:33 -07:00
Navid Shaikh 389a7592bc Adds step to simplify code along with goimports (#239)
(and gofmt if goimports isn't available)

 - Runs goimports on all packages except vendor dir and filter on only *.go files

 - Runs gofmt on all dirs except vendor and filters on *.go files, also writes the results instead of printing diff

 - Fixes typo s/insteat/insead

 - Adds the changes after adding simply code step in hack/build.sh

 - Uses source_dir var specifying the dirs to work on

 - Combines gofmt commands into single command
2019-07-08 03:17:33 -07:00
Joan Edwards 314be82e0a Correct minor grammatical issue (#238) 2019-07-07 23:48:33 -07:00
Joan Edwards ca90232c9a Small grammatical correction for README.md (#237)
* Small grammatical correction for README.md

* Update README.md
2019-07-07 23:41:33 -07:00
Ashleigh Brennan 38a4a6fc18 Added link to OpenShift kubeconfig creation docs (#226) 2019-07-06 00:43:31 -07:00
Navid Shaikh fc9b24c1e5 Add custom comparison for checking multiple substrings (#227)
* Adds custom comparison for checking multiple substrings

 This changeset introduces custom comparison for checking if a target
 string has given multiple substrings, namely `ContainsMultipleSubstrings`.

 Also removes `commands.TestContains` function and replaces all references
 of `commands.TestContains` with `gotest.tools/assert.Check` function and
 uses `ContainsMultipleSubstrings` as comparison function.

* Renames and makes the compare function variadic

 New name: ContainsAll
 New location: pkg/util/compare.go
 Also the function now takes target string as first arg,
 and accepts any number of substrings to check.
 Removed the message arg, the compare function composes the error message.
 For eg:
```
        Actual output: foo-abcd   foo       <unknown>   0 OK / 0     <unknown>   <unknown>
        Missing strings: foo-abcd1, foo1
```

* Adds tests for compare utility ContainsAll

* Update vendor/modules.txt
2019-07-05 10:07:32 -07:00
Roland Huß 2db1195b3f fix(release.sh): Point to proper directory to extract the serving version (#221)
The argument to build_flags.sh must point to the basedirectory where
go.mod is located.

Fixes #212
2019-07-03 01:47:32 -07:00
dr.max 500b7d1371 fixes(issue #111) generically for all command groups (#218)
Explores all sub-commands from root and adds a RunE for all
commands that are groups with child commands and without a RunE.
The added RunE will return the correct errors when the command
is called with empty sub-command or with an unknown sub-command.
It will also print the command help message first.

Added a gotest.tools test for root.go.
2019-07-02 23:50:32 -07:00
Roland Huß d51a3a8d91 fix(serving): Fix logic 'service create --force' and some bogus tests (#216)
* fix(servicing): Fix logic 'service create --force' and some bogus tests

Now a more meaningful error is returned when the user tries to create
a service that already exists. Until know the service is tried
to be created even if the client already knows that it exists.

Also some broken (broken in the sense that the test was nonsense) tests has been fixed.

* chore(serving): Use constant instead of string lateral in test
2019-07-02 12:19:32 -07:00
Navid Shaikh aac0ec265e Adds kn route list command (#202)
- Accepts an argument name for listing particular route
- Enables the machine readable output flags
- Updates docs for kn route command group
- Adds unit tests for route command group and route list
- Adds integration tests for route list in basic workflow test
- Updates tests and getting namespace
- Adds more unit tests for code in pkg/kn/commands/route/list_flags.go
- Adds route list command in smoke tests
- Updates vendor/modules.txt
- Clean up imports
- Addresses review comments
 - replaces knative to Knative
 - uses reflect.DeepEqual for slice comparison
 - removes few code comments
 - removes irrelevant tests modifications from the PR
2019-07-02 11:25:32 -07:00
Navid Shaikh e431ba2d54 Removes pausing between e2e smoke tests (#220)
* Removes pausing between e2e smoke tests

 Removes time.Sleep as by default service create waits for it to
 become ready. Also adds a command to create service in --async mode.

* Checks if service create in async mode is ready

 also describes the async mode service and finally deletes it
2019-07-02 03:31:31 -07:00
Navid Shaikh eb53a6f999 Exchange SERVICE and NAME column in kn revision list output (#219)
* Exchange SERVICE and NAME column in kn revision list output

 Fixes #195

* Uses serving.ServiceLableKey instead of serving.ConfigurationLabelKey
2019-07-01 08:50:19 -07:00