Skip to content

Commit

Permalink
Add GitHub actions CI workflow to build, run and test the app
Browse files Browse the repository at this point in the history
  • Loading branch information
lschuermann committed Sep 12, 2023
1 parent 3d2f7bb commit f3f5d5f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
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 ./...
30 changes: 30 additions & 0 deletions utils/assignments_test.go
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);
}
}
}

0 comments on commit f3f5d5f

Please sign in to comment.