forked from deis/workflow-e2e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
103 lines (88 loc) · 1.98 KB
/
model.go
File metadata and controls
103 lines (88 loc) · 1.98 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package model
import (
"bytes"
"fmt"
"math/rand"
"path"
"runtime"
"strings"
"github.com/deis/workflow-e2e/tests/settings"
)
var Admin = User{
Username: "admin",
Password: "admin",
Email: "admintest@deis.com",
}
type User struct {
Username string
Password string
Email string
}
func NewUser() User {
randSuffix := rand.Intn(100000)
return User{
Username: fmt.Sprintf("test-%d", randSuffix),
Password: "asdf1234",
Email: fmt.Sprintf("test-%d@deis.io", randSuffix),
}
}
type App struct {
Name string
URL string
}
func NewApp() App {
name := fmt.Sprintf("test-%d", rand.Intn(999999999))
return App{
Name: name,
URL: strings.Replace(settings.DeisControllerURL, "deis", name, 1),
}
}
type Cmd struct {
Env []string
CommandLineString string
}
type Cert struct {
Name string
CertPath string
KeyPath string
}
func NewCert() Cert {
certPath := path.Join(getDir(), "..", "files", "certs")
return Cert{
Name: getRandCertName(),
CertPath: fmt.Sprintf("%s/www.foo.com.cert", certPath),
KeyPath: fmt.Sprintf("%s/www.foo.com.key", certPath),
}
}
func getRandCertName() string {
return fmt.Sprintf("%d-cert", rand.Intn(999999999))
}
func getDir() string {
_, filename, _, _ := runtime.Caller(1)
return path.Dir(filename)
}
// CmdResult represents a generic command result, with expected Out, Err and
// ExitCode
type CmdResult struct {
Out []byte
Err []byte
ExitCode int
}
// Satisfies returns whether or not the original CmdResult, ocd, meets all of
// the expectations contained in the expeced CmdResult, ecd
func (ocd CmdResult) Satisfies(ecd CmdResult) bool {
if !bytes.Contains(ocd.Out, ecd.Out) {
return false
}
if !bytes.Contains(ocd.Err, ecd.Err) {
return false
}
if ocd.ExitCode != ecd.ExitCode {
return false
}
return true
}
// String returns the CmdResult in printable form
func (ocd CmdResult) String() string {
return fmt.Sprintf("[Out: '%s', Err: '%s', ExitCode: '%d']", ocd.Out, ocd.Err, ocd.ExitCode)
}