Skip to content

Commit 772a0f7

Browse files
Add tests in CI (#4)
1 parent 6e0807d commit 772a0f7

File tree

7 files changed

+70
-4
lines changed

7 files changed

+70
-4
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,32 @@ jobs:
4444
push: true
4545
tags: ${{ env.TEST_TAG }}
4646

47-
- name: Run the Container
48-
id: run
47+
- name: No issues in a healthy package
48+
id: test-healthy
49+
working-directory: ./tests/healthypkg
4950
run: |
51+
echo "Running Docker command in the current directory: $(pwd)"
52+
5053
docker run \
51-
--rm ${{ env.TEST_TAG }} || true
54+
-v .:/github/workspace \
55+
-e PACKAGE_TO_SCAN="./..." \
56+
--rm ${{ env.TEST_TAG }}
57+
58+
- name: Spot issues in an unhealthy package
59+
id: test-unhealthy
60+
working-directory: ./tests/unhealthypkg
61+
run: |
62+
set +e
63+
64+
echo "Running Docker command in the current directory: $(pwd)"
65+
66+
if docker run \
67+
-v .:/github/workspace \
68+
-e PACKAGE_TO_SCAN="./..." \
69+
--rm ${{ env.TEST_TAG }}; then
70+
echo "Container didn't fail when it should've"
71+
exit 1
72+
else
73+
echo "Container failed as expected"
74+
exit 0
75+
fi

.github/workflows/linter.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ jobs:
2828
DEFAULT_BRANCH: main
2929
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3030
VALIDATE_ALL_CODEBASE: false
31+
FILTER_REGEX_EXCLUDE: 'tests/.*'

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.4
1+
0.0.5

tests/healthypkg/cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("I haven't been using shampoo since 2016. 🥚")
7+
}

tests/healthypkg/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module healthypkg
2+
3+
go 1.21.0

tests/unhealthypkg/cmd/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import "log"
4+
5+
type BaldGuy struct {
6+
Name string
7+
HairCount int
8+
}
9+
10+
func fetchABaldBuy() *BaldGuy {
11+
baldBuy := &BaldGuy{
12+
Name: "Daniel Gospodinow",
13+
HairCount: 0,
14+
}
15+
16+
// Doing the nasty thing.
17+
baldBuy = nil
18+
19+
return baldBuy
20+
}
21+
22+
func main() {
23+
baldGuy := fetchABaldBuy()
24+
25+
if baldGuy.HairCount > 0 {
26+
log.Printf("Bald guy %s has %d hairs, he's surely been on a trip to Turkey!", baldGuy.Name, baldGuy.HairCount)
27+
}
28+
}

tests/unhealthypkg/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module unhealthypkg
2+
3+
go 1.21.0

0 commit comments

Comments
 (0)