-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform_test.go
75 lines (59 loc) · 2.37 KB
/
platform_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// ██████╗ ██████╗ ██████╗ ███████╗██╗ ██╗███████╗██████╗ ███████╗████████╗
// ██╔════╝██╔═══██╗██╔══██╗██╔════╝██║ ██║██╔════╝██╔══██╗██╔════╝╚══██╔══╝
// ██║ ██║ ██║██║ ██║█████╗ ██║ █╗ ██║█████╗ ██████╔╝█████╗ ██║
// ██║ ██║ ██║██║ ██║██╔══╝ ██║███╗██║██╔══╝ ██╔══██╗██╔══╝ ██║
// ╚██████╗╚██████╔╝██████╔╝███████╗╚███╔███╔╝███████╗██║ ██║██║ ██║
// ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝
//
// Copyright 2015 Codewerft UG (http://www.codewerft.net).
// All rights reserved.
package platform_test
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/oweidner/platform"
)
var (
testserver *httptest.Server
serverURL string
)
func init() {
// Config file is passed via -config= flag.
var configFile = flag.String("config", "", "set configuration file")
flag.Parse()
p := platform.New(configFile)
// ADD APP specific routes and functions
testserver, serveError := p.UnitTestServe()
if serveError != nil {
// report the error
}
serverURL = testserver.URL
}
// TestGetVersion tests GET /platform/version
//
func TestGetVersion(t *testing.T) {
response, err := http.Get(fmt.Sprintf("%v/platform/version", serverURL))
if err != nil {
t.Fatal(err)
}
defer response.Body.Close()
contents, _ := ioutil.ReadAll(response.Body)
var dat map[string]interface{}
if err := json.Unmarshal(contents, &dat); err != nil {
t.Fatal(err)
}
v1 := dat["Server"].(string)
if v1 == "" {
t.Error("Server version empty.")
}
v2 := dat["API"].(string)
if v2 == "" {
t.Error("API version empty.")
}
}
// TestAuth tests POST /platform/auth