aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorMura Li <typeless@users.noreply.github.com>2017-03-11 22:30:29 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-11 22:30:29 +0800
commitbdcc1a23e0525da67d722c65bcdbb7e3fa7cfdf8 (patch)
treef3e5c488d9da2da2a17c215dca0279cd3145837a /integrations
parent8a98a25d8e538d7ef026147b14b937beba2b1056 (diff)
downloadgitea-bdcc1a23e0525da67d722c65bcdbb7e3fa7cfdf8.tar.gz
gitea-bdcc1a23e0525da67d722c65bcdbb7e3fa7cfdf8.zip
Add integration test for signup (#1135)
* Add integration test for signup * Remove unused functions * Refactoring * Add repo_create_test.go * Rollback the incomplete repo create test * Comply with linter requirements and simplify the code a little bit
Diffstat (limited to 'integrations')
-rw-r--r--integrations/internal/utils/utils.go31
-rw-r--r--integrations/signup_test.go35
2 files changed, 66 insertions, 0 deletions
diff --git a/integrations/internal/utils/utils.go b/integrations/internal/utils/utils.go
index 511fa478b9..e8380df39e 100644
--- a/integrations/internal/utils/utils.go
+++ b/integrations/internal/utils/utils.go
@@ -6,9 +6,11 @@ package utils
import (
"errors"
+ "fmt"
"io"
"io/ioutil"
"log"
+ "net/http"
"os"
"os/exec"
"path/filepath"
@@ -123,3 +125,32 @@ func (t *T) RunTest(tests ...func(*T) error) (err error) {
// Note that the return value 'err' may be updated by the 'defer' statement before despite it's returning nil here.
return nil
}
+
+// GetAndPost provides a convenient helper function for testing an HTTP endpoint with GET and POST method.
+// The function sends GET first and then POST with the given form.
+func GetAndPost(url string, form map[string][]string) error {
+ var err error
+ var r *http.Response
+
+ r, err = http.Get(url)
+ if err != nil {
+ return err
+ }
+ defer r.Body.Close()
+
+ if r.StatusCode != http.StatusOK {
+ return fmt.Errorf("GET '%s': %s", url, r.Status)
+ }
+
+ r, err = http.PostForm(url, form)
+ if err != nil {
+ return err
+ }
+ defer r.Body.Close()
+
+ if r.StatusCode != http.StatusOK {
+ return fmt.Errorf("POST '%s': %s", url, r.Status)
+ }
+
+ return nil
+}
diff --git a/integrations/signup_test.go b/integrations/signup_test.go
new file mode 100644
index 0000000000..c317b88d10
--- /dev/null
+++ b/integrations/signup_test.go
@@ -0,0 +1,35 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package integration
+
+import (
+ "os"
+ "testing"
+
+ "code.gitea.io/gitea/integrations/internal/utils"
+)
+
+var signupFormSample map[string][]string = map[string][]string{
+ "Name": []string{"tester"},
+ "Email": []string{"user1@example.com"},
+ "Passwd": []string{"12345678"},
+}
+
+func signup(t *utils.T) error {
+ return utils.GetAndPost("http://:"+ServerHTTPPort+"/user/sign_up", signupFormSample)
+}
+
+func TestSignup(t *testing.T) {
+ conf := utils.Config{
+ Program: "../gitea",
+ WorkDir: "",
+ Args: []string{"web", "--port", ServerHTTPPort},
+ LogFile: os.Stderr,
+ }
+
+ if err := utils.New(t, &conf).RunTest(install, signup); err != nil {
+ t.Fatal(err)
+ }
+}