@@ -1129,6 +1129,65 @@ func TestCollectInstallationFlags(t *testing.T) {
1129
1129
}
1130
1130
}
1131
1131
1132
+ func TestCollectBuildOS (t * testing.T ) {
1133
+ t .Parallel ()
1134
+
1135
+ testCases := []struct {
1136
+ name string
1137
+ buildOS string
1138
+ wantOS string
1139
+ }{
1140
+ {
1141
+ name : "debian plus image" ,
1142
+ buildOS : "debian-plus" ,
1143
+ wantOS : "debian-plus" ,
1144
+ },
1145
+ {
1146
+ name : "ubi-9 plus app protect image" ,
1147
+ buildOS : "ubi-9-plus-nap" ,
1148
+ wantOS : "ubi-9-plus-nap" ,
1149
+ },
1150
+ {
1151
+ name : "alpine oss image" ,
1152
+ buildOS : "alpine" ,
1153
+ wantOS : "alpine" ,
1154
+ },
1155
+ {
1156
+ name : "self built image" ,
1157
+ buildOS : "" ,
1158
+ wantOS : "" ,
1159
+ },
1160
+ }
1161
+
1162
+ for _ , tc := range testCases {
1163
+ t .Run (tc .name , func (t * testing.T ) {
1164
+ buf := & bytes.Buffer {}
1165
+ exp := & telemetry.StdoutExporter {Endpoint : buf }
1166
+
1167
+ configurator := newConfiguratorWithIngress (t )
1168
+
1169
+ cfg := telemetry.CollectorConfig {
1170
+ Configurator : configurator ,
1171
+ K8sClientReader : newTestClientset (node1 , kubeNS ),
1172
+ Version : telemetryNICData .ProjectVersion ,
1173
+ BuildOS : tc .buildOS ,
1174
+ }
1175
+
1176
+ c , err := telemetry .NewCollector (cfg , telemetry .WithExporter (exp ))
1177
+ if err != nil {
1178
+ t .Fatal (err )
1179
+ }
1180
+ c .Collect (context .Background ())
1181
+
1182
+ buildOS := c .BuildOS ()
1183
+
1184
+ if tc .wantOS != buildOS {
1185
+ t .Errorf ("want: %s, got: %s" , tc .wantOS , buildOS )
1186
+ }
1187
+ })
1188
+ }
1189
+ }
1190
+
1132
1191
func TestCountVirtualServersOnCustomResourceEnabled (t * testing.T ) {
1133
1192
t .Parallel ()
1134
1193
0 commit comments