7
7
"encoding/hex"
8
8
"github.com/G-Node/gin-valid/internal/config"
9
9
"github.com/gorilla/mux"
10
+ "io/ioutil"
10
11
"net/http"
11
12
"net/http/httptest"
12
13
"os"
@@ -22,18 +23,19 @@ func TestResultsUnsupportedV2(t *testing.T) {
22
23
router .HandleFunc ("/results/{validator}/{user}/{repo}/{id}" , Results ).Methods ("GET" )
23
24
r , _ := http .NewRequest ("GET" , filepath .Join ("/results/wtf" , username , "/" , reponame , "/" , id ), bytes .NewReader (body ))
24
25
w := httptest .NewRecorder ()
26
+ resultfldr , _ := ioutil .TempDir ("" , "results" )
25
27
srvcfg := config .Read ()
26
28
srvcfg .Settings .Validators = append (srvcfg .Settings .Validators , "wtf" )
29
+ srvcfg .Dir .Result = resultfldr
27
30
config .Set (srvcfg )
28
- os .MkdirAll (filepath .Join (srvcfg . Dir . Result , "nix" , username , reponame , id ), 0755 )
29
- f , _ := os .Create (filepath .Join (srvcfg . Dir . Result , "nix" , username , reponame , id , srvcfg .Label .ResultsFile ))
31
+ os .MkdirAll (filepath .Join (resultfldr , "nix" , username , reponame , id ), 0755 )
32
+ f , _ := os .Create (filepath .Join (resultfldr , "nix" , username , reponame , id , srvcfg .Label .ResultsFile ))
30
33
defer f .Close ()
31
34
f .WriteString (content )
32
35
sig := hmac .New (sha256 .New , []byte (srvcfg .Settings .HookSecret ))
33
36
sig .Write (body )
34
37
r .Header .Add ("X-Gogs-Signature" , hex .EncodeToString (sig .Sum (nil )))
35
38
router .ServeHTTP (w , r )
36
- os .RemoveAll (filepath .Join (srvcfg .Dir .Result , "nix" , username , reponame , id ))
37
39
srvcfg .Settings .Validators = srvcfg .Settings .Validators [:len (srvcfg .Settings .Validators )- 1 ]
38
40
config .Set (srvcfg )
39
41
status := w .Code
@@ -50,16 +52,18 @@ func TestResultsODML(t *testing.T) {
50
52
router .HandleFunc ("/results/{validator}/{user}/{repo}/{id}" , Results ).Methods ("GET" )
51
53
r , _ := http .NewRequest ("GET" , filepath .Join ("/results/odml" , username , "/" , reponame , "/" , id ), bytes .NewReader (body ))
52
54
w := httptest .NewRecorder ()
55
+ resultfldr , _ := ioutil .TempDir ("" , "results" )
53
56
srvcfg := config .Read ()
54
- os .MkdirAll (filepath .Join (srvcfg .Dir .Result , "odml" , username , reponame , id ), 0755 )
55
- f , _ := os .Create (filepath .Join (srvcfg .Dir .Result , "odml" , username , reponame , id , srvcfg .Label .ResultsFile ))
57
+ srvcfg .Dir .Result = resultfldr
58
+ config .Set (srvcfg )
59
+ os .MkdirAll (filepath .Join (resultfldr , "odml" , username , reponame , id ), 0755 )
60
+ f , _ := os .Create (filepath .Join (resultfldr , "odml" , username , reponame , id , srvcfg .Label .ResultsFile ))
56
61
defer f .Close ()
57
62
f .WriteString (content )
58
63
sig := hmac .New (sha256 .New , []byte (srvcfg .Settings .HookSecret ))
59
64
sig .Write (body )
60
65
r .Header .Add ("X-Gogs-Signature" , hex .EncodeToString (sig .Sum (nil )))
61
66
router .ServeHTTP (w , r )
62
- os .RemoveAll (filepath .Join (srvcfg .Dir .Result , "odml" , username , reponame , id ))
63
67
status := w .Code
64
68
if status != http .StatusOK {
65
69
t .Fatalf (`Results(w http.ResponseWriter, r *http.Request) status code = %v` , status )
@@ -74,16 +78,18 @@ func TestResultsNIX(t *testing.T) {
74
78
router .HandleFunc ("/results/{validator}/{user}/{repo}/{id}" , Results ).Methods ("GET" )
75
79
r , _ := http .NewRequest ("GET" , filepath .Join ("/results/nix" , username , "/" , reponame , "/" , id ), bytes .NewReader (body ))
76
80
w := httptest .NewRecorder ()
81
+ resultfldr , _ := ioutil .TempDir ("" , "results" )
77
82
srvcfg := config .Read ()
78
- os .MkdirAll (filepath .Join (srvcfg .Dir .Result , "nix" , username , reponame , id ), 0755 )
79
- f , _ := os .Create (filepath .Join (srvcfg .Dir .Result , "nix" , username , reponame , id , srvcfg .Label .ResultsFile ))
83
+ srvcfg .Dir .Result = resultfldr
84
+ config .Set (srvcfg )
85
+ os .MkdirAll (filepath .Join (resultfldr , "nix" , username , reponame , id ), 0755 )
86
+ f , _ := os .Create (filepath .Join (resultfldr , "nix" , username , reponame , id , srvcfg .Label .ResultsFile ))
80
87
defer f .Close ()
81
88
f .WriteString (content )
82
89
sig := hmac .New (sha256 .New , []byte (srvcfg .Settings .HookSecret ))
83
90
sig .Write (body )
84
91
r .Header .Add ("X-Gogs-Signature" , hex .EncodeToString (sig .Sum (nil )))
85
92
router .ServeHTTP (w , r )
86
- os .RemoveAll (filepath .Join (srvcfg .Dir .Result , "nix" , username , reponame , id ))
87
93
status := w .Code
88
94
if status != http .StatusOK {
89
95
t .Fatalf (`Results(w http.ResponseWriter, r *http.Request) status code = %v` , status )
@@ -98,16 +104,18 @@ func TestResultsInJSON(t *testing.T) {
98
104
router .HandleFunc ("/results/{validator}/{user}/{repo}/{id}" , Results ).Methods ("GET" )
99
105
r , _ := http .NewRequest ("GET" , filepath .Join ("/results/bids" , username , "/" , reponame , "/" , id ), bytes .NewReader (body ))
100
106
w := httptest .NewRecorder ()
107
+ resultfldr , _ := ioutil .TempDir ("" , "results" )
101
108
srvcfg := config .Read ()
102
- os .MkdirAll (filepath .Join (srvcfg .Dir .Result , "bids" , username , reponame , id ), 0755 )
103
- f , _ := os .Create (filepath .Join (srvcfg .Dir .Result , "bids" , username , reponame , id , srvcfg .Label .ResultsFile ))
109
+ srvcfg .Dir .Result = resultfldr
110
+ config .Set (srvcfg )
111
+ os .MkdirAll (filepath .Join (resultfldr , "bids" , username , reponame , id ), 0755 )
112
+ f , _ := os .Create (filepath .Join (resultfldr , "bids" , username , reponame , id , srvcfg .Label .ResultsFile ))
104
113
defer f .Close ()
105
114
f .WriteString (content )
106
115
sig := hmac .New (sha256 .New , []byte (srvcfg .Settings .HookSecret ))
107
116
sig .Write (body )
108
117
r .Header .Add ("X-Gogs-Signature" , hex .EncodeToString (sig .Sum (nil )))
109
118
router .ServeHTTP (w , r )
110
- os .RemoveAll (filepath .Join (srvcfg .Dir .Result , "bids" , username , reponame , id ))
111
119
status := w .Code
112
120
if status != http .StatusOK {
113
121
t .Fatalf (`Results(w http.ResponseWriter, r *http.Request) status code = %v` , status )
@@ -122,16 +130,18 @@ func TestResultsInProgress(t *testing.T) {
122
130
router .HandleFunc ("/results/{validator}/{user}/{repo}/{id}" , Results ).Methods ("GET" )
123
131
r , _ := http .NewRequest ("GET" , filepath .Join ("/results/bids" , username , "/" , reponame , "/" , id ), bytes .NewReader (body ))
124
132
w := httptest .NewRecorder ()
133
+ resultfldr , _ := ioutil .TempDir ("" , "results" )
125
134
srvcfg := config .Read ()
126
- os .MkdirAll (filepath .Join (srvcfg .Dir .Result , "bids" , username , reponame , id ), 0755 )
127
- f , _ := os .Create (filepath .Join (srvcfg .Dir .Result , "bids" , username , reponame , id , srvcfg .Label .ResultsFile ))
135
+ srvcfg .Dir .Result = resultfldr
136
+ config .Set (srvcfg )
137
+ os .MkdirAll (filepath .Join (resultfldr , "bids" , username , reponame , id ), 0755 )
138
+ f , _ := os .Create (filepath .Join (resultfldr , "bids" , username , reponame , id , srvcfg .Label .ResultsFile ))
128
139
defer f .Close ()
129
140
f .WriteString (content )
130
141
sig := hmac .New (sha256 .New , []byte (srvcfg .Settings .HookSecret ))
131
142
sig .Write (body )
132
143
r .Header .Add ("X-Gogs-Signature" , hex .EncodeToString (sig .Sum (nil )))
133
144
router .ServeHTTP (w , r )
134
- os .RemoveAll (filepath .Join (srvcfg .Dir .Result , "bids" , username , reponame , id ))
135
145
status := w .Code
136
146
if status != http .StatusOK {
137
147
t .Fatalf (`Results(w http.ResponseWriter, r *http.Request) status code = %v` , status )
@@ -146,16 +156,18 @@ func TestResultsSomeResults(t *testing.T) {
146
156
router .HandleFunc ("/results/{validator}/{user}/{repo}/{id}" , Results ).Methods ("GET" )
147
157
r , _ := http .NewRequest ("GET" , filepath .Join ("/results/bids" , username , "/" , reponame , "/" , id ), bytes .NewReader (body ))
148
158
w := httptest .NewRecorder ()
159
+ resultfldr , _ := ioutil .TempDir ("" , "results" )
149
160
srvcfg := config .Read ()
150
- os .MkdirAll (filepath .Join (srvcfg .Dir .Result , "bids" , username , reponame , id ), 0755 )
151
- f , _ := os .Create (filepath .Join (srvcfg .Dir .Result , "bids" , username , reponame , id , srvcfg .Label .ResultsFile ))
161
+ srvcfg .Dir .Result = resultfldr
162
+ config .Set (srvcfg )
163
+ os .MkdirAll (filepath .Join (resultfldr , "bids" , username , reponame , id ), 0755 )
164
+ f , _ := os .Create (filepath .Join (resultfldr , "bids" , username , reponame , id , srvcfg .Label .ResultsFile ))
152
165
defer f .Close ()
153
166
f .WriteString (content )
154
167
sig := hmac .New (sha256 .New , []byte (srvcfg .Settings .HookSecret ))
155
168
sig .Write (body )
156
169
r .Header .Add ("X-Gogs-Signature" , hex .EncodeToString (sig .Sum (nil )))
157
170
router .ServeHTTP (w , r )
158
- os .RemoveAll (filepath .Join (srvcfg .Dir .Result , "bids" , username , reponame , id ))
159
171
status := w .Code
160
172
if status != http .StatusOK {
161
173
t .Fatalf (`Results(w http.ResponseWriter, r *http.Request) status code = %v` , status )
0 commit comments