|
| 1 | +// Copyright Mondoo, Inc. 2026 |
| 2 | +// SPDX-License-Identifier: BUSL-1.1 |
| 3 | + |
| 4 | +package k8s_scan |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 11 | + |
| 12 | + "go.mondoo.com/mondoo-operator/api/v1alpha2" |
| 13 | +) |
| 14 | + |
| 15 | +const testClusterUID = "abcdefg" |
| 16 | + |
| 17 | +func TestInventory_WithAnnotations(t *testing.T) { |
| 18 | + auditConfig := v1alpha2.MondooAuditConfig{ |
| 19 | + ObjectMeta: metav1.ObjectMeta{Name: "mondoo-client"}, |
| 20 | + Spec: v1alpha2.MondooAuditConfigSpec{ |
| 21 | + Annotations: map[string]string{ |
| 22 | + "env": "prod", |
| 23 | + "team": "platform", |
| 24 | + }, |
| 25 | + }, |
| 26 | + } |
| 27 | + |
| 28 | + inv, err := Inventory("", testClusterUID, auditConfig, v1alpha2.MondooOperatorConfig{}) |
| 29 | + assert.NoError(t, err, "unexpected error generating inventory") |
| 30 | + assert.Contains(t, inv, "env") |
| 31 | + assert.Contains(t, inv, "prod") |
| 32 | + assert.Contains(t, inv, "team") |
| 33 | + assert.Contains(t, inv, "platform") |
| 34 | +} |
| 35 | + |
| 36 | +func TestExternalClusterInventory_WithAnnotations(t *testing.T) { |
| 37 | + auditConfig := v1alpha2.MondooAuditConfig{ |
| 38 | + ObjectMeta: metav1.ObjectMeta{Name: "mondoo-client"}, |
| 39 | + Spec: v1alpha2.MondooAuditConfigSpec{ |
| 40 | + Annotations: map[string]string{ |
| 41 | + "env": "staging", |
| 42 | + "team": "security", |
| 43 | + }, |
| 44 | + }, |
| 45 | + } |
| 46 | + |
| 47 | + cluster := v1alpha2.ExternalCluster{ |
| 48 | + Name: "remote-cluster", |
| 49 | + } |
| 50 | + |
| 51 | + inv, err := ExternalClusterInventory("", testClusterUID, cluster, auditConfig, v1alpha2.MondooOperatorConfig{}) |
| 52 | + assert.NoError(t, err, "unexpected error generating inventory") |
| 53 | + assert.Contains(t, inv, "env") |
| 54 | + assert.Contains(t, inv, "staging") |
| 55 | + assert.Contains(t, inv, "team") |
| 56 | + assert.Contains(t, inv, "security") |
| 57 | +} |
0 commit comments