-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_structs.go
93 lines (78 loc) · 1.78 KB
/
test_structs.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"errors"
"image"
"image/jpeg"
"net"
"os"
"testing"
)
type mockAPI struct {
Ip net.IP
Port int
}
func (host mockAPI) getIp() string {
return net.ParseIP("10.0.0.1").String()
}
func (host mockAPI) Get(path string) ([]byte, error) {
return []byte("wef"), nil
}
func (host mockAPI) GetJpeg(path string) (image.Image, error) {
var file image.Image
var t testing.T
testImage, err := os.Open("test-image.jpg")
if err != nil {
t.Errorf("Couldn't open test image file")
}
file, err = jpeg.Decode(testImage)
if err != nil {
t.Errorf("Couldn't decode test image file")
}
return file, nil
}
func (host mockAPI) GetFileList() ([]Image, error) {
var images []Image
images = append(images, Image{
Name: "foo",
Size: 1,
Modified: "bar",
})
return images, nil
}
func (host mockAPI) GetStatus() (map[string]interface{}, error) {
var result map[string]interface{}
return result, nil
}
func (host mockAPI) Delete(scanName string) error {
return nil
}
type mockAPIFail struct {
Ip net.IP
Port int
}
func (host mockAPIFail) getIp() string {
return net.ParseIP("10.0.0.1").String()
}
func (host mockAPIFail) Get(path string) ([]byte, error) {
return []byte("wef"), errors.New("failure")
}
func (host mockAPIFail) GetJpeg(path string) (image.Image, error) {
var file image.Image
return file, errors.New("failure")
}
func (host mockAPIFail) GetFileList() ([]Image, error) {
var images []Image
images = append(images, Image{
Name: "foo",
Size: 1,
Modified: "bar",
})
return images, errors.New("failure")
}
func (host mockAPIFail) GetStatus() (map[string]interface{}, error) {
var result map[string]interface{}
return result, errors.New("failure")
}
func (host mockAPIFail) Delete(scanName string) error {
return errors.New("failure")
}