-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apod_test.go
77 lines (65 loc) · 1.54 KB
/
apod_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package apod_test
import (
"testing"
"time"
"github.com/helixspiral/apod"
)
func TestNewAPOD(t *testing.T) {
// We can't do a whole lot of checking for this function so we just do this to make sure they don't error.
// If they don't, we're good for now.
Apod := apod.NewAPOD()
if Apod == nil {
t.Fatal("apod didn't return when not providing a key")
}
Apod = apod.NewAPOD("DEMO_KEY1")
if Apod == nil {
t.Fatal("apod didn't return when providing a key")
}
}
func TestQuery(t *testing.T) {
Apod := apod.NewAPOD("DEMO_KEY")
date, _ := time.Parse("2006-01-02", "2022-02-01")
// Test for Count with Date. Should error
queryInput := &apod.ApodQueryInput{
Date: date,
Count: 2,
}
_, err := Apod.Query(queryInput)
if err == nil {
t.Fatal("Should have errored with count and date, but didn't.")
}
// Test for Date with StartDate. Should error
queryInput = &apod.ApodQueryInput{
Date: date,
StartDate: date.Add(time.Hour * 24),
}
_, err = Apod.Query(queryInput)
if err == nil {
t.Fatal("Should have errored with Date and StartDate, but didn't.")
}
// Test for Date
queryInput = &apod.ApodQueryInput{
Date: date,
}
_, err = Apod.Query(queryInput)
if err != nil {
t.Fatal(err)
}
// Test for Start and End Dates
queryInput = &apod.ApodQueryInput{
StartDate: date,
EndDate: date.Add((time.Hour * 24) * 5),
}
_, err = Apod.Query(queryInput)
if err != nil {
t.Fatal(err)
}
// Test for count
queryInput = &apod.ApodQueryInput{
Count: 2,
}
_, err = Apod.Query(queryInput)
if err != nil {
t.Fatal(err)
}
}