1 package capabilities
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7
8 "edge-infra.dev/pkg/edge/api/graph/model"
9 )
10
11 var testLabels = []*model.Label{
12 {
13 Key: "test-label",
14 Color: "#eeeeee",
15 Visible: true,
16 Editable: false,
17 Unique: false,
18 Description: "test-label",
19 Type: "test-label-type",
20 },
21 {
22 Key: "test-label-2",
23 Color: "#eeeeee",
24 Visible: true,
25 Editable: false,
26 Unique: false,
27 Description: "test-label-2",
28 Type: "test-label-type-2",
29 },
30 {
31 Key: VirtualMachinesPallet,
32 Color: capabilityLabelColor,
33 Visible: true,
34 Editable: false,
35 Unique: false,
36 Description: "optional pallet edge capability",
37 Type: EdgeCapabilitiesLabel,
38 },
39 {
40 Key: DistributedStoragePallet,
41 Color: capabilityLabelColor,
42 Visible: true,
43 Editable: false,
44 Unique: false,
45 Description: "optional pallet edge capability",
46 Type: EdgeCapabilitiesLabel,
47 },
48 {
49 Key: MetricsPallet,
50 Color: capabilityLabelColor,
51 Visible: true,
52 Editable: false,
53 Unique: false,
54 Description: "optional pallet edge capability",
55 Type: EdgeCapabilitiesLabel,
56 },
57 }
58
59 func TestGetCapabilityLabelsNoCapabilityParam(t *testing.T) {
60 labels := GetCapabilityLabels(testLabels)
61 assert.Equal(t, 3, len(labels))
62 assert.Equal(t, testLabels[2], labels[0])
63 assert.Equal(t, testLabels[3], labels[1])
64 assert.Equal(t, testLabels[4], labels[2])
65 }
66
67 func TestGetCapabilityLabelsWithCapabilityParam(t *testing.T) {
68 labels := GetCapabilityLabels(testLabels, VirtualMachinesPallet)
69 assert.Equal(t, 1, len(labels))
70 assert.Equal(t, testLabels[2], labels[0])
71 }
72
73 func TestGetCapabilityLabelsForSupportedVersionNoFloorVersion(t *testing.T) {
74 capabilityLabels := GetCapabilityLabels(testLabels)
75 supportedLabels, err := GetCapabilityLabelsForSupportedVersion(capabilityLabels, "0.20.0", nil)
76 assert.NoError(t, err)
77 assert.Equal(t, 2, len(supportedLabels))
78 assert.Equal(t, testLabels[2], supportedLabels[0])
79 supportedLabels2, err := GetCapabilityLabelsForSupportedVersion(capabilityLabels, "0.21.0", nil)
80 assert.NoError(t, err)
81 assert.Equal(t, 3, len(supportedLabels2))
82 assert.Equal(t, testLabels[2], supportedLabels2[0])
83 assert.Equal(t, testLabels[3], supportedLabels2[1])
84 assert.Equal(t, testLabels[4], supportedLabels2[2])
85 }
86
87 func TestGetCapabilityLabelsForSupportedVersionWithFloorVersion(t *testing.T) {
88 floorVersion := "0.20.0"
89 capabilityLabels := GetCapabilityLabels(testLabels)
90 supportedLabels, err := GetCapabilityLabelsForSupportedVersion(capabilityLabels, "0.21.0", &floorVersion)
91 assert.NoError(t, err)
92 assert.Equal(t, 1, len(supportedLabels))
93 assert.Equal(t, testLabels[4], supportedLabels[0])
94 }
95
View as plain text