mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +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:
parent
51c63c9da1
commit
56586cae1b
@ -40,7 +40,6 @@ func TestBuildRegistryPlusImage(t *testing.T) {
|
|||||||
ContainerRegistryURL: "//myregistry.com/registry/containers",
|
ContainerRegistryURL: "//myregistry.com/registry/containers",
|
||||||
ContainerImageNameTag: "myFancyContainer:1337",
|
ContainerImageNameTag: "myFancyContainer:1337",
|
||||||
})
|
})
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "registry URL could not be extracted: invalid registry url")
|
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",
|
ContainerRegistryURL: "//myregistry.com/registry/containers",
|
||||||
ContainerImageNameTag: "myFancyContainer:1337",
|
ContainerImageNameTag: "myFancyContainer:1337",
|
||||||
})
|
})
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "registry URL could not be extracted: invalid registry url")
|
assert.EqualError(t, err, "registry URL could not be extracted: invalid registry url")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -202,7 +200,6 @@ func TestRunGitopsUpdateDeploymentWithKubectl(t *testing.T) {
|
|||||||
runnerMock := &gitOpsExecRunnerMock{}
|
runnerMock := &gitOpsExecRunnerMock{}
|
||||||
|
|
||||||
err := runGitopsUpdateDeployment(&configuration, runnerMock, gitUtilsMock, &filesMock{})
|
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]")
|
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}
|
runner := &gitOpsExecRunnerMock{failOnRunExecutable: true}
|
||||||
|
|
||||||
err := runGitopsUpdateDeployment(validConfiguration, runner, &gitUtilsMock{}, &filesMock{})
|
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")
|
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{})
|
err := runGitopsUpdateDeployment(configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "tool invalid is not supported")
|
assert.EqualError(t, err, "tool invalid is not supported")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -415,7 +410,6 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) {
|
|||||||
configuration.ContainerRegistryURL = "://myregistry.com"
|
configuration.ContainerRegistryURL = "://myregistry.com"
|
||||||
|
|
||||||
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
|
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`)
|
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 = ""
|
configuration.ChartPath = ""
|
||||||
|
|
||||||
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
|
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]")
|
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 = ""
|
configuration.DeploymentName = ""
|
||||||
|
|
||||||
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
|
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]")
|
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 = ""
|
configuration.ChartPath = ""
|
||||||
|
|
||||||
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
|
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]")
|
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:"
|
configuration.ContainerImageNameTag = "registry/containers/myFancyContainer:"
|
||||||
|
|
||||||
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
|
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")
|
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"
|
configuration.ContainerImageNameTag = ":1.0.1"
|
||||||
|
|
||||||
err := runGitopsUpdateDeployment(&configuration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, &filesMock{})
|
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")
|
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}
|
runner := &gitOpsExecRunnerMock{failOnRunExecutable: true}
|
||||||
|
|
||||||
err := runGitopsUpdateDeployment(validConfiguration, runner, &gitUtilsMock{}, &filesMock{})
|
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")
|
assert.EqualError(t, err, "failed to apply helm command: failed to execute helm command: error happened")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -379,7 +379,6 @@ func TestHandleHTTPError(t *testing.T) {
|
|||||||
message := "Custom Error Message"
|
message := "Custom Error Message"
|
||||||
|
|
||||||
err := HandleHTTPError(&resp, receivedErr, message, ConnectionDetailsHTTP{})
|
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))
|
assert.EqualError(t, err, fmt.Sprintf("%s: %s - %s", receivedErr.Error(), abapErrorCode, abapErrorMessage))
|
||||||
log.Entry().Info(err.Error())
|
log.Entry().Info(err.Error())
|
||||||
})
|
})
|
||||||
@ -399,7 +398,6 @@ func TestHandleHTTPError(t *testing.T) {
|
|||||||
message := "Custom Error Message"
|
message := "Custom Error Message"
|
||||||
|
|
||||||
err := HandleHTTPError(&resp, receivedErr, message, ConnectionDetailsHTTP{})
|
err := HandleHTTPError(&resp, receivedErr, message, ConnectionDetailsHTTP{})
|
||||||
assert.Error(t, err, "Error was expected")
|
|
||||||
assert.EqualError(t, err, fmt.Sprintf("%s", receivedErr.Error()))
|
assert.EqualError(t, err, fmt.Sprintf("%s", receivedErr.Error()))
|
||||||
log.Entry().Info(err.Error())
|
log.Entry().Info(err.Error())
|
||||||
})
|
})
|
||||||
@ -419,7 +417,6 @@ func TestHandleHTTPError(t *testing.T) {
|
|||||||
message := "Custom Error Message"
|
message := "Custom Error Message"
|
||||||
|
|
||||||
err := HandleHTTPError(&resp, receivedErr, message, ConnectionDetailsHTTP{})
|
err := HandleHTTPError(&resp, receivedErr, message, ConnectionDetailsHTTP{})
|
||||||
assert.Error(t, err, "Error was expected")
|
|
||||||
assert.EqualError(t, err, fmt.Sprintf("%s", receivedErr.Error()))
|
assert.EqualError(t, err, fmt.Sprintf("%s", receivedErr.Error()))
|
||||||
log.Entry().Info(err.Error())
|
log.Entry().Info(err.Error())
|
||||||
})
|
})
|
||||||
|
@ -25,7 +25,6 @@ func TestCommit(t *testing.T) {
|
|||||||
_, err := commitSingleFile(".", "message", "user", WorktreeMockFailing{
|
_, err := commitSingleFile(".", "message", "user", WorktreeMockFailing{
|
||||||
failingAdd: true,
|
failingAdd: true,
|
||||||
})
|
})
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "failed to add file to git: failed to add file")
|
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{
|
_, err := commitSingleFile(".", "message", "user", WorktreeMockFailing{
|
||||||
failingCommit: true,
|
failingCommit: true,
|
||||||
})
|
})
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "failed to commit file: failed to commit file")
|
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.Run("error pushing", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
err := pushChangesToRepository("user", "password", RepositoryMockError{})
|
err := pushChangesToRepository("user", "password", RepositoryMockError{})
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "failed to push commit: error on push commits")
|
assert.EqualError(t, err, "failed to push commit: error on push commits")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -74,7 +71,6 @@ func TestPlainClone(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
abstractedGit := UtilsGitMockError{}
|
abstractedGit := UtilsGitMockError{}
|
||||||
_, err := plainClone("user", "password", "URL", "directory", abstractedGit)
|
_, err := plainClone("user", "password", "URL", "directory", abstractedGit)
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "failed to clone git: error during clone")
|
assert.EqualError(t, err, "failed to clone git: error during clone")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -94,7 +90,6 @@ func TestChangeBranch(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
worktreeMock := &WorktreeMock{}
|
worktreeMock := &WorktreeMock{}
|
||||||
err := changeBranch("", worktreeMock)
|
err := changeBranch("", worktreeMock)
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "no branch name provided")
|
assert.EqualError(t, err, "no branch name provided")
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -109,7 +104,6 @@ func TestChangeBranch(t *testing.T) {
|
|||||||
err := changeBranch("otherBranch", WorktreeMockFailing{
|
err := changeBranch("otherBranch", WorktreeMockFailing{
|
||||||
failingCheckout: true,
|
failingCheckout: true,
|
||||||
})
|
})
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "failed to checkout branch: failed to checkout branch")
|
assert.EqualError(t, err, "failed to checkout branch: failed to checkout branch")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ func TestReadTaskReport(t *testing.T) {
|
|||||||
result, err := ReadTaskReport("./testData/missing")
|
result, err := ReadTaskReport("./testData/missing")
|
||||||
// assert
|
// assert
|
||||||
assert.Empty(t, result.ProjectKey)
|
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")
|
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")
|
result, err := ReadTaskReport("./testData/invalid")
|
||||||
// assert
|
// assert
|
||||||
assert.Empty(t, result.ProjectKey)
|
assert.Empty(t, result.ProjectKey)
|
||||||
assert.Error(t, err)
|
|
||||||
assert.EqualError(t, err, "decode testData/invalid/.scannerwork/report-task.txt: missing required key projectKey")
|
assert.EqualError(t, err, "decode testData/invalid/.scannerwork/report-task.txt: missing required key projectKey")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user