forked from grafana/tempo-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtempomonolithic_controller_test.go
66 lines (60 loc) · 1.85 KB
/
tempomonolithic_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
package controllers
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
configv1alpha1 "github.com/grafana/tempo-operator/apis/config/v1alpha1"
"github.com/grafana/tempo-operator/apis/tempo/v1alpha1"
)
func TestReconcileMonolithic(t *testing.T) {
nsn := types.NamespacedName{Name: "sample", Namespace: "default"}
tempo := &v1alpha1.TempoMonolithic{
ObjectMeta: metav1.ObjectMeta{
Name: nsn.Name,
Namespace: nsn.Namespace,
},
}
err := k8sClient.Create(context.Background(), tempo)
require.NoError(t, err)
reconciler := TempoMonolithicReconciler{
Client: k8sClient,
Scheme: testScheme,
CtrlConfig: configv1alpha1.ProjectConfig{},
}
reconcile, err := reconciler.Reconcile(context.Background(), ctrl.Request{NamespacedName: nsn})
require.NoError(t, err)
assert.Equal(t, false, reconcile.Requeue)
// Check if objects of specific types were created and are managed by the operator
opts := []client.ListOption{
client.InNamespace(nsn.Namespace),
client.MatchingLabels(map[string]string{
"app.kubernetes.io/instance": nsn.Name,
"app.kubernetes.io/managed-by": "tempo-operator",
}),
}
{
list := &corev1.ConfigMapList{}
err = k8sClient.List(context.Background(), list, opts...)
assert.NoError(t, err)
assert.NotEmpty(t, list.Items)
}
{
list := &appsv1.StatefulSetList{}
err = k8sClient.List(context.Background(), list, opts...)
assert.NoError(t, err)
assert.NotEmpty(t, list.Items)
}
{
list := &corev1.ServiceList{}
err = k8sClient.List(context.Background(), list, opts...)
assert.NoError(t, err)
assert.NotEmpty(t, list.Items)
}
}