-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
61 lines (53 loc) · 1.19 KB
/
main_test.go
File metadata and controls
61 lines (53 loc) · 1.19 KB
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
package main
import (
"net"
"os"
"regexp"
"testing"
)
func TestGetIpAddr(t *testing.T) {
result := getIpAddr("10.0.0.1")
resultIp := net.ParseIP("10.0.0.1")
if resultIp.String() != result.String() {
t.Errorf("Function did not return valid IP")
}
}
func TestPollTrue(t *testing.T) {
host := mockAPI{}
result := poll(host)
if result != true {
t.Errorf("Poll did not return true")
}
}
func TestPollFalse(t *testing.T) {
host := mockAPIFail{}
result := poll(host)
if result != false {
t.Errorf("Poll did not return false")
}
}
func TestGetImage(t *testing.T) {
host := mockAPI{}
testFilePath := "test/0_01-02-2002 1:2:3.jpeg"
_ = os.Remove(testFilePath)
result, err := getImage("IMG_0.JPG", host, "test")
if err != nil {
t.Errorf("Function returned error %s", err)
}
re := regexp.MustCompile(`test/0_[0-9-]+_[0-9:]+.jpeg`)
if !re.MatchString(result) {
t.Errorf("Function did not return correct file path %s", result)
}
_, err = os.Stat(result)
if err != nil {
t.Errorf("Could not stat test file")
}
_ = os.Remove(result)
}
func TestDeleteFile(t *testing.T) {
host := mockAPI{}
err := deleteFile("foobar", host)
if err != nil {
t.Errorf("Function errored: %s", err)
}
}