summaryrefslogtreecommitdiffstats
path: root/integrations/version_test.go
diff options
context:
space:
mode:
authorMura Li <typeless@users.noreply.github.com>2017-03-06 22:13:17 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-06 22:13:17 +0800
commit848293671b5d9c31ce3eb9ad8a1f130edd0ee7c5 (patch)
treef6d6b3cdf62bdb58f8e9332e756444a289b4f4da /integrations/version_test.go
parent2215840363815a30dfe87244f59e90f8283fbb07 (diff)
downloadgitea-848293671b5d9c31ce3eb9ad8a1f130edd0ee7c5.tar.gz
gitea-848293671b5d9c31ce3eb9ad8a1f130edd0ee7c5.zip
Add basic integration test infrastructure (and new endpoint `/api/v1/version` for testing it) (#741)
* Implement '/api/v1/version' * Cleanup and various fixes * Enhance run.sh * Add install_test.go * Add parameter utils.Config for testing handlers * Re-organize TestVersion.go * Rename functions * handling process cleanup properly * Fix missing function renaming * Cleanup the 'retry' logic * Cleanup * Remove unneeded logging code * Logging messages tweaking * Logging message tweaking * Fix logging messages * Use 'const' instead of hardwired numbers * We don't really need retries anymore * Move constant ServerHttpPort to install_test.go * Restore mistakenly removed constant * Add required comments to make the linter happy. * Fix comments and naming to address linter's complaints * Detect Gitea executale version automatically * Remove tests/run.sh, `go test` suffices. * Make `make build` a prerequisite of `make test` * Do not sleep before trying * Speedup the server pinging loop * Use defined const instead of hardwired numbers * Remove redundant error handling * Use a dedicated target for running code.gitea.io/tests * Do not make 'test' depend on 'build' target * Rectify the excluded package list * Remove redundant 'exit 1' * Change the API to allow passing test.T to test handlers * Make testing.T an embedded field * Use assert.Equal to comparing results * Add copyright info * Parametrized logging output * Use tmpdir instead * Eliminate redundant casting * Remove unneeded variable * Fix last commit * Add missing copyright info * Replace fmt.Fprintf with fmt.Fprint * rename the xtest to integration-test * Use Symlink instead of hard-link for cross-device linking * Turn debugging logs on * Follow the existing framework for APIs * Output logs only if test.v is true * Re-order import statements * Enhance the error message * Fix comment which breaks the linter's rule * Rename 'integration-test' to 'e2e-test' for saving keystrokes * Add comment to avoid possible confusion * Rename tests -> integration-tests Also change back the Makefile to use `make integration-test`. * Use tests/integration for now * tests/integration -> integrations Slightly flattened directory hierarchy is better. * Update Makefile accordingly * Fix a missing change in Makefile * govendor update code.gitea.io/sdk/gitea * Fix comment of struct fields * Fix conditional nonsense * Fix missing updates regarding version string changes * Make variable naming more consistent * Check http status code * Rectify error messages
Diffstat (limited to 'integrations/version_test.go')
-rw-r--r--integrations/version_test.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/integrations/version_test.go b/integrations/version_test.go
new file mode 100644
index 0000000000..beda5c3ab7
--- /dev/null
+++ b/integrations/version_test.go
@@ -0,0 +1,82 @@
+// 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 (
+ "encoding/json"
+ "fmt"
+ "log"
+ "net/http"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "code.gitea.io/gitea/integrations/internal/utils"
+ "code.gitea.io/sdk/gitea"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func version(t *utils.T) error {
+ var err error
+
+ path, err := filepath.Abs(t.Config.Program)
+ if err != nil {
+ return err
+ }
+
+ cmd := exec.Command(path, "--version")
+ out, err := cmd.Output()
+ if err != nil {
+ return err
+ }
+
+ fields := strings.Fields(string(out))
+ if !strings.HasPrefix(string(out), "Gitea version") {
+ return fmt.Errorf("unexpected version string '%s' of the gitea executable", out)
+ }
+
+ expected := fields[2]
+
+ var r *http.Response
+ r, err = http.Get("http://:" + ServerHTTPPort + "/api/v1/version")
+ if err != nil {
+ return err
+ }
+ defer r.Body.Close()
+
+ if r.StatusCode != http.StatusOK {
+ return fmt.Errorf("'/api/v1/version': %s\n", r.Status)
+ }
+
+ var v gitea.ServerVersion
+
+ dec := json.NewDecoder(r.Body)
+ if err := dec.Decode(&v); err != nil {
+ return err
+ }
+
+ actual := v.Version
+
+ log.Printf("Actual: \"%s\" Expected: \"%s\"\n", actual, expected)
+ assert.Equal(t, expected, actual)
+
+ return nil
+}
+
+func TestVersion(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, version); err != nil {
+ t.Fatal(err)
+ }
+}