@@ -19,20 +19,15 @@ package main
19
19
import (
20
20
"bytes"
21
21
"context"
22
- "encoding/json"
23
22
"os"
24
23
"testing"
25
24
"time"
26
25
27
26
"github.com/deckhouse/deckhouse/pkg/log"
28
27
"github.com/deckhouse/module-sdk/pkg"
29
- "github.com/deckhouse/module-sdk/pkg/jq"
30
28
"github.com/deckhouse/module-sdk/testing/mock"
31
29
. "github.com/onsi/ginkgo"
32
30
. "github.com/onsi/gomega"
33
- v1 "k8s.io/api/core/v1"
34
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
35
- "sigs.k8s.io/yaml"
36
31
)
37
32
38
33
func TestDiscoveryVirthandlerNodes (t * testing.T ) {
@@ -44,28 +39,6 @@ var _ = Describe("Discovery virt-handler nodes", func() {
44
39
err := os .Setenv ("D8_IS_TESTS_ENVIRONMENT" , "true" )
45
40
Expect (err ).ShouldNot (HaveOccurred ())
46
41
47
- const (
48
- node1YAML = `
49
- ---
50
- apiVersion: v1
51
- kind: Node
52
- metadata:
53
- labels:
54
- kubevirt.internal.virtualization.deckhouse.io/schedulable: "true"
55
- name: node1
56
- `
57
-
58
- node2YAML = `
59
- ---
60
- apiVersion: v1
61
- kind: Node
62
- metadata:
63
- labels:
64
- kubevirt.internal.virtualization.deckhouse.io/schedulable: "true"
65
- name: node2
66
- `
67
- )
68
-
69
42
var (
70
43
snapshots * mock.SnapshotsMock
71
44
values * mock.PatchableValuesCollectorMock
@@ -74,16 +47,6 @@ metadata:
74
47
buf * bytes.Buffer
75
48
)
76
49
77
- filterResultNode1 , err := nodeYamlToSnapshot (node1YAML )
78
- if err != nil {
79
- Expect (err ).ShouldNot (HaveOccurred ())
80
- }
81
-
82
- filterResultNode2 , err := nodeYamlToSnapshot (node2YAML )
83
- if err != nil {
84
- Expect (err ).ShouldNot (HaveOccurred ())
85
- }
86
-
87
50
BeforeEach (func () {
88
51
snapshots = mock .NewSnapshotsMock (GinkgoT ())
89
52
values = mock .NewPatchableValuesCollectorMock (GinkgoT ())
@@ -112,19 +75,19 @@ metadata:
112
75
snapshots .GetMock .When (nodesSnapshot ).Then (
113
76
[]pkg.Snapshot {},
114
77
)
115
- values .SetMock .When (virtHandlerNodeCountPath , 1 )
78
+ values .SetMock .When (virtHandlerNodeCountPath , 0 )
116
79
err := handleDiscoveryVirtHandkerNodes (context .Background (), input )
117
80
Expect (err ).ShouldNot (HaveOccurred ())
118
81
})
119
82
})
120
83
121
- Context ("Four nodes but only two should be patched ." , func () {
84
+ Context ("Two nodes should be discovered ." , func () {
122
85
It ("Hook must execute successfully" , func () {
123
86
124
87
snapshots .GetMock .When (nodesSnapshot ).Then (
125
88
[]pkg.Snapshot {
126
- mock .NewSnapshotMock (GinkgoT ()).UnmarshalToMock . Set ( getNodeSnapshot ( filterResultNode1 ) ),
127
- mock .NewSnapshotMock (GinkgoT ()).UnmarshalToMock . Set ( getNodeSnapshot ( filterResultNode2 ) ),
89
+ mock .NewSnapshotMock (GinkgoT ()).StringMock . Return ( "n1" ),
90
+ mock .NewSnapshotMock (GinkgoT ()).StringMock . Return ( "n2" ),
128
91
},
129
92
)
130
93
@@ -135,34 +98,3 @@ metadata:
135
98
})
136
99
137
100
})
138
-
139
- func nodeYamlToSnapshot (manifest string ) (string , error ) {
140
- node := new (v1.Node )
141
- err := yaml .Unmarshal ([]byte (manifest ), node )
142
- if err != nil {
143
- return "" , err
144
- }
145
-
146
- query , err := jq .NewQuery (nodeJQFilter )
147
- if err != nil {
148
- return "" , err
149
- }
150
-
151
- filterResult , err := query .FilterObject (context .Background (), node )
152
- if err != nil {
153
- return "" , err
154
- }
155
-
156
- return filterResult .String (), nil
157
- }
158
-
159
- func getNodeSnapshot (nodeManifest string ) func (v any ) (err error ) {
160
- return func (v any ) (err error ) {
161
- rt := v .(* metav1.ObjectMeta )
162
- if err := json .Unmarshal ([]byte (nodeManifest ), rt ); err != nil {
163
- return err
164
- }
165
-
166
- return nil
167
- }
168
- }
0 commit comments