Skip to content

Commit

Permalink
Add tests in CI (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgospodinow authored Jan 27, 2024
1 parent 6e0807d commit 772a0f7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
30 changes: 27 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,32 @@ jobs:
push: true
tags: ${{ env.TEST_TAG }}

- name: Run the Container
id: run
- name: No issues in a healthy package
id: test-healthy
working-directory: ./tests/healthypkg
run: |
echo "Running Docker command in the current directory: $(pwd)"
docker run \
--rm ${{ env.TEST_TAG }} || true
-v .:/github/workspace \
-e PACKAGE_TO_SCAN="./..." \
--rm ${{ env.TEST_TAG }}
- name: Spot issues in an unhealthy package
id: test-unhealthy
working-directory: ./tests/unhealthypkg
run: |
set +e
echo "Running Docker command in the current directory: $(pwd)"
if docker run \
-v .:/github/workspace \
-e PACKAGE_TO_SCAN="./..." \
--rm ${{ env.TEST_TAG }}; then
echo "Container didn't fail when it should've"
exit 1
else
echo "Container failed as expected"
exit 0
fi
1 change: 1 addition & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ jobs:
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: false
FILTER_REGEX_EXCLUDE: 'tests/.*'
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.4
0.0.5
7 changes: 7 additions & 0 deletions tests/healthypkg/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("I haven't been using shampoo since 2016. 🥚")
}
3 changes: 3 additions & 0 deletions tests/healthypkg/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module healthypkg

go 1.21.0
28 changes: 28 additions & 0 deletions tests/unhealthypkg/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import "log"

type BaldGuy struct {
Name string
HairCount int
}

func fetchABaldBuy() *BaldGuy {
baldBuy := &BaldGuy{
Name: "Daniel Gospodinow",
HairCount: 0,
}

// Doing the nasty thing.
baldBuy = nil

return baldBuy
}

func main() {
baldGuy := fetchABaldBuy()

if baldGuy.HairCount > 0 {
log.Printf("Bald guy %s has %d hairs, he's surely been on a trip to Turkey!", baldGuy.Name, baldGuy.HairCount)
}
}
3 changes: 3 additions & 0 deletions tests/unhealthypkg/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module unhealthypkg

go 1.21.0

0 comments on commit 772a0f7

Please sign in to comment.