1
- package main
1
+ package integration
2
2
3
3
import (
4
4
"encoding/json"
5
- "flag"
6
5
"fmt"
7
- "os/exec"
8
- "regexp"
9
6
"strings"
10
7
"testing"
11
8
)
@@ -20,36 +17,6 @@ type MobileClientJson struct {
20
17
Spec MobileClientSpec
21
18
}
22
19
23
- var namespace = flag .String ("namespace" , "" , "Openshift namespace (most often Project) to run our integration tests in" )
24
- var name = flag .String ("name" , "" , "Client name to be created" )
25
- var executable = flag .String ("executable" , "" , "Executable under test" )
26
-
27
- type ValidationFunction = func (output []byte , err error ) (bool , []string )
28
-
29
- func EmptyValidation (output []byte , err error ) (bool , []string ) {
30
- return true , []string {}
31
- }
32
-
33
- func VNoErr (output []byte , err error ) (bool , []string ) {
34
- return err == nil , []string {fmt .Sprintf ("%s" , err )}
35
- }
36
-
37
- func VIsErr (output []byte , err error ) (bool , []string ) {
38
- return err != nil , []string {fmt .Sprintf ("%s" , err )}
39
- }
40
-
41
- func VRegex (pattern string ) func (output []byte , err error ) (bool , []string ) {
42
- return func (output []byte , err error ) (bool , []string ) {
43
- matched , errMatch := regexp .MatchString (pattern , fmt .Sprintf ("%s" , output ))
44
- if errMatch != nil {
45
- return false , []string {fmt .Sprintf ("Error in regexp %s when trying to match %s" , errMatch , pattern )}
46
- }
47
- if ! matched {
48
- return false , []string {fmt .Sprintf ("Expected combined output matching %s" , pattern )}
49
- }
50
- return true , []string {}
51
- }
52
- }
53
20
func VMobileClientJson (name string , clientType string ) func (output []byte , err error ) (bool , []string ) {
54
21
return func (output []byte , err error ) (bool , []string ) {
55
22
var parsed MobileClientJson
@@ -67,68 +34,32 @@ func VMobileClientJson(name string, clientType string) func(output []byte, err e
67
34
}
68
35
}
69
36
70
- func All (vs ... ValidationFunction ) ValidationFunction {
71
- return func (output []byte , err error ) (bool , []string ) {
72
- for _ , v := range vs {
73
- r , o := v (output , err )
74
- if ! r {
75
- return r , o
76
- }
77
- }
78
- return true , []string {}
79
- }
80
- }
81
-
82
- type CmdDesc struct {
83
- executable string
84
- Arg []string
85
- Validator ValidationFunction
86
- }
87
-
88
- func (c CmdDesc ) Add (arg ... string ) CmdDesc {
89
- return CmdDesc {c .executable , append (c .Arg , arg ... ), c .Validator }
90
- }
91
-
92
- func (c CmdDesc ) Complying (validator ValidationFunction ) CmdDesc {
93
- return CmdDesc {c .executable , c .Arg , All (c .Validator , validator )}
94
- }
95
-
96
- func (c CmdDesc ) Run (t * testing.T ) ([]byte , error ) {
97
- t .Log (c .Arg )
98
- cmd := exec .Command (c .executable , c .Arg ... )
99
- output , err := cmd .CombinedOutput ()
100
- t .Log (fmt .Sprintf ("%s\n " , output ))
101
- v , errs := c .Validator (output , err )
102
- if ! v {
103
- t .Fatal (errs )
104
- }
105
- return output , err
106
- }
107
-
108
- func ValidatedCmd (executable string , arg ... string ) CmdDesc {
109
- return CmdDesc {executable , arg , EmptyValidation }
110
- }
111
-
112
- func TestPositive (t * testing.T ) {
37
+ func TestClientJson (t * testing.T ) {
113
38
114
39
clientTypes := []string {
115
40
"cordova" ,
116
41
"iOS" ,
117
42
"android" ,
118
43
}
119
44
45
+ name := fmt .Sprintf ("%s-mobile-crud-test-entity" , * prefix )
120
46
m := ValidatedCmd (* executable , fmt .Sprintf ("--namespace=%s" , * namespace ), "-o=json" )
47
+ oc := ValidatedCmd ("oc" , fmt .Sprintf ("--namespace=%s" , * namespace ), "-o=json" )
121
48
for _ , clientType := range clientTypes {
122
49
t .Run (clientType , func (t * testing.T ) {
123
- expectedId := strings .ToLower (fmt .Sprintf ("%s-%s" , * name , clientType ))
124
- notExists := All (VIsErr , VRegex (".*Error: failed to get.*" ))
125
- exists := All (VNoErr , VMobileClientJson (* name , clientType ))
50
+ expectedId := strings .ToLower (fmt .Sprintf ("%s-%s" , name , clientType ))
51
+
52
+ notExists := All (VIsErr , VRegex (fmt .Sprintf (".*\" %s\" not found.*" , expectedId )))
53
+ exists := All (VNoErr , VMobileClientJson (name , clientType ))
54
+
126
55
m .Add ("get" , "client" , expectedId ).Complying (notExists ).Run (t )
127
- m .Add ("create" , "client" , * name , clientType ).Complying (exists ).Run (t )
56
+ oc .Add ("get" , "mobileclient" , expectedId ).Complying (notExists ).Run (t )
57
+ m .Add ("create" , "client" , name , clientType ).Complying (exists ).Run (t )
128
58
m .Add ("get" , "client" , expectedId ).Complying (exists ).Run (t )
59
+ oc .Add ("get" , "mobileclient" , expectedId ).Complying (exists ).Run (t )
129
60
m .Add ("delete" , "client" , expectedId ).Complying (VNoErr ).Run (t )
130
61
m .Add ("get" , "client" , expectedId ).Complying (notExists ).Run (t )
131
-
62
+ oc . Add ( "get" , "mobileclient" , expectedId ). Complying ( notExists ). Run ( t )
132
63
})
133
64
}
134
65
}
0 commit comments