Skip to content

Commit 0f5c6ce

Browse files
smothikimboersma
authored andcommitted
test(integration): add basic working framework files
1 parent 715bbca commit 0f5c6ce

7 files changed

Lines changed: 245 additions & 31 deletions

File tree

client/deis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def auth_cancel(self, args):
678678
self._settings.save()
679679
print('Account cancelled')
680680
else:
681-
print('Accont not changed')
681+
print('Account not changed')
682682

683683
def auth_login(self, args):
684684
"""

integration/auth_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package verbose
2+
3+
import (
4+
"fmt"
5+
"github.com/deis/deis/tests/integration-utils"
6+
"testing"
7+
)
8+
9+
func authSetup(t *testing.T) *AuthData {
10+
_ := itutils.GlobalSetup(t)
11+
ucfg := itutils.SetUser()
12+
fmt.Println("username :" + ucfg.UserName)
13+
fmt.Println("password :" + ucfg.Password)
14+
return &ucfg
15+
}
16+
17+
func authRegisterTest(t *testing.T, params *AuthData) {
18+
cmd := itutils.GetCommand("auth", "register")
19+
itutils.Execute(t, cmd, params, false)
20+
itutils.Execute(t, cmd, params, true)
21+
}
22+
23+
func authLoginTest(t *testing.T, params *AuthData) {
24+
cmd := itutils.GetCommand("auth", "login")
25+
itutils.Execute(t, cmd, params, false)
26+
params = authSetup(t)
27+
itutils.Execute(t, cmd, params, true)
28+
}
29+
30+
func authLogoutTest(t *testing.T, params *AuthData) {
31+
cmd := itutils.GetCommand("auth", "logout")
32+
itutils.Execute(t, cmd, params, false)
33+
34+
}
35+
36+
func authCancel() {
37+
fmt.Println("coming soon")
38+
}
39+
40+
func TestAuth(t *testing.T) {
41+
params := authSetup(t)
42+
authRegisterTest(t, params)
43+
authLogoutTest(t, params)
44+
authLoginTest(t, params)
45+
46+
}

integration/integration_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package verbose
2+
3+
import (
4+
"fmt"
5+
_ "github.com/deis/deis/tests/integration"
6+
_ "github.com/deis/deis/tests/utils"
7+
"testing"
8+
)
9+
10+
func authTest(t *testing.T) {
11+
fmt.Println("itutis")
12+
}

integration/keys_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package verbose
2+
3+
import (
4+
"fmt"
5+
"github.com/deis/deis/tests/integration-utils"
6+
"testing"
7+
)
8+
9+
func keysSetup(t *testing.T) *itutils.DeisTestConfig {
10+
cfg := itutils.GlobalSetup(t)
11+
return cfg
12+
}
13+
14+
func keysAddTest(t *testing.T, params *itutils.DeisTestConfig) {
15+
cmd := itutils.GetCommand("keys", "add")
16+
itutils.Execute(t, cmd, params, false)
17+
itutils.Execute(t, cmd, params, true)
18+
}
19+
20+
func keysListTest(t *testing.T, params *itutils.DeisTestConfig) {
21+
cmd := itutils.GetCommand("keys", "list")
22+
itutils.Execute(t, cmd, params, false)
23+
}
24+
25+
func keysRemoveTest(t *testing.T, params *itutils.DeisTestConfig) {
26+
cmd := itutils.GetCommand("keys", "remove")
27+
itutils.Execute(t, cmd, params, false)
28+
}
29+
30+
func authCancel() {
31+
fmt.Println("coming soon")
32+
}
33+
34+
func TestKeys(t *testing.T) {
35+
params := keysSetup(t)
36+
keysAddTest(t, params)
37+
keysListTest(t, params)
38+
keysRemoveTest(t, params)
39+
}

integration/testconfig.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"commands": {
3+
"auth": {
4+
"register":"register http://{{.HostName}} --username={{.UserName}} --password={{.Password}} --email={{.Email}}",
5+
"login": "auth:login http://{{.HostName}} --username={{.UserName}} --password={{.Password}}",
6+
"logout": "auth:logout",
7+
"cancel":"auth:cancel"
8+
},
9+
"keys": {
10+
"add": "keys:add {{.AuthKey}}.pub || true",
11+
"list": "keys:list",
12+
"remove": "keys:remove {{.AuthKey}}.pub ||true"
13+
}
14+
},
15+
"apps": {
16+
"go": ["example-go","helloworld"],
17+
"ruby" : ["example-ruby-sinatra"],
18+
"dart" : ["example-dart"],
19+
"java" : ["example-java-jetty","example-play"],
20+
"Javascript" : ["example-nodejs-express"],
21+
"python" : ["example-python-django","example-python-flask","example-dockerfile-python"],
22+
"scala" : ["example-scala"],
23+
"php": ["example-php"],
24+
"clojure":["example-clojure-ring"]
25+
}
26+
}

tests/integration-utils/itutils.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package itutils
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
gson "github.com/bitly/go-simplejson"
7+
"github.com/deis/deis/tests/utils"
8+
"os/exec"
9+
"testing"
10+
"text/template"
11+
)
12+
13+
var Deis = "/usr/local/bin/deis "
14+
15+
type DeisTestConfig struct {
16+
AuthKey string
17+
Hosts string
18+
HostName string
19+
SshKey string
20+
}
21+
22+
type UserDetails struct {
23+
UserName string
24+
Password string
25+
Email string
26+
HostName string
27+
}
28+
29+
func SetUser() *UserDetails {
30+
var user = new(UserDetails)
31+
user.UserName, user.Password = utils.GetUserDetails()
32+
user.Email = "test@test.co.nz"
33+
return user
34+
}
35+
36+
func GlobalSetup(t *testing.T) *DeisTestConfig {
37+
var envCfg = DeisTestConfig{
38+
"~/.ssh/deis",
39+
"54.193.41.120",
40+
"deis.54.193.9.175.xip.io",
41+
"~/.vagrant.d/insecure_private_key",
42+
}
43+
var user = UserDetails{
44+
"Test",
45+
"asdf1234",
46+
"test@test.co.nz",
47+
envCfg.HostName,
48+
}
49+
Execute(t, GetCommand("auth", "register"), user, false)
50+
return &envCfg
51+
}
52+
53+
func Execute(t *testing.T, cmd string, params interface{}, failFlag bool, expect string) {
54+
var cmdBuf bytes.Buffer
55+
tmpl := template.Must(template.New("cmd").Parse(cmd))
56+
if err := tmpl.Execute(&cmdBuf, params); err != nil {
57+
t.Fatal(err)
58+
}
59+
cmdString := cmdBuf.String()
60+
fmt.Println(cmdString)
61+
cmdl := exec.Command("sh", "-c", Deis+cmdString)
62+
if err := utils.RunCommandWithStdoutStderr(cmdl); err != nil {
63+
if failFlag {
64+
fmt.Println("Test Failed expected behavior ")
65+
} else {
66+
t.Fatalf("Output:\n%v", err)
67+
}
68+
} else if failFlag {
69+
t.Fatalf("test should be failed here but passing ")
70+
} else {
71+
fmt.Println("ok")
72+
}
73+
}
74+
75+
func GetCommand(cmdtype, cmd string) string {
76+
js, _ := gson.NewJson(utils.GetFileBytes("testconfig.json"))
77+
command, _ := js.Get("commands").Get(cmdtype).Get(cmd).String()
78+
return command
79+
}

tests/utils/utils.go

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package utils
22

33
import (
4+
"bufio"
45
"fmt"
6+
"github.com/satori/go.uuid"
57
"io"
68
"net"
79
"os"
810
"os/exec"
911
"strings"
1012
"syscall"
1113
"testing"
12-
13-
"github.com/satori/go.uuid"
14+
"time"
1415
)
1516

1617
// NewUuid returns a new V4-style unique identifier.
@@ -20,6 +21,21 @@ func NewUuid() string {
2021
return strings.Split(s1, "-")[0]
2122
}
2223

24+
func GetFileBytes(filename string) []byte {
25+
file, _ := os.Open(filename)
26+
defer file.Close()
27+
stat, _ := file.Stat()
28+
bs := make([]byte, stat.Size())
29+
_, _ = file.Read(bs)
30+
return bs
31+
}
32+
33+
func GetUserDetails() (string, string) {
34+
u1 := uuid.NewV4()
35+
s1 := fmt.Sprintf("%s", u1)
36+
return strings.Split(s1, "-")[0], strings.Split(s1, "-")[1]
37+
}
38+
2339
// GetHostOs returns either "darwin" or "ubuntu".
2440
func GetHostOs() string {
2541
cmd := exec.Command("uname")
@@ -69,45 +85,40 @@ func getExitCode(err error) (int, error) {
6985
return exitCode, fmt.Errorf("failed to get exit code")
7086
}
7187

72-
func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) {
73-
exitCode = 0
74-
out, err := cmd.CombinedOutput()
75-
if err != nil {
76-
var exiterr error
77-
if exitCode, exiterr = getExitCode(err); exiterr != nil {
78-
// TODO: Fix this so we check the error's text.
79-
// we've failed to retrieve exit code, so we set it to 127
80-
exitCode = 127
81-
}
82-
}
83-
output = string(out)
84-
return
85-
}
86-
87-
func runCommandWithStdoutStderr(cmd *exec.Cmd) (exitCode int, err error) {
88-
exitCode = 0
89-
// var stderrBuffer, stdoutBuffer bytes.Buffer
88+
func RunCommandWithStdoutStderr(cmd *exec.Cmd) (stdout, stderr bytes.Buffer, err error) {
89+
var stdout, stderr bytes.Buffer
9090
stderrPipe, err := cmd.StderrPipe()
9191
stdoutpipe, err := cmd.StdoutPipe()
9292

93+
cmd.Env = os.Environ()
9394
if err != nil {
94-
return -1, err
95+
return
9596
}
9697

9798
err = cmd.Start()
9899
if err != nil {
99-
var exiterr error
100-
if exitCode, exiterr = getExitCode(err); exiterr != nil {
101-
// TODO: Fix this so we check the error's text.
102-
// we've failed to retrieve exit code, so we set it to 127
103-
exitCode = 127
104-
}
100+
return
105101
}
106102

107-
go io.Copy(os.Stdout, stdoutpipe)
108-
go io.Copy(os.Stderr, stderrPipe)
109-
103+
go func() {
104+
io.Copy(&stdout, stdoutPipe)
105+
io.Copy(os.Stdout, stdoutPipe)
106+
}()
107+
go func() {
108+
io.Copy(&stderr, stderrPipe)
109+
io.Copy(os.Stderr, stderrPipe)
110+
}()
111+
time.Sleep(2000 * time.Millisecond)
110112
err = cmd.Wait()
113+
if err != nil {
114+
return
115+
}
116+
return
117+
}
118+
119+
func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) {
120+
exitCode = 0
121+
out, err := cmd.CombinedOutput()
111122
if err != nil {
112123
var exiterr error
113124
if exitCode, exiterr = getExitCode(err); exiterr != nil {
@@ -116,6 +127,7 @@ func runCommandWithStdoutStderr(cmd *exec.Cmd) (exitCode int, err error) {
116127
exitCode = 127
117128
}
118129
}
130+
output = string(out)
119131
return
120132
}
121133

0 commit comments

Comments
 (0)