@@ -18,12 +18,14 @@ import (
18
18
"testing"
19
19
20
20
"github.com/stretchr/testify/assert"
21
+ corev1 "k8s.io/api/core/v1"
21
22
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22
23
23
24
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
25
+ "github.com/open-telemetry/opentelemetry-operator/internal/manifests"
24
26
)
25
27
26
- func TestServiceAccountNewDefault (t * testing.T ) {
28
+ func TestServiceAccountDefaultName (t * testing.T ) {
27
29
// prepare
28
30
otelcol := v1alpha1.OpenTelemetryCollector {
29
31
ObjectMeta : metav1.ObjectMeta {
@@ -32,13 +34,13 @@ func TestServiceAccountNewDefault(t *testing.T) {
32
34
}
33
35
34
36
// test
35
- sa := ServiceAccountName (otelcol )
37
+ saName := ServiceAccountName (otelcol )
36
38
37
39
// verify
38
- assert .Equal (t , "my-instance-collector " , sa )
40
+ assert .Equal (t , "my-instance-targetallocator " , saName )
39
41
}
40
42
41
- func TestServiceAccountOverride (t * testing.T ) {
43
+ func TestServiceAccountOverrideName (t * testing.T ) {
42
44
// prepare
43
45
otelcol := v1alpha1.OpenTelemetryCollector {
44
46
ObjectMeta : metav1.ObjectMeta {
@@ -57,3 +59,45 @@ func TestServiceAccountOverride(t *testing.T) {
57
59
// verify
58
60
assert .Equal (t , "my-special-sa" , sa )
59
61
}
62
+
63
+ func TestServiceAccountDefault (t * testing.T ) {
64
+ params := manifests.Params {
65
+ OtelCol : v1alpha1.OpenTelemetryCollector {
66
+ ObjectMeta : metav1.ObjectMeta {
67
+ Name : "my-instance" ,
68
+ },
69
+ },
70
+ }
71
+ expected := & corev1.ServiceAccount {
72
+ ObjectMeta : metav1.ObjectMeta {
73
+ Name : "my-instance-targetallocator" ,
74
+ Namespace : params .OtelCol .Namespace ,
75
+ Labels : Labels (params .OtelCol , "my-instance-targetallocator" ),
76
+ Annotations : params .OtelCol .Annotations ,
77
+ },
78
+ }
79
+
80
+ saName := ServiceAccountName (params .OtelCol )
81
+ sa := ServiceAccount (params )
82
+
83
+ assert .Equal (t , sa .Name , saName )
84
+ assert .Equal (t , expected , sa )
85
+ }
86
+
87
+ func TestServiceAccountOverride (t * testing.T ) {
88
+ params := manifests.Params {
89
+ OtelCol : v1alpha1.OpenTelemetryCollector {
90
+ ObjectMeta : metav1.ObjectMeta {
91
+ Name : "my-instance" ,
92
+ },
93
+ Spec : v1alpha1.OpenTelemetryCollectorSpec {
94
+ TargetAllocator : v1alpha1.OpenTelemetryTargetAllocator {
95
+ ServiceAccount : "my-special-sa" ,
96
+ },
97
+ },
98
+ },
99
+ }
100
+ sa := ServiceAccount (params )
101
+
102
+ assert .Nil (t , sa )
103
+ }
0 commit comments