cmd/gitbay-runner/steps_test.go

ac8d910ff31c2fadc452928e1d56c64b4af25495
gitbay/cmd/gitbay-runner/steps_test.go

33 lines · 1019 bytes

 1package main
 2
 3import (
 4	"os"
 5	"os/exec"
 6	"strings"
 7	"testing"
 8	"time"
 9)
10
11// The failing step is named by number in the log and in the outcome
12// reported to the server (#266).
13func TestRunStepsNamesTheFailedStep(t *testing.T) {
14	r := &runner{isolation: isolationNone}
15	run := func(cmd *exec.Cmd, _ time.Time) (bool, string) {
16		if err := cmd.Run(); err != nil {
17			return false, exitReason(err)
18		}
19		return true, ""
20	}
21	env := []string{"PATH=" + os.Getenv("PATH")}
22	var log strings.Builder
23	f := r.runSteps(job{Steps: []string{"true", "exit 3", "true"}}, t.TempDir(), env, &log, time.Now().Add(time.Minute), run)
24	if f == nil || f.Step != 2 || f.Reason != "exit 3" {
25		t.Fatalf("failure %+v, want step 2, exit 3", f)
26	}
27	if !strings.Contains(log.String(), "step 2/3 failed: exit 3\n") {
28		t.Fatalf("log does not name the step:\n%s", log.String())
29	}
30	if f := r.runSteps(job{Steps: []string{"true"}}, t.TempDir(), env, &log, time.Now().Add(time.Minute), run); f != nil {
31		t.Fatalf("a passing job failed: %+v", f)
32	}
33}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form