* Use assert.NoError instead of assert.Nil
This gives nicer error messages.
* Swap arguments to assert.Equal
The expectation comes first. Otherwise, error messages will be
misleading.
An example:
=== RUN TestDeleteWithIncorrectRepoForDeleteCaches
Error: authentication token not found for host github.com
delete_test.go:56:
Error Trace: /build/source/cmd/delete_test.go:56
Error: Should be true
Test: TestDeleteWithIncorrectRepoForDeleteCaches
Messages: 1 unmatched mocks: https://api.github.com/repos/testOrg/testRepo/actions/caches?key=cacheName
delete_test.go:59:
Error Trace: /build/source/cmd/delete_test.go:59
Error: Not equal:
expected: "authentication token not found for host github.com"
actual : "The given repo does not exist."
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-authentication token not found for host github.com
+The given repo does not exist.
Test: TestDeleteWithIncorrectRepoForDeleteCaches
--- FAIL: TestDeleteWithIncorrectRepoForDeleteCaches (0.00s)
* Use assert.Error instead of assert.NotNil
This gives nicer error messages.
* Use assert.ErrorAs and assert.ErrorContains
This simplifies the assertions and potentially gives better error
messages.
* Use require instead of assert and use assert.NotNil as guard
This is to prevent panics in tests, when things get accessed which
shouldn't be nil.