Skip to content

Commit

Permalink
(integration tests) support for generating coverage files when execut…
Browse files Browse the repository at this point in the history
…ing lab as a binary
  • Loading branch information
zaquestion committed Dec 2, 2017
1 parent dbf9447 commit 8ec6b6d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/issueList_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func Test_issueList(t *testing.T) {

issues := strings.Split(string(b), "\n")
t.Log(issues)
firstIssue := issues[len(issues)-2 : len(issues)-1]
firstIssue := issues[len(issues)-4 : len(issues)-3]
require.Equal(t, "#1 test issue for lab list", firstIssue[0])
}
2 changes: 1 addition & 1 deletion cmd/mrList_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func Test_mrList(t *testing.T) {

issues := strings.Split(string(b), "\n")
t.Log(issues)
firstIssue := issues[len(issues)-2 : len(issues)-1]
firstIssue := issues[len(issues)-4 : len(issues)-3]
require.Equal(t, "#1 Test MR for lab list", firstIssue[0])
}
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}
os.Chdir(wd)
err = exec.Command("go", "build", "-o", "lab_bin").Run()
err = exec.Command("go", "test", "-c", "-coverpkg", "./...", "-covermode", "count", "-o", "lab_bin").Run()
if err != nil {
log.Fatal(err)
}
Expand Down
17 changes: 17 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

// This file is mandatory as otherwise the lab.test binary is not generated correctly.
import (
"flag"
"math/rand"
"strconv"
"testing"
"time"
)

// Test started when the test binary is started. Only calls main.
func TestLab(t *testing.T) {
rand.Seed(time.Now().UnixNano())
flag.Set("test.coverprofile", "../coverage-"+strconv.Itoa(int(rand.Uint64()))+".out")
main()
}

0 comments on commit 8ec6b6d

Please sign in to comment.