forked from micro/micro
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv_test.go
executable file
·117 lines (102 loc) · 2.66 KB
/
env_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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//go:build integration
// +build integration
package test
import (
"os/exec"
"strings"
"testing"
)
func TestEnvBasic(t *testing.T) {
TrySuite(t, testEnvOverrides, retryCount)
}
func testEnvBasic(t *T) {
outp, err := exec.Command("micro", "-env=platform", "env").CombinedOutput()
if err != nil {
t.Fatal(err)
return
}
if !strings.Contains(string(outp), "platform") ||
!strings.Contains(string(outp), "server") ||
!strings.Contains(string(outp), "local") {
t.Fatal("Env output lacks local, server, or platform")
return
}
}
func TestEnvOverrides(t *testing.T) {
TrySuite(t, testEnvOverrides, retryCount)
}
func testEnvOverrides(t *T) {
outp, err := exec.Command("micro", "-env=platform", "env").CombinedOutput()
if err != nil {
t.Fatal(err)
return
}
if !strings.Contains(string(outp), "* platform") {
t.Fatal("Env platform is not selected")
return
}
outp, err = exec.Command("micro", "-e=platform", "env").CombinedOutput()
if err != nil {
t.Fatal(err)
return
}
if !strings.Contains(string(outp), "* platform") {
t.Fatal("Env platform is not selected")
return
}
}
func TestEnvOps(t *testing.T) {
TrySuite(t, testEnvOps, retryCount)
}
func testEnvOps(t *T) {
// add an env
_, err := exec.Command("micro", "env", "add", "fooTestEnvOps", "127.0.0.1:8081").CombinedOutput()
if err != nil {
t.Fatalf("Error running micro env %s", err)
return
}
outp, err := exec.Command("micro", "env").CombinedOutput()
if err != nil {
t.Fatalf("Error running micro env %s", err)
return
}
if !strings.Contains(string(outp), "fooTestEnvOps") {
t.Fatalf("Cannot find expected environment. Output %s", outp)
return
}
// can we actually set it correctly
_, err = exec.Command("micro", "env", "set", "fooTestEnvOps").CombinedOutput()
if err != nil {
t.Fatalf("Error running micro env %s", err)
return
}
outp, err = exec.Command("micro", "env").CombinedOutput()
if err != nil {
t.Fatalf("Error running micro env %s", err)
return
}
if !strings.Contains(string(outp), "* fooTestEnvOps") {
t.Fatalf("Environment not set. Output %s", outp)
return
}
_, err = exec.Command("micro", "env", "set", "local").CombinedOutput()
if err != nil {
t.Fatalf("Error running micro env %s", err)
return
}
// we should be able to delete it too
_, err = exec.Command("micro", "env", "del", "fooTestEnvOps").CombinedOutput()
if err != nil {
t.Fatalf("Error running micro env %s", err)
return
}
outp, err = exec.Command("micro", "env").CombinedOutput()
if err != nil {
t.Fatalf("Error running micro env %s", err)
return
}
if strings.Contains(string(outp), "fooTestEnvOps") {
t.Fatalf("Found unexpected environment. Output %s", outp)
return
}
}