Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 10b026e

Browse files
author
Michael Sauter
committed
Improve tests by checking for specific log output
Closes #127.
1 parent c4eec8a commit 10b026e

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

test/tasks/ods-finish_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"path/filepath"
7+
"strings"
78
"testing"
89
"time"
910

@@ -84,6 +85,11 @@ func TestTaskODSFinish(t *testing.T) {
8485
bitbucketClient := tasktesting.BitbucketClientOrFatal(t, ctxt.Clients.KubernetesClientSet, ctxt.Namespace)
8586
checkBuildStatus(t, bitbucketClient, ctxt.ODS.GitCommitSHA, bitbucket.BuildStatusSuccessful)
8687
checkArtifactsAreInNexus(t, ctxt, nexus.TemporaryRepositoryDefault)
88+
89+
wantLogMsg := "Artifact coverage.out is already present in Nexus repository"
90+
if !strings.Contains(string(ctxt.CollectedLogs), wantLogMsg) {
91+
t.Fatalf("Want:\n%s\n\nGot:\n%s", wantLogMsg, string(ctxt.CollectedLogs))
92+
}
8793
},
8894
},
8995
"set bitbucket build status to successful and upload artifacts to permanent Nexus repository": {
@@ -109,6 +115,23 @@ func TestTaskODSFinish(t *testing.T) {
109115
checkArtifactsAreInNexus(t, ctxt, nexus.PermanentRepositoryDefault)
110116
},
111117
},
118+
"stops gracefully when context cannot be read": {
119+
WorkspaceDirMapping: map[string]string{"source": "empty"},
120+
PreRunFunc: func(t *testing.T, ctxt *tasktesting.TaskRunContext) {
121+
ctxt.Params = map[string]string{
122+
"pipeline-run-name": "foo",
123+
"aggregate-tasks-status": "Failed",
124+
}
125+
},
126+
WantRunSuccess: false,
127+
PostRunFunc: func(t *testing.T, ctxt *tasktesting.TaskRunContext) {
128+
want := "Unable to continue as pipeline context cannot be read"
129+
130+
if !strings.Contains(string(ctxt.CollectedLogs), want) {
131+
t.Fatalf("Want:\n%s\n\nGot:\n%s", want, string(ctxt.CollectedLogs))
132+
}
133+
},
134+
},
112135
},
113136
)
114137
}

test/tasks/ods-start_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"strings"
78
"testing"
89

910
"github.com/opendevstack/pipeline/internal/directory"
@@ -181,8 +182,14 @@ func TestTaskODSStart(t *testing.T) {
181182
}
182183
},
183184
WantRunSuccess: false,
184-
// TODO: check in post run func that failure is actually due to
185-
// missing pipeline run artifact and not due to sth. else.
185+
PostRunFunc: func(t *testing.T, ctxt *tasktesting.TaskRunContext) {
186+
want := "Pipeline runs with subrepos require a successful pipeline run " +
187+
"for all checked out subrepo commits, however no such run was found"
188+
189+
if !strings.Contains(string(ctxt.CollectedLogs), want) {
190+
t.Fatalf("Want:\n%s\n\nGot:\n%s", want, string(ctxt.CollectedLogs))
191+
}
192+
},
186193
},
187194
"handles QA stage": {
188195
WorkspaceDirMapping: map[string]string{"source": "hello-world-app"},

test/testdata/workspaces/empty/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)