1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-16 05:16:08 +02:00

Remove assert.Error right before assert.EqualError (#2344)

Is there any benefit from having

```
assert.Error(./.)
assert.EqualError(./.)
```

?

assert.Error ensures that we have an error.
assert.EqualError ensures that we have an error and
moreover it checks for a specific error. Hence
assert.EqualError does all and more what assert.Error
does.

In case there is a benefit from that pattern this PR should not be merged.
In case there is not benefit from that pattern  we should abandong that pattern.
This commit is contained in:
Marcus Holl 2020-11-11 14:14:55 +01:00 committed by GitHub
parent 51c63c9da1
commit 56586cae1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 23 deletions

View File

@ -40,7 +40,6 @@ func TestBuildRegistryPlusImage(t *testing.T) {
ContainerRegistryURL: "//myregistry.com/registry/containers",
ContainerImageNameTag: "myFancyContainer:1337",
})
assert.Error(t, err)
assert.EqualError(t, err, "registry URL could not be extracted: invalid registry url")
})
}
@ -74,7 +73,6 @@ func TestBuildRegistryPlusImageWithoutTag(t *testing.T) {
ContainerRegistryURL: "//myregistry.com/registry/containers",
ContainerImageNameTag: "myFancyContainer:1337",
})
assert.Error(t, err)
assert.EqualError(t, err, "registry URL could not be extracted: invalid registry url")
})
}
@ -202,7 +200,6 @@ func TestRunGitopsUpdateDeploymentWithKubectl(t *testing.T) {
runnerMock := &gitOpsExecRunnerMock{}
err := runGitopsUpdateDeployment(&configuration, runnerMock, gitUtilsMock, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, "missing required fields for kubectl: the following parameters are necessary for kubectl: [containerName]")
})
@ -211,7 +208,6 @@ func TestRunGitopsUpdateDeploymentWithKubectl(t *testing.T) {
runner := &gitOpsExecRunnerMock{failOnRunExecutable: true}
err := runGitopsUpdateDeployment(validConfiguration, runner, &gitUtilsMock{}, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, "error on kubectl execution: failed to apply kubectl command: failed to apply kubectl command: error happened")
})
@ -302,7 +298,6 @@ func TestRunGitopsUpdateDeploymentWithInvalid(t *testing.T) {
}
err := runGitopsUpdateDeployment(configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, "tool invalid is not supported")
})
}
@ -415,7 +410,6 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) {
configuration.ContainerRegistryURL = "://myregistry.com"
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, `failed to apply helm command: failed to extract registry URL, image name, and image tag: registry URL could not be extracted: invalid registry url: parse "://myregistry.com": missing protocol scheme`)
})
@ -425,7 +419,6 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) {
configuration.ChartPath = ""
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, "missing required fields for helm: the following parameters are necessary for helm: [chartPath]")
})
@ -435,7 +428,6 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) {
configuration.DeploymentName = ""
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, "missing required fields for helm: the following parameters are necessary for helm: [deploymentName]")
})
@ -446,7 +438,6 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) {
configuration.ChartPath = ""
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, "missing required fields for helm: the following parameters are necessary for helm: [chartPath deploymentName]")
})
@ -456,7 +447,6 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) {
configuration.ContainerImageNameTag = "registry/containers/myFancyContainer:"
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, "failed to apply helm command: failed to extract registry URL, image name, and image tag: tag could not be extracted")
})
@ -466,7 +456,6 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) {
configuration.ContainerImageNameTag = ":1.0.1"
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, "failed to apply helm command: failed to extract registry URL, image name, and image tag: image name could not be extracted")
})
@ -475,7 +464,6 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) {
runner := &gitOpsExecRunnerMock{failOnRunExecutable: true}
err := runGitopsUpdateDeployment(validConfiguration, runner, &gitUtilsMock{}, &filesMock{})
assert.Error(t, err)
assert.EqualError(t, err, "failed to apply helm command: failed to execute helm command: error happened")
})

