-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathdiscovery_test.go
More file actions
109 lines (102 loc) · 2.43 KB
/
discovery_test.go
File metadata and controls
109 lines (102 loc) · 2.43 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
package resources
import (
"slices"
"testing"
"github.com/stretchr/testify/require"
"go.mondoo.com/mql/v13/providers-sdk/v1/inventory"
)
func TestAllResolvedResources(t *testing.T) {
expected := []string{
DiscoverySubscriptions,
DiscoveryInstancesApi,
DiscoverySqlServers,
DiscoveryPostgresServers,
DiscoveryPostgresFlexibleServers,
DiscoveryMySqlServers,
DiscoveryMySqlFlexibleServers,
DiscoveryAksClusters,
DiscoveryAppServiceApps,
DiscoveryCacheRedis,
DiscoveryBatchAccounts,
DiscoveryStorageAccounts,
DiscoveryKeyVaults,
DiscoverySecurityGroups,
DiscoveryCosmosDb,
DiscoveryVirtualNetworks,
DiscoveryInstances,
DiscoveryStorageContainers,
}
require.ElementsMatch(t, expected, All)
}
func TestAutoResolvedResources(t *testing.T) {
expected := []string{
DiscoverySubscriptions,
DiscoveryInstancesApi,
DiscoverySqlServers,
DiscoveryPostgresServers,
DiscoveryPostgresFlexibleServers,
DiscoveryMySqlServers,
DiscoveryMySqlFlexibleServers,
DiscoveryAksClusters,
DiscoveryAppServiceApps,
DiscoveryCacheRedis,
DiscoveryBatchAccounts,
DiscoveryStorageAccounts,
DiscoveryKeyVaults,
DiscoverySecurityGroups,
DiscoveryCosmosDb,
DiscoveryVirtualNetworks,
}
require.ElementsMatch(t, expected, Auto)
}
func TestGetDiscoveryTargets(t *testing.T) {
cases := []struct {
name string
targets []string
want []string
}{
{
name: "empty defaults to Auto",
targets: []string{},
want: Auto,
},
{
name: "all",
targets: []string{"all"},
want: All,
},
{
name: "all with extras",
targets: []string{"all", "projects", "instances"},
want: All,
},
{
name: "auto",
targets: []string{"auto"},
want: Auto,
},
{
name: "auto with extras",
targets: []string{"auto", "postgres-servers", "keyvaults-vaults"},
want: append(slices.Clone(Auto), DiscoveryPostgresServers, DiscoveryKeyVaults),
},
{
name: "explicit targets",
targets: []string{"postgres-servers", "keyvaults-vaults", "instances"},
want: []string{DiscoveryPostgresServers, DiscoveryKeyVaults, DiscoveryInstances},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
config := &inventory.Config{
Discover: &inventory.Discovery{
Targets: tc.targets,
},
}
got := getDiscoveryTargets(config)
require.ElementsMatch(t, tc.want, got)
})
}
}