Skip to content

Commit 7e153c6

Browse files
committed
Add feature: tests in a seperate package
1 parent 76ef75d commit 7e153c6

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ jobs:
2525
- name: Run tests
2626
run: |
2727
go version
28-
go test -v -timeout 9999s -count 1 -p 1 -cover -coverprofile coverage.txt .
28+
go test -v -timeout 9999s -count 1 -p 1 -cover -coverprofile coverage.txt ./
29+
- name: Run tests (in different package)
30+
run: |
31+
go version
32+
cd module_test && \
33+
go test -v -timeout 9999s -count 1 -p 1 -cover -coverprofile ../coverage_test_package.txt -coverpkg=github.com/btnguyen2k/mymodule ./ && \
34+
cd ..
2935
- name: Codecov
3036
uses: codecov/codecov-action@v3
3137
with:

module_test/code_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package module_test
2+
3+
import (
4+
"github.com/btnguyen2k/mymodule"
5+
"reflect"
6+
"testing"
7+
)
8+
9+
// sample tests
10+
11+
func TestClone_int(t *testing.T) {
12+
testName := "TestClone_int"
13+
input := []int{1, 2, 3}
14+
output := mymodule.Clone(input)
15+
if !reflect.DeepEqual(input, output) {
16+
t.Fatalf("%s failed: expected %v but received %v", testName, input, output)
17+
}
18+
}
19+
20+
func TestClone_uint(t *testing.T) {
21+
testName := "TestClone_uint"
22+
input := []uint{4, 5, 6}
23+
output := mymodule.Clone(input)
24+
if !reflect.DeepEqual(input, output) {
25+
t.Fatalf("%s failed: expected %v but received %v", testName, input, output)
26+
}
27+
}
28+
29+
func TestClone_float(t *testing.T) {
30+
testName := "TestClone_float"
31+
input := []float64{7.8, 8.9, 9.0}
32+
output := mymodule.Clone(input)
33+
if !reflect.DeepEqual(input, output) {
34+
t.Fatalf("%s failed: expected %v but received %v", testName, input, output)
35+
}
36+
}
37+
38+
func TestClone_string(t *testing.T) {
39+
testName := "TestClone_string"
40+
input := []string{"string 1", "string 2", "string 3"}
41+
output := mymodule.Clone(input)
42+
if !reflect.DeepEqual(input, output) {
43+
t.Fatalf("%s failed: expected %v but received %v", testName, input, output)
44+
}
45+
}

module_test/go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module module_test
2+
3+
go 1.18
4+
5+
require github.com/btnguyen2k/mymodule v0.0.0-00010101000000-000000000000
6+
7+
replace github.com/btnguyen2k/mymodule => ../

module_test/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.com/btnguyen2k/consu/semver v0.2.1 h1:le0FzrM7u0IOR4MnOyBySHpZ/p3vV4JjofAhPB7edWE=

0 commit comments

Comments
 (0)