View File

@ -379,7 +379,6 @@ func TestHandleHTTPError(t *testing.T) {
message := "Custom Error Message"
err := HandleHTTPError(&resp, receivedErr, message, ConnectionDetailsHTTP{})
assert.Error(t, err, "Error was expected")
assert.EqualError(t, err, fmt.Sprintf("%s: %s - %s", receivedErr.Error(), abapErrorCode, abapErrorMessage))
log.Entry().Info(err.Error())
})
@ -399,7 +398,6 @@ func TestHandleHTTPError(t *testing.T) {
message := "Custom Error Message"
err := HandleHTTPError(&resp, receivedErr, message, ConnectionDetailsHTTP{})
assert.Error(t, err, "Error was expected")
assert.EqualError(t, err, fmt.Sprintf("%s", receivedErr.Error()))
log.Entry().Info(err.Error())
})
@ -419,7 +417,6 @@ func TestHandleHTTPError(t *testing.T) {
message := "Custom Error Message"
err := HandleHTTPError(&resp, receivedErr, message, ConnectionDetailsHTTP{})
assert.Error(t, err, "Error was expected")
assert.EqualError(t, err, fmt.Sprintf("%s", receivedErr.Error()))
log.Entry().Info(err.Error())
})

View File

@ -25,7 +25,6 @@ func TestCommit(t *testing.T) {
_, err := commitSingleFile(".", "message", "user", WorktreeMockFailing{
failingAdd: true,
})
assert.Error(t, err)
assert.EqualError(t, err, "failed to add file to git: failed to add file")
})
@ -34,7 +33,6 @@ func TestCommit(t *testing.T) {
_, err := commitSingleFile(".", "message", "user", WorktreeMockFailing{
failingCommit: true,
})
assert.Error(t, err)
assert.EqualError(t, err, "failed to commit file: failed to commit file")
})
}
@ -52,7 +50,6 @@ func TestPushChangesToRepository(t *testing.T) {
t.Run("error pushing", func(t *testing.T) {
t.Parallel()
err := pushChangesToRepository("user", "password", RepositoryMockError{})
assert.Error(t, err)
assert.EqualError(t, err, "failed to push commit: error on push commits")
})
}
@ -74,7 +71,6 @@ func TestPlainClone(t *testing.T) {
t.Parallel()
abstractedGit := UtilsGitMockError{}
_, err := plainClone("user", "password", "URL", "directory", abstractedGit)
assert.Error(t, err)
assert.EqualError(t, err, "failed to clone git: error during clone")
})
}
@ -94,7 +90,6 @@ func TestChangeBranch(t *testing.T) {
t.Parallel()
worktreeMock := &WorktreeMock{}
err := changeBranch("", worktreeMock)
assert.Error(t, err)
assert.EqualError(t, err, "no branch name provided")
})
@ -109,7 +104,6 @@ func TestChangeBranch(t *testing.T) {
err := changeBranch("otherBranch", WorktreeMockFailing{
failingCheckout: true,
})
assert.Error(t, err)
assert.EqualError(t, err, "failed to checkout branch: failed to checkout branch")
})
}

View File

@ -25,7 +25,6 @@ func TestReadTaskReport(t *testing.T) {
result, err := ReadTaskReport("./testData/missing")
// assert
assert.Empty(t, result.ProjectKey)
assert.Error(t, err)
assert.EqualError(t, err, "open testData/missing/.scannerwork/report-task.txt: no such file or directory")
})
@ -34,7 +33,6 @@ func TestReadTaskReport(t *testing.T) {
result, err := ReadTaskReport("./testData/invalid")
// assert
assert.Empty(t, result.ProjectKey)
assert.Error(t, err)
assert.EqualError(t, err, "decode testData/invalid/.scannerwork/report-task.txt: missing required key projectKey")
})
}