@@ -7,7 +7,11 @@ import (
7
7
"testing"
8
8
9
9
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
10
+ "github.com/stretchr/testify/assert"
10
11
"github.com/stretchr/testify/require"
12
+ appsv1 "k8s.io/api/apps/v1"
13
+ corev1 "k8s.io/api/core/v1"
14
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
15
12
16
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/constants"
13
17
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/testutils"
@@ -42,3 +46,73 @@ func TestDaemonsetMetrics(t *testing.T) {
42
46
testutils .AssertMetricsInt (t , rm .Metrics [3 ], "k8s.daemonset.ready_nodes" ,
43
47
metricspb .MetricDescriptor_GAUGE_INT64 , 2 )
44
48
}
49
+
50
+ func TestTransform (t * testing.T ) {
51
+ originalDS := & appsv1.DaemonSet {
52
+ ObjectMeta : metav1.ObjectMeta {
53
+ Name : "my-daemonset" ,
54
+ Namespace : "default" ,
55
+ Labels : map [string ]string {
56
+ "app" : "my-app" ,
57
+ },
58
+ },
59
+ Spec : appsv1.DaemonSetSpec {
60
+ Selector : & metav1.LabelSelector {
61
+ MatchLabels : map [string ]string {
62
+ "app" : "my-app" ,
63
+ },
64
+ },
65
+ Template : corev1.PodTemplateSpec {
66
+ ObjectMeta : metav1.ObjectMeta {
67
+ Labels : map [string ]string {
68
+ "app" : "my-app" ,
69
+ },
70
+ },
71
+ Spec : corev1.PodSpec {
72
+ Containers : []corev1.Container {
73
+ {
74
+ Name : "my-container" ,
75
+ Image : "nginx:latest" ,
76
+ ImagePullPolicy : corev1 .PullAlways ,
77
+ Ports : []corev1.ContainerPort {
78
+ {
79
+ Name : "http" ,
80
+ ContainerPort : 80 ,
81
+ Protocol : corev1 .ProtocolTCP ,
82
+ },
83
+ },
84
+ },
85
+ },
86
+ },
87
+ },
88
+ },
89
+ Status : appsv1.DaemonSetStatus {
90
+ CurrentNumberScheduled : 3 ,
91
+ NumberReady : 3 ,
92
+ DesiredNumberScheduled : 3 ,
93
+ NumberMisscheduled : 0 ,
94
+ Conditions : []appsv1.DaemonSetCondition {
95
+ {
96
+ Type : "Available" ,
97
+ Status : corev1 .ConditionTrue ,
98
+ },
99
+ },
100
+ },
101
+ }
102
+ wantDS := & appsv1.DaemonSet {
103
+ ObjectMeta : metav1.ObjectMeta {
104
+ Name : "my-daemonset" ,
105
+ Namespace : "default" ,
106
+ Labels : map [string ]string {
107
+ "app" : "my-app" ,
108
+ },
109
+ },
110
+ Status : appsv1.DaemonSetStatus {
111
+ CurrentNumberScheduled : 3 ,
112
+ NumberReady : 3 ,
113
+ DesiredNumberScheduled : 3 ,
114
+ NumberMisscheduled : 0 ,
115
+ },
116
+ }
117
+ assert .Equal (t , wantDS , Transform (originalDS ))
118
+ }
0 commit comments