-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(ci_trace,tests) test selecting and stream job logs
- Loading branch information
1 parent
8323f0f
commit 381b503
Showing
6 changed files
with
157 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package cmd | ||
|
||
import ( | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_ciTrace(t *testing.T) { | ||
t.Parallel() | ||
repo := copyTestRepo(t) | ||
cmd := exec.Command("../lab_bin", "fetch", "origin") | ||
cmd.Dir = repo | ||
if b, err := cmd.CombinedOutput(); err != nil { | ||
t.Log(string(b)) | ||
t.Fatal(err) | ||
} | ||
|
||
cmd = exec.Command("../lab_bin", "checkout", "origin/ci_test_pipeline") | ||
cmd.Dir = repo | ||
if b, err := cmd.CombinedOutput(); err != nil { | ||
t.Log(string(b)) | ||
t.Fatal(err) | ||
} | ||
|
||
tests := []struct { | ||
desc string | ||
args []string | ||
assertContains func(t *testing.T, out string) | ||
}{ | ||
{ | ||
desc: "noargs", | ||
args: []string{}, | ||
assertContains: func(t *testing.T, out string) { | ||
assert.Contains(t, out, "Showing logs for deploy10 job #62958489") | ||
assert.Contains(t, out, "Checking out 09b519cb as ci_test_pipeline...") | ||
assert.Contains(t, out, "For example you might run an update here or install a build dependency") | ||
assert.Contains(t, out, "$ echo \"Or perhaps you might print out some debugging details\"") | ||
assert.Contains(t, out, "Job succeeded") | ||
}, | ||
}, | ||
{ | ||
desc: "manual", | ||
args: []string{"origin", "deploy2"}, | ||
assertContains: func(t *testing.T, out string) { | ||
assert.Contains(t, out, "Manual job deploy2 not started\n") | ||
}, | ||
}, | ||
{ | ||
desc: "arg job name", | ||
args: []string{"origin", "deploy1"}, | ||
assertContains: func(t *testing.T, out string) { | ||
assert.Contains(t, out, "Showing logs for deploy1 job #62958479") | ||
assert.Contains(t, out, "Checking out 09b519cb as ci_test_pipeline...") | ||
assert.Contains(t, out, "For example you might run an update here or install a build dependency") | ||
assert.Contains(t, out, "$ echo \"Or perhaps you might print out some debugging details\"") | ||
assert.Contains(t, out, "Job succeeded") | ||
}, | ||
}, | ||
{ | ||
desc: "explicit sha:job", | ||
args: []string{"origin", "09b519cba018b707c98fc56e37df15806d89d866:deploy1"}, | ||
assertContains: func(t *testing.T, out string) { | ||
assert.Contains(t, out, "Showing logs for deploy1 job #62958479") | ||
assert.Contains(t, out, "Checking out 09b519cb as ci_test_pipeline...") | ||
assert.Contains(t, out, "For example you might do some cleanup here") | ||
assert.Contains(t, out, "Job succeeded") | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
test := test | ||
t.Run(test.desc, func(t *testing.T) { | ||
t.Parallel() | ||
cmd = exec.Command("../lab_bin", append([]string{"ci", "trace"}, test.args...)...) | ||
cmd.Dir = repo | ||
|
||
b, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Log(string(b)) | ||
t.Fatal(err) | ||
} | ||
out := string(b) | ||
test.assertContains(t, out) | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters