-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub actions CI workflow to build, run and test the app
- Loading branch information
1 parent
3d2f7bb
commit f3f5d5f
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: cos316-test-ci | ||
|
||
on: | ||
push: # Run CI for push operations on all branches | ||
|
||
jobs: | ||
ci-build: | ||
# Our CI build action will run on a Ubuntu virtual machine | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Makes sure that our repository is available | ||
# | ||
# All further actions will run from within this repository | ||
- uses: actions/checkout@v3 | ||
|
||
# Simply build and run our program for now. This will | ||
# automatically fail the CI if the build or run operations fail | ||
# (return with a non-zero error code). | ||
- name: build | ||
run: go build main.go | ||
|
||
# Execute our program. It should run without returning an | ||
# error-code. | ||
- name: run | ||
run: ./cos316test | ||
|
||
# Run any tests defined in the go source code: | ||
- name: test | ||
run: go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
"math/rand" | ||
"time" | ||
) | ||
|
||
// https://stackoverflow.com/a/43497333, CC BY-SA 3.0 @mkopriva | ||
func randdate() time.Time { | ||
min := time.Date(1970, 1, 0, 0, 0, 0, 0, time.UTC).Unix() | ||
max := time.Date(2070, 1, 0, 0, 0, 0, 0, time.UTC).Unix() | ||
delta := max - min | ||
|
||
sec := rand.Int63n(delta) + min | ||
return time.Unix(sec, 0) | ||
} | ||
|
||
func TestAssignmentDueToday(t *testing.T) { | ||
for i := 0; i < 1000; i++ { | ||
// Generate a random date. If its a Wednesday, | ||
// an assignment should be due... | ||
date := randdate() | ||
|
||
if (date.Weekday() == time.Wednesday) != AssignmentDueToday(date) { | ||
t.Errorf("Assignment should be due on %s!", date); | ||
} | ||
} | ||
} | ||
|