@@ -5,27 +5,38 @@ import (
5
5
"net/http"
6
6
"net/http/httptest"
7
7
"net/url"
8
- "testing"
9
8
10
9
"github.com/github/git-lfs/api"
11
- "github.com/github/git-lfs/vendor/_nuts/github.com/ stretchr/testify/assert "
10
+ "github.com/stretchr/testify/suite "
12
11
)
13
12
14
13
var (
15
14
root , _ = url .Parse ("https://example.com" )
16
15
)
17
16
18
- func TestHttpLifecycleMakesRequestsAgainstAbsolutePath (t * testing.T ) {
17
+ type HttpLifecycleTestSuite struct {
18
+ suite.Suite
19
+ }
20
+
21
+ func (suite * HttpLifecycleTestSuite ) SetupTest () {
22
+ SetupTestCredentialsFunc ()
23
+ }
24
+
25
+ func (suite * HttpLifecycleTestSuite ) TearDownTest () {
26
+ RestoreCredentialsFunc ()
27
+ }
28
+
29
+ func (suite * HttpLifecycleTestSuite ) TestHttpLifecycleMakesRequestsAgainstAbsolutePath () {
19
30
l := api .NewHttpLifecycle (root )
20
31
req , err := l .Build (& api.RequestSchema {
21
32
Path : "/foo" ,
22
33
})
23
34
24
- assert . Nil (t , err )
25
- assert . Equal (t , "https://example.com/foo" , req .URL .String ())
35
+ suite . Assert (). Nil (err )
36
+ suite . Assert (). Equal ("https://example.com/foo" , req .URL .String ())
26
37
}
27
38
28
- func TestHttpLifecycleAttachesQueryParameters ( t * testing. T ) {
39
+ func ( suite * HttpLifecycleTestSuite ) TestHttpLifecycleAttachesQueryParameters ( ) {
29
40
l := api .NewHttpLifecycle (root )
30
41
req , err := l .Build (& api.RequestSchema {
31
42
Path : "/foo" ,
@@ -34,52 +45,52 @@ func TestHttpLifecycleAttachesQueryParameters(t *testing.T) {
34
45
},
35
46
})
36
47
37
- assert . Nil (t , err )
38
- assert . Equal (t , "https://example.com/foo?a=b" , req .URL .String ())
48
+ suite . Assert (). Nil (err )
49
+ suite . Assert (). Equal ("https://example.com/foo?a=b" , req .URL .String ())
39
50
}
40
51
41
- func TestHttpLifecycleAttachesBodyWhenPresent ( t * testing. T ) {
52
+ func ( suite * HttpLifecycleTestSuite ) TestHttpLifecycleAttachesBodyWhenPresent ( ) {
42
53
l := api .NewHttpLifecycle (root )
43
54
req , err := l .Build (& api.RequestSchema {
44
55
Body : struct {
45
56
Foo string `json:"foo"`
46
57
}{"bar" },
47
58
})
48
59
49
- assert . Nil (t , err )
60
+ suite . Assert (). Nil (err )
50
61
51
62
body , err := ioutil .ReadAll (req .Body )
52
- assert . Nil (t , err )
53
- assert . Equal (t , "{\" foo\" :\" bar\" }" , string (body ))
63
+ suite . Assert (). Nil (err )
64
+ suite . Assert (). Equal ("{\" foo\" :\" bar\" }" , string (body ))
54
65
}
55
66
56
- func TestHttpLifecycleDoesNotAttachBodyWhenEmpty ( t * testing. T ) {
67
+ func ( suite * HttpLifecycleTestSuite ) TestHttpLifecycleDoesNotAttachBodyWhenEmpty ( ) {
57
68
l := api .NewHttpLifecycle (root )
58
69
req , err := l .Build (& api.RequestSchema {})
59
70
60
- assert . Nil (t , err )
61
- assert . Nil (t , req .Body )
71
+ suite . Assert (). Nil (err )
72
+ suite . Assert (). Nil (req .Body )
62
73
}
63
74
64
- func TestHttpLifecycleExecutesRequestWithoutBody ( t * testing. T ) {
75
+ func ( suite * HttpLifecycleTestSuite ) TestHttpLifecycleExecutesRequestWithoutBody ( ) {
65
76
var called bool
66
77
server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
67
78
called = true
68
79
69
- assert . Equal (t , "/path" , r .URL .RequestURI ())
80
+ suite . Assert (). Equal ("/path" , r .URL .RequestURI ())
70
81
}))
71
82
defer server .Close ()
72
83
73
84
req , _ := http .NewRequest (http .MethodGet , server .URL + "/path" , nil )
74
85
75
- l := api .NewHttpLifecycle (nil )
86
+ l := api .NewHttpLifecycle (root )
76
87
_ , err := l .Execute (req , nil )
77
88
78
- assert . True (t , called )
79
- assert . Nil (t , err )
89
+ suite . Assert (). True (called )
90
+ suite . Assert (). Nil (err )
80
91
}
81
92
82
- func TestHttpLifecycleExecutesRequestWithBody ( t * testing. T ) {
93
+ func ( suite * HttpLifecycleTestSuite ) TestHttpLifecycleExecutesRequestWithBody ( ) {
83
94
type Response struct {
84
95
Foo string `json:"foo"`
85
96
}
@@ -94,11 +105,11 @@ func TestHttpLifecycleExecutesRequestWithBody(t *testing.T) {
94
105
95
106
req , _ := http .NewRequest (http .MethodGet , server .URL + "/path" , nil )
96
107
97
- l := api .NewHttpLifecycle (nil )
108
+ l := api .NewHttpLifecycle (root )
98
109
resp := new (Response )
99
110
_ , err := l .Execute (req , resp )
100
111
101
- assert . True (t , called )
102
- assert . Nil (t , err )
103
- assert . Equal (t , "bar" , resp .Foo )
112
+ suite . Assert (). True (called )
113
+ suite . Assert (). Nil (err )
114
+ suite . Assert (). Equal ("bar" , resp .Foo )
104
115
}
0 commit comments