File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,11 @@ package utils
6
6
7
7
import (
8
8
"errors"
9
+ "fmt"
9
10
"io"
10
11
"io/ioutil"
11
12
"log"
13
+ "net/http"
12
14
"os"
13
15
"os/exec"
14
16
"path/filepath"
@@ -123,3 +125,32 @@ func (t *T) RunTest(tests ...func(*T) error) (err error) {
123
125
// Note that the return value 'err' may be updated by the 'defer' statement before despite it's returning nil here.
124
126
return nil
125
127
}
128
+
129
+ // GetAndPost provides a convenient helper function for testing an HTTP endpoint with GET and POST method.
130
+ // The function sends GET first and then POST with the given form.
131
+ func GetAndPost (url string , form map [string ][]string ) error {
132
+ var err error
133
+ var r * http.Response
134
+
135
+ r , err = http .Get (url )
136
+ if err != nil {
137
+ return err
138
+ }
139
+ defer r .Body .Close ()
140
+
141
+ if r .StatusCode != http .StatusOK {
142
+ return fmt .Errorf ("GET '%s': %s" , url , r .Status )
143
+ }
144
+
145
+ r , err = http .PostForm (url , form )
146
+ if err != nil {
147
+ return err
148
+ }
149
+ defer r .Body .Close ()
150
+
151
+ if r .StatusCode != http .StatusOK {
152
+ return fmt .Errorf ("POST '%s': %s" , url , r .Status )
153
+ }
154
+
155
+ return nil
156
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 The Gitea Authors. All rights reserved.
2
+ // Use of this source code is governed by a MIT-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package integration
6
+
7
+ import (
8
+ "os"
9
+ "testing"
10
+
11
+ "code.gitea.io/gitea/integrations/internal/utils"
12
+ )
13
+
14
+ var signupFormSample map [string ][]string = map [string ][]string {
15
+ "Name" : []string {"tester" },
16
+ "Email" : []string {"user1@example.com" },
17
+ "Passwd" : []string {"12345678" },
18
+ }
19
+
20
+ func signup (t * utils.T ) error {
21
+ return utils .GetAndPost ("http://:" + ServerHTTPPort + "/user/sign_up" , signupFormSample )
22
+ }
23
+
24
+ func TestSignup (t * testing.T ) {
25
+ conf := utils.Config {
26
+ Program : "../gitea" ,
27
+ WorkDir : "" ,
28
+ Args : []string {"web" , "--port" , ServerHTTPPort },
29
+ LogFile : os .Stderr ,
30
+ }
31
+
32
+ if err := utils .New (t , & conf ).RunTest (install , signup ); err != nil {
33
+ t .Fatal (err )
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments