Commit ebe312b 1 parent d28e588 commit ebe312b Copy full SHA for ebe312b
File tree 10 files changed +98
-15
lines changed
10 files changed +98
-15
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ jobs: # basic units of work in a run
10
10
POSTGRES_USER : circleci-demo-go
11
11
POSTGRES_DB : circle_test
12
12
13
+ parallelism : 2
14
+
13
15
environment : # environment variables for the build itself
14
16
TEST_RESULTS : /tmp/test-results # path to where test results will be saved
15
17
@@ -26,13 +28,6 @@ jobs: # basic units of work in a run
26
28
command : |
27
29
go get -v
28
30
29
- - run :
30
- name : Get go-junit-report for setting up test timings on CircleCI
31
- command : |
32
- go get github.com/jstemmer/go-junit-report
33
- # Remove go-junit-report from go.mod
34
- go mod tidy
35
-
36
31
# Wait for Postgres to be ready before proceeding
37
32
- run :
38
33
name : Waiting for Postgres to be ready
@@ -46,8 +41,8 @@ jobs: # basic units of work in a run
46
41
47
42
# store the results of our tests in the $TEST_RESULTS directory
48
43
command : |
49
- trap "go-junit-report <${TEST_RESULTS}/go-test.out > ${TEST_RESULTS}/go-test-report.xml" EXIT
50
- make test | tee ${TEST_RESULTS}/go-test.out
44
+ PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
45
+ gotestsum --junitfile ${TEST_RESULTS}/gotestsum-report.xml -- $PACKAGE_NAMES
51
46
52
47
- run : make # pull and build dependencies for the project
53
48
Original file line number Diff line number Diff line change 1
1
GOFILES = $(shell find . -name '* .go')
2
- GOPACKAGES = $(shell go list ./...)
3
2
4
3
default : build
5
4
@@ -13,8 +12,3 @@ build-native: $(GOFILES)
13
12
14
13
workdir/contacts : $(GOFILES )
15
14
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o workdir/contacts .
16
-
17
- test : test-all
18
-
19
- test-all :
20
- @go test -v $(GOPACKAGES )
Original file line number Diff line number Diff line change
1
+ package bigdata
2
+
3
+ import (
4
+ "time"
5
+ )
6
+
7
+ func DoComputation () bool {
8
+ time .Sleep (5 * time .Second )
9
+ return true
10
+ }
11
+
12
+ func DoComplexComputation () bool {
13
+ time .Sleep (10 * time .Second )
14
+ return true
15
+ }
Original file line number Diff line number Diff line change
1
+ package bigdata
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestDoComputation (t * testing.T ) {
10
+ result := DoComputation ()
11
+ assert .True (t , result )
12
+ }
13
+
14
+ func TestDoComplexComputation (t * testing.T ) {
15
+ result := DoComplexComputation ()
16
+ assert .True (t , result )
17
+ }
Original file line number Diff line number Diff line change
1
+ package formatter
2
+
3
+ func Format (input string ) string {
4
+ return "Formatted: " + input
5
+ }
Original file line number Diff line number Diff line change
1
+ package formatter
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestFormat (t * testing.T ) {
10
+ result := Format ("my string" )
11
+ assert .Equal (t , result , "Formatted: my string" )
12
+ }
Original file line number Diff line number Diff line change
1
+ package math
2
+
3
+ func Sum (x int , y int ) int {
4
+ return x + y
5
+ }
Original file line number Diff line number Diff line change
1
+ package math
2
+
3
+ import (
4
+ "testing"
5
+ "time"
6
+
7
+ "github.com/stretchr/testify/assert"
8
+ )
9
+
10
+ func TestSumPositive (t * testing.T ) {
11
+ total := Sum (1 , 1 )
12
+ assert .Equal (t , total , 2 )
13
+ }
14
+ func TestSumNegative (t * testing.T ) {
15
+ total := Sum (1 , - 10 )
16
+ assert .Equal (t , total , - 9 )
17
+ }
18
+
19
+ func TestSumLarge (t * testing.T ) {
20
+ time .Sleep (5 * time .Second )
21
+ total := Sum (10000 , 10000 )
22
+ assert .Equal (t , total , 20000 )
23
+ }
Original file line number Diff line number Diff line change
1
+ package validator
2
+
3
+ func Validate (input string ) bool {
4
+ return true
5
+ }
Original file line number Diff line number Diff line change
1
+ package validator
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestValidate (t * testing.T ) {
10
+ result := Validate ("my string" )
11
+ assert .True (t , result )
12
+ }
You can’t perform that action at this time.
0 commit comments