Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests in CI #4

Merged
merged 10 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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