Skip to content

Commit 249fb50

Browse files
committed
added go script for testing ci
1 parent 1649192 commit 249fb50

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

.github/workflows/go-ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: go-ci
1+
name: Go general check (gofmt, vet, build, test)
22

33
on:
44
push:

main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func hello() error {
6+
fmt.Println("hello")
7+
return nil
8+
}
9+
10+
func main() {
11+
if err := hello(); err != nil {
12+
fmt.Println("Error:", err)
13+
}
14+
}

main_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import "testing"
4+
5+
func Test_hello(t *testing.T) {
6+
tests := []struct {
7+
name string // description of this test case
8+
wantErr bool
9+
}{
10+
{
11+
name: "It should print hello without error",
12+
wantErr: false,
13+
},
14+
}
15+
for _, tt := range tests {
16+
t.Run(tt.name, func(t *testing.T) {
17+
gotErr := hello()
18+
if gotErr != nil {
19+
if !tt.wantErr {
20+
t.Errorf("hello() failed: %v", gotErr)
21+
}
22+
return
23+
}
24+
if tt.wantErr {
25+
t.Fatal("hello() succeeded unexpectedly")
26+
}
27+
})
28+
}
29+
}

0 commit comments

Comments
 (0)