Add test for RandDate func

This commit is contained in:
Andinus 2020-03-26 15:31:00 +05:30
parent 945ea27d5f
commit afd4130b38
Signed by: andinus
GPG Key ID: B67D55D482A799FD
2 changed files with 21 additions and 0 deletions

18
apod/randomdate_test.go Normal file
View File

@ -0,0 +1,18 @@
package apod
import (
"regexp"
"testing"
)
// TestRandDate tests the RandDate func. We're not actually testing
// much, there are many cases and we really can't test for all, we'll
// have to run this test a lot of times for that. Even after that it
// doesn't guarantee anything because our test itself is flawed.
func TestRandDate(t *testing.T) {
date := RandDate()
re := regexp.MustCompile("((19|20)\\d\\d)-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])")
if !re.MatchString(date) {
t.Errorf("Date format is incorrect, got %s, want YYYY-MM-DD.", date)
}
}

View File

@ -9,6 +9,7 @@ steps:
GOARCH: amd64
GOOS: openbsd
commands:
- go test -v ./...
- go build ./cmd/cetus
- name: build-linux
@ -17,6 +18,7 @@ steps:
GOARCH: amd64
GOOS: linux
commands:
- go test -v ./...
- go build ./cmd/cetus
- name: build-darwin
@ -25,4 +27,5 @@ steps:
GOARCH: amd64
GOOS: darwin
commands:
- go test -v ./...
- go build ./cmd/cetus