-
Notifications
You must be signed in to change notification settings - Fork 344
/
controller_test.go
138 lines (116 loc) · 3.69 KB
/
controller_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
135
136
137
138
package controller
import (
"context"
"testing"
"github.com/operator-framework/operator-sdk/pkg/sdk"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
)
func TestNewControllerForAllInOneAsDefault(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestNewControllerForAllInOneAsDefault")
ctrl := NewController(context.TODO(), jaeger)
rightType := false
switch ctrl.(type) {
case *allInOneController:
rightType = true
}
assert.True(t, rightType)
}
func TestNewControllerForAllInOneAsExplicitValue(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestNewControllerForAllInOneAsExplicitValue")
jaeger.Spec.Strategy = "ALL-IN-ONE" // same as 'all-in-one'
ctrl := NewController(context.TODO(), jaeger)
rightType := false
switch ctrl.(type) {
case *allInOneController:
rightType = true
}
assert.True(t, rightType)
}
func TestNewControllerForProduction(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestNewControllerForProduction")
jaeger.Spec.Strategy = "production"
ctrl := NewController(context.TODO(), jaeger)
ds := ctrl.Create()
assert.Len(t, ds, 6)
}
func TestUnknownStorage(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestNewControllerForProduction")
jaeger.Spec.Storage.Type = "unknown"
normalize(jaeger)
assert.Equal(t, "memory", jaeger.Spec.Storage.Type)
}
func TestElasticsearchAsStorageOptions(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestElasticsearchAsStorageOptions")
jaeger.Spec.Strategy = "production"
jaeger.Spec.Storage.Type = "elasticsearch"
jaeger.Spec.Storage.Options = v1alpha1.NewOptions(map[string]interface{}{
"es.server-urls": "http://elasticsearch-example-es-cluster:9200",
})
ctrl := NewController(context.TODO(), jaeger)
ds := ctrl.Create()
deps := getDeployments(ds)
assert.Len(t, deps, 2) // query and collector, for a production setup
counter := 0
for _, dep := range deps {
for _, arg := range dep.Spec.Template.Spec.Containers[0].Args {
if arg == "--es.server-urls=http://elasticsearch-example-es-cluster:9200" {
counter++
}
}
}
assert.Equal(t, len(deps), counter)
}
func TestDefaultName(t *testing.T) {
jaeger := &v1alpha1.Jaeger{}
normalize(jaeger)
assert.NotEmpty(t, jaeger.Name)
}
func TestIncompatibleStorageForProduction(t *testing.T) {
jaeger := &v1alpha1.Jaeger{
Spec: v1alpha1.JaegerSpec{
Strategy: "production",
Storage: v1alpha1.JaegerStorageSpec{
Type: "memory",
},
},
}
normalize(jaeger)
assert.Equal(t, "all-in-one", jaeger.Spec.Strategy)
}
func getDeployments(objs []sdk.Object) []*appsv1.Deployment {
var deps []*appsv1.Deployment
for _, obj := range objs {
switch obj.(type) {
case *appsv1.Deployment:
deps = append(deps, obj.(*appsv1.Deployment))
}
}
return deps
}
func assertHasAllObjects(t *testing.T, name string, objs []sdk.Object, deployments map[string]bool, services map[string]bool, ingresses map[string]bool) {
for _, obj := range objs {
switch typ := obj.(type) {
case *appsv1.Deployment:
deployments[obj.(*appsv1.Deployment).ObjectMeta.Name] = true
case *v1.Service:
services[obj.(*v1.Service).ObjectMeta.Name] = true
case *v1beta1.Ingress:
ingresses[obj.(*v1beta1.Ingress).ObjectMeta.Name] = true
default:
assert.Failf(t, "unknown type to be deployed", "%v", typ)
}
}
for k, v := range deployments {
assert.True(t, v, "Expected %s to have been returned from the list of deployments", k)
}
for k, v := range services {
assert.True(t, v, "Expected %s to have been returned from the list of services", k)
}
for k, v := range ingresses {
assert.True(t, v, "Expected %s to have been returned from the list of ingress rules", k)
}
}