Skip to content

Commit 4ab7e6a

Browse files
ValClarksonJeff McCormick
authored andcommitted
adding new tests and updated setupkube.go to work with gcp (CrunchyData#832)
1 parent d43c042 commit 4ab7e6a

File tree

3 files changed

+241
-1
lines changed

3 files changed

+241
-1
lines changed

testing/simple/setupkube.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"k8s.io/client-go/kubernetes"
1515
"k8s.io/client-go/rest"
1616
"k8s.io/client-go/tools/clientcmd"
17+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
1718
)
1819

1920
var (
@@ -22,7 +23,7 @@ var (
2223
testclustername = flag.String("clustername", "", "cluster name to test with")
2324

2425
Namespace = "pgouser1"
25-
TestClusterName = "foo"
26+
TestClusterName = "foomatic"
2627
SLEEP_SECS = 10
2728
)
2829

testing/simple/show_test.go

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package smoketest
2+
3+
import (
4+
//meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
"k8s.io/client-go/kubernetes"
6+
"os/exec"
7+
"strings"
8+
"testing"
9+
)
10+
11+
func TestShowCluster(t *testing.T) {
12+
var clientset *kubernetes.Clientset
13+
var cluster string
14+
15+
// t.Fatal("not implemented")
16+
t.Run("setup", func(t *testing.T) {
17+
t.Log("some setup code")
18+
clientset, _ = SetupKube()
19+
if clientset == nil {
20+
t.Error("clientset is nil")
21+
}
22+
})
23+
24+
tests := []struct {
25+
name string
26+
args []string
27+
fixture string
28+
}{
29+
{"pgo show cluster", []string{"show", "cluster", TestClusterName}, ""},
30+
}
31+
32+
t.Log("TestShowCluster starts")
33+
for _, tt := range tests {
34+
cmd := exec.Command("pgo", tt.args...)
35+
output, err := cmd.CombinedOutput()
36+
if err != nil {
37+
//t.Fatal(err)
38+
}
39+
40+
actual := string(output)
41+
42+
t.Logf("actual %s- ", actual)
43+
cluster = "cluster : " + TestClusterName
44+
found := strings.Contains(actual, cluster)
45+
if !found {
46+
t.Error("could not find cluster : " + TestClusterName + "in output")
47+
}
48+
49+
}
50+
51+
t.Run("teardown", func(t *testing.T) {
52+
t.Log("some teardown code")
53+
})
54+
}
55+
56+
func TestShowNamespace(t *testing.T) {
57+
var clientset *kubernetes.Clientset
58+
59+
// t.Fatal("not implemented")
60+
t.Run("setup", func(t *testing.T) {
61+
t.Log("some setup code")
62+
clientset, _ = SetupKube()
63+
if clientset == nil {
64+
t.Error("clientset is nil")
65+
}
66+
})
67+
68+
tests := []struct {
69+
name string
70+
args []string
71+
fixture string
72+
}{
73+
{"pgo show namespace", []string{"show", "namespace"}, ""},
74+
}
75+
76+
t.Log("TestShowNamespace starts")
77+
for _, tt := range tests {
78+
cmd := exec.Command("pgo", tt.args...)
79+
output, err := cmd.CombinedOutput()
80+
if err != nil {
81+
//t.Fatal(err)
82+
}
83+
84+
actual := string(output)
85+
86+
t.Logf("actual %s- ", actual)
87+
found := strings.Contains(actual, Namespace)
88+
if !found {
89+
t.Error("could not find " + Namespace + "namespace in output")
90+
}
91+
92+
}
93+
94+
t.Run("teardown", func(t *testing.T) {
95+
t.Log("some teardown code")
96+
})
97+
}
98+
99+
100+
func TestShowPvc(t *testing.T) {
101+
var clientset *kubernetes.Clientset
102+
103+
// t.Fatal("not implemented")
104+
t.Run("setup", func(t *testing.T) {
105+
t.Log("some setup code")
106+
clientset, _ = SetupKube()
107+
if clientset == nil {
108+
t.Error("clientset is nil")
109+
}
110+
})
111+
112+
tests := []struct {
113+
name string
114+
args []string
115+
fixture string
116+
}{
117+
{"pgo show pvc", []string{"show", "pvc", TestClusterName}, ""},
118+
}
119+
120+
t.Log("TestShowPvc starts")
121+
for _, tt := range tests {
122+
cmd := exec.Command("pgo", tt.args...)
123+
output, err := cmd.CombinedOutput()
124+
if err != nil {
125+
//t.Fatal(err)
126+
}
127+
128+
actual := string(output)
129+
130+
t.Logf("actual %s- ", actual)
131+
found := strings.Contains(actual, "pgdata")
132+
if !found {
133+
t.Error("could not find pgdata in output")
134+
}
135+
136+
}
137+
138+
t.Run("teardown", func(t *testing.T) {
139+
t.Log("some teardown code")
140+
})
141+
}
142+

testing/simple/user_test.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package smoketest
2+
3+
import (
4+
//meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
"k8s.io/client-go/kubernetes"
6+
"os/exec"
7+
"strings"
8+
"testing"
9+
)
10+
11+
func TestCreateUser(t *testing.T) {
12+
var clientset *kubernetes.Clientset
13+
14+
// t.Fatal("not implemented")
15+
t.Run("setup", func(t *testing.T) {
16+
t.Log("some setup code")
17+
clientset, _ = SetupKube()
18+
if clientset == nil {
19+
t.Error("clientset is nil")
20+
}
21+
})
22+
23+
tests := []struct {
24+
name string
25+
args []string
26+
fixture string
27+
}{
28+
{"pgo create user", []string{"create", "user", "test2", "--managed","--selector=name=" + TestClusterName }, ""},
29+
}
30+
31+
t.Log("TestCreateUser starts")
32+
for _, tt := range tests {
33+
cmd := exec.Command("pgo", tt.args...)
34+
output, err := cmd.CombinedOutput()
35+
if err != nil {
36+
//t.Fatal(err)
37+
}
38+
39+
actual := string(output)
40+
41+
t.Logf("actual %s- ", actual)
42+
found := strings.Contains(actual, "adding new user")
43+
if !found {
44+
t.Error("could not find adding new user in output")
45+
}
46+
47+
}
48+
49+
t.Run("teardown", func(t *testing.T) {
50+
t.Log("some teardown code")
51+
})
52+
}
53+
54+
55+
func TestDeleteUser(t *testing.T) {
56+
var clientset *kubernetes.Clientset
57+
58+
// t.Fatal("not implemented")
59+
t.Run("setup", func(t *testing.T) {
60+
t.Log("some setup code")
61+
clientset, _ = SetupKube()
62+
if clientset == nil {
63+
t.Error("clientset is nil")
64+
}
65+
})
66+
67+
tests := []struct {
68+
name string
69+
args []string
70+
fixture string
71+
}{
72+
{"pgo delete user", []string{"delete", "user", "test1", "--selector=name=" + TestClusterName }, ""},
73+
}
74+
75+
t.Log("TestCreateUser starts")
76+
for _, tt := range tests {
77+
cmd := exec.Command("pgo", tt.args...)
78+
output, err := cmd.CombinedOutput()
79+
if err != nil {
80+
//t.Fatal(err)
81+
}
82+
83+
actual := string(output)
84+
85+
t.Logf("actual %s- ", actual)
86+
found := strings.Contains(actual, "delete")
87+
if !found {
88+
t.Error("could not find delete in output")
89+
}
90+
91+
}
92+
93+
t.Run("teardown", func(t *testing.T) {
94+
t.Log("some teardown code")
95+
})
96+
}
97+
//TODO: need to add pgo show user

0 commit comments

Comments
 (0)