Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(service update): Print success message after successful update #169

Merged
merged 2 commits into from
Jun 17, 2019

Conversation

rhuss
Copy link
Contributor

@rhuss rhuss commented Jun 7, 2019

No description provided.

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jun 7, 2019
@knative-prow-robot knative-prow-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 7, 2019
@rhuss
Copy link
Contributor Author

rhuss commented Jun 7, 2019

Hmm, I really don't understand how test coverage could decrease with this PR:

  • I added 1 line and removed 2 in code
  • The new line is always teste also by existing tests
  • I added a new assertion (but that doesn't count to coverage, I know)

But no idea how @knative-metrics-robots measure coverage. Nevertheless, I question the result.

Copy link
Collaborator

@navidshaikh navidshaikh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rhuss
Copy link
Contributor Author

rhuss commented Jun 7, 2019

But no idea how @knative-metrics-robots measure coverage. Nevertheless, I question the result.

Ok, I see. Because I removed also two lines which were already covered, therefore the coverage dropped

c        c-2
--  >    ----
t        t-2

is true as along t > c.

@@ -55,19 +56,19 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
}
service = service.DeepCopy()

err = editFlags.Apply(service, cmd)
if err != nil {
if err = editFlags.Apply(service, cmd); err != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont think we are switching to the collapsed style judging by the rest of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point, shouldn't touch existing code for good (aka better) reasons.

@@ -108,6 +109,10 @@ func TestServiceUpdateImage(t *testing.T) {
} else if template.Spec.DeprecatedContainer.Image != "gcr.io/foo/quux:xyzzy" {
t.Fatalf("wrong image set: %v", template.Spec.DeprecatedContainer.Image)
}

if !strings.Contains(output, "update") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well test fuller message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will anchor on some more keywords here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhuss why no just expect what is being printed "Service '...' updated in namespace ..."?

Copy link
Contributor Author

@rhuss rhuss Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I want to focus on the important context provided by an error message, not on the exact wording. That's why I don't do == assert on error/success messages. That also helps me in focussing on what should be contained in good messages:

  • All context available at that point in code (i.e. the input parameters of the method)
  • A suggestion how to get over an error (if its an error message)
  • Keyword of what has happened, reflecting the action performed ("update").

Side effect: Your tests become more robust as they don't depend on the exact wording and whether there is a comma or not (except you insist on that). In TDD world you would first write the test with the things you would expect to be included in the message, and then write the message. Not write the message first and just blindly check for it (that test doesn't hasn't much expressiveness anyway)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhuss one of the important aspects of a test is readability. personally i dont find following code readable because its intent is not clear. it also ends up more fragile as it may produce false positives.

	if !strings.Contains(strings.ToLower(output), "update") ||
		!strings.Contains(output, "foo") ||
		!strings.Contains(strings.ToLower(output), "service") ||
		!strings.Contains(strings.ToLower(output), "namespace") ||
		!strings.Contains(output, "bar") {
		t.Fatalf("wrong or no success message: %s", output)
	}

however preferred style of these types of assertions is quite subjective so i wont dwell on it too much.

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/service/service_update.go 75.0% 76.0% 1.0

@rhuss
Copy link
Contributor Author

rhuss commented Jun 14, 2019

@cppforlife Anything else missing for this PR to get merged ?

@cppforlife
Copy link

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 17, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cppforlife, navidshaikh, rhuss

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 17, 2019
@knative-prow-robot knative-prow-robot merged commit 8a1d412 into knative:master Jun 17, 2019
maximilien pushed a commit to maximilien/client that referenced this pull request Jun 17, 2019
…native#169)

* fix(service update): Print success message after successful update

* chore(service update): Improve test, revert unneeded changes
maximilien added a commit to maximilien/client that referenced this pull request Jun 17, 2019
Implements Kn plugins re-using some code from kubectl plugins.
This is WIP to allow concrete discussions and testing and
hopefully also allow sub tasks to be created and worked on
in parallel.

This version contains the following:

1. wraps the main root Kn command to support plugin
2. plugins are any executable in PATH with name kn-*
3. 'kn plugins list' to list found kn plugins
4. skips any kn plugins found with name that match core
   commands, e.g., kn-service would be ignored
5. execute any valid kn plugins found

And is missing:

1. unit and 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

Adds a Golang version of e2e Basic workflow that can execute locally (knative#121)

1. creates a namespace 'kne2etests' (default name, change with env KN_E2E_NAMESPACE)
2. executes kn commands as per Basic workflow doc in said namespace
3. verifies each command's output
4. deletes the 'kne2etests' namespace

Fix typo in README.md (knative#181)

Renames service 'get' to 'list' (knative#179)

* Renames service 'get' to 'list'

 As per title.

* Renames get references to list in e2e tests

* Replaces get to list in docs

Renames revision 'get' to 'list' (knative#180)

* Renames revision 'get' to 'list'

 As per title.

* Renames revision get references to revision list in docs

feat(build.sh) - Add mandatory license check (knative#187)

We could decide to make that optional, too, if this is coming into the way.

Chore: Fix typos in docs (knative#178)

fix(service update): Print success message after successful update (knative#169)

* fix(service update): Print success message after successful update

* chore(service update): Improve test, revert unneeded changes

[WIP] Kn plugins implementation

Implements Kn plugins re-using some code from kubectl plugins.
This is WIP to allow concrete discussions and testing and
hopefully also allow sub tasks to be created and worked on
in parallel.

This version contains the following:

1. wraps the main root Kn command to support plugin
2. plugins are any executable in PATH with name kn-*
3. 'kn plugins list' to list found kn plugins
4. skips any kn plugins found with name that match core
   commands, e.g., kn-service would be ignored
5. execute any valid kn plugins found
6. started adding UTs for plugin commands and files
7. rebased with latest HEAD

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
@rhuss rhuss deleted the pr/update-success-message branch March 9, 2021 10:32
dsimansk pushed a commit to dsimansk/client that referenced this pull request Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants