forked from jaswdr/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
57 lines (46 loc) · 1.19 KB
/
utils_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
package faker
import (
"net/http"
"os"
"runtime"
"strings"
"testing"
)
type ErrorRaiserHTTPClient struct {
err error
}
func (client ErrorRaiserHTTPClient) Get(_ string) (*http.Response, error) {
return nil, client.err
}
type ErrorRaiserTempFileCreator struct {
err error
}
func (creator ErrorRaiserTempFileCreator) TempFile(_ string) (*os.File, error) {
return nil, creator.err
}
func TestHTTPClientImplCanDoGetRequests(t *testing.T) {
client := HTTPClientImpl{}
resp, err := client.Get("https://www.example.com")
Expect(t, err, nil)
Expect(t, resp.StatusCode, http.StatusOK)
}
func TestHTTPClientImplReturnsErrorWhenRequestFails(t *testing.T) {
client := HTTPClientImpl{}
_, err := client.Get("https://invalid")
NotExpect(t, err, nil)
}
func TestTempFileCreatorImplCanCreateTempFiles(t *testing.T) {
creator := TempFileCreatorImpl{}
f, err := creator.TempFile("prefix")
Expect(t, err, nil)
Expect(t, true, strings.Contains(f.Name(), "prefix"))
Expect(t, f.Close(), nil)
}
type WindowsOSResolver struct{}
func (WindowsOSResolver) OS() string {
return "windows"
}
func TestOSResolverImplReturnsGOOS(t *testing.T) {
resolver := OSResolverImpl{}
Expect(t, runtime.GOOS, resolver.OS())
}