-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
134 lines (115 loc) · 4.17 KB
/
main_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"bytes"
"flag"
"fmt"
"github.com/Peripli/istio-broker-proxy/pkg/router"
. "github.com/onsi/gomega"
"istio.io/istio/pkg/log"
"os"
"os/exec"
"strings"
"testing"
)
func newMockConfigStore(dummy string) router.ConfigStore {
return router.NewMockConfigStore()
}
func TestSetupConfiguration(t *testing.T) {
g := NewGomegaWithT(t)
args := strings.Split("--port 8000 --forwardUrl https://192.168.252.10:9293/cf --skipVerifyTLS --systemdomain istio.xxx.io --providerId istio.yyy.io --loadBalancerPort 9000 --configStore file:///var/vcap/store/istio-config --ipAddress 10.0.81.0 --serviceNamePrefix istio- ", " ")
flag.CommandLine.Parse(args)
g.Expect(routerConfig.SkipVerifyTLS).To(BeTrue())
g.Expect(producerInterceptor.ProviderID).To(Equal("istio.yyy.io"))
}
func TestConfigureProducerInterceptor(t *testing.T) {
g := NewGomegaWithT(t)
args := strings.Split("--port 8000 --forwardUrl https://192.168.252.10:9293/cf --skipVerifyTLS --systemdomain istio.xxx.io --providerId istio.yyy.io --loadBalancerPort 9000 --configStore file:///tmp --ipAddress 10.0.81.0 --serviceNamePrefix istio- --networkProfile xxx.yyy", " ")
flag.CommandLine.Parse(args)
interceptor, ok := configureInterceptor(newMockConfigStore).(router.ProducerInterceptor)
g.Expect(ok).To(BeTrue())
g.Expect(interceptor.NetworkProfile).To(Equal("xxx.yyy"))
g.Expect(interceptor.SystemDomain).To(Equal("istio.xxx.io"))
}
func TestConfigureConsumerInterceptor(t *testing.T) {
g := NewGomegaWithT(t)
args := strings.Split("--port 8000 --forwardUrl https://192.168.252.10:9293/cf --skipVerifyTLS --consumerId istio.yyy.io --loadBalancerPort 9000 --configStore file:///tmp --ipAddress 10.0.81.0 --serviceNamePrefix istio- --networkProfile xxx.yyy", " ")
flag.CommandLine.Parse(args)
interceptor, ok := configureInterceptor(newMockConfigStore).(router.ConsumerInterceptor)
g.Expect(ok).To(BeTrue())
g.Expect(interceptor.NetworkProfile).To(Equal("xxx.yyy"))
g.Expect(interceptor.ConsumerID).To(Equal("istio.yyy.io"))
}
func TestMain(m *testing.M) {
SetupConfiguration()
os.Exit(m.Run())
}
func TestNewConfigStoreInvalidSchema(t *testing.T) {
g := NewGomegaWithT(t)
_, err := newConfigStore("xxx://")
g.Expect(err).To(HaveOccurred())
}
func TestNewConfigStoreFile(t *testing.T) {
g := NewGomegaWithT(t)
_, err := newConfigStore("file:///tmp")
g.Expect(err).NotTo(HaveOccurred())
}
func TestNewConfigStoreInvalidURL(t *testing.T) {
g := NewGomegaWithT(t)
_, err := newConfigStore("\x7f")
g.Expect(err).To(HaveOccurred())
}
func TestLogLevelDebug(t *testing.T) {
g := NewGomegaWithT(t)
fmt.Printf("%s", os.Getenv("LOG"))
if os.Getenv("LOG") == "1" {
args := strings.Split("--logLevel 5", " ")
flag.CommandLine.Parse(args)
configureLogging()
log.Debugf("Debug logging enabled")
log.Sync()
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestLogLevelDebug")
cmd.Env = append(os.Environ(), "LOG=1")
var out, err bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &err
cmd.Run()
fmt.Println(out.String())
fmt.Println(err.String())
g.Expect(out.String()).To(ContainSubstring("Log level is set to 5"))
g.Expect(out.String()).To(ContainSubstring("Debug logging enabled"))
}
func TestDefaultLogLevelInfo(t *testing.T) {
g := NewGomegaWithT(t)
fmt.Printf("%s", os.Getenv("LOG"))
if os.Getenv("LOG") == "1" {
flag.CommandLine.Parse([]string{})
configureLogging()
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestDefaultLogLevelInfo")
cmd.Env = append(os.Environ(), "LOG=1")
var out bytes.Buffer
cmd.Stdout = &out
cmd.Run()
g.Expect(out.String()).To(ContainSubstring("Log level is set to 4"))
}
func TestNoDebugMessageInInfo(t *testing.T) {
g := NewGomegaWithT(t)
fmt.Printf("%s", os.Getenv("LOG"))
if os.Getenv("LOG") == "1" {
args := strings.Split("--logLevel 4 --networkProfile xxx.yyy", " ")
flag.CommandLine.Parse(args)
configureLogging()
log.Debugf("Debug logging enabled")
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestDefaultLogLevelInfo")
cmd.Env = append(os.Environ(), "LOG=1")
var out bytes.Buffer
cmd.Stdout = &out
cmd.Run()
g.Expect(out.String()).To(ContainSubstring("Log level is set to 4"))
g.Expect(out.String()).NotTo(ContainSubstring("Debug logging enabled"))
}