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

lint: Add testifylint to prevent unnecessary test code issues #1813

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

Matovidlo
Copy link
Contributor

@Matovidlo Matovidlo commented Jun 4, 2024

Jira: PSGO-682

Changes:

  • Add testifylint to prevent unnecessary test code issues (require/assert).

@Matovidlo Matovidlo force-pushed the lint-add-testifylint-linter branch 2 times, most recently from 25b8a7f to e5a0e34 Compare June 6, 2024 06:25
@Matovidlo Matovidlo requested a review from michaljurecko June 14, 2024 08:53
Comment on lines -25 to 34
assert.NoError(t, projectState.Set(branchState))
require.NoError(t, projectState.Set(branchState))

d := NewDiffer(projectState)
results, err := d.Diff()
assert.NoError(t, err)
require.NoError(t, err)
assert.Len(t, results.Results, 1)
result := results.Results[0]
assert.Equal(t, ResultOnlyInLocal, result.State)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes it makes sense for the test to continue, so you get the overall picture and you don't have to run the test repeatedly.

I prefer to use assert and require only when there is no point in continuing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should you continue when err is not nil? If yes then use if assert.NoError(t, err); err != nil { } Otherwise it makes sense. I don't see anything else just a plain help to prevent unnecessary panics in test code. When you do not care about error, just omit it using _

@Matovidlo Matovidlo force-pushed the lint-add-testifylint-linter branch from 65d07ab to f305538 Compare November 22, 2024 09:58
Copy link

Templates API Kubernetes Diff [CI]

Between base 392b793 ⬅️ head f766f90.

Expand
--- /tmp/artifacts/test-k8s-state.old.json.processed.kv	2024-11-22 12:48:36.419878086 +0000
+++ /tmp/artifacts/test-k8s-state.new.json.processed.kv	2024-11-22 12:48:36.651878699 +0000
@@ -194 +194 @@
-<Deployment/templates-api>.spec.template.spec.containers[0].image = "docker.io/keboola/templates-api:849e4bf-1732279046";
+<Deployment/templates-api>.spec.template.spec.containers[0].image = "docker.io/keboola/templates-api:f766f90-1732279361";
@@ -747,3 +747,3 @@
-<Pod/templates-api-<hash>>.spec.containers[0].image = "docker.io/keboola/templates-api:849e4bf-1732279046";
-<Pod/templates-api-<hash>>.spec.containers[0].image = "docker.io/keboola/templates-api:849e4bf-1732279046";
-<Pod/templates-api-<hash>>.spec.containers[0].image = "docker.io/keboola/templates-api:849e4bf-1732279046";
+<Pod/templates-api-<hash>>.spec.containers[0].image = "docker.io/keboola/templates-api:f766f90-1732279361";
+<Pod/templates-api-<hash>>.spec.containers[0].image = "docker.io/keboola/templates-api:f766f90-1732279361";
+<Pod/templates-api-<hash>>.spec.containers[0].image = "docker.io/keboola/templates-api:f766f90-1732279361";
@@ -1417 +1417 @@
-<ReplicaSet/templates-api-<hash>>.spec.template.spec.containers[0].image = "docker.io/keboola/templates-api:849e4bf-1732279046";
+<ReplicaSet/templates-api-<hash>>.spec.template.spec.containers[0].image = "docker.io/keboola/templates-api:f766f90-1732279361";
@@ -1488,0 +1489,12 @@
+<Secret/sh.helm.release.v1.templates-api-etcd.v2> = {};
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.apiVersion = "v1";
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.data = {};
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.kind = "Secret";
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.metadata = {};
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.metadata.labels = {};
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.metadata.labels.name = "templates-api-etcd";
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.metadata.labels.owner = "helm";
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.metadata.labels.version = "2";
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.metadata.name = "sh.helm.release.v1.templates-api-etcd.v2";
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.metadata.namespace = "templates-api";
+<Secret/sh.helm.release.v1.templates-api-etcd.v2>.type = "helm.sh/release.v1";


(see artifacts in the Github Action for more information)

@Matovidlo Matovidlo marked this pull request as ready for review November 22, 2024 13:00
@Matovidlo Matovidlo merged commit ce32001 into main Nov 25, 2024
13 checks passed
@Matovidlo Matovidlo deleted the lint-add-testifylint-linter branch November 25, 2024 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants