From afd4130b382c333e746adff49ce5d2c554d3045d Mon Sep 17 00:00:00 2001 From: Andinus Date: Thu, 26 Mar 2020 15:31:00 +0530 Subject: Add test for RandDate func --- apod/randomdate_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 apod/randomdate_test.go (limited to 'apod') diff --git a/apod/randomdate_test.go b/apod/randomdate_test.go new file mode 100644 index 0000000..8ac82bc --- /dev/null +++ b/apod/randomdate_test.go @@ -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) + } +} -- cgit 1.4.1-2-gfad0