Skip to content

Commit 612fc1c

Browse files
committed
fix tests
Signed-off-by: Pavel Tishkov <[email protected]>
1 parent bc07edd commit 612fc1c

File tree

3 files changed

+5
-78
lines changed

3 files changed

+5
-78
lines changed

images/hooks/cmd/discovery-virthandler-nodes/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ var configDiscoveryService = &pkg.HookConfig{
6363

6464
func handleDiscoveryVirtHandkerNodes(_ context.Context, input *pkg.HookInput) error {
6565
nodeCount := len(input.Snapshots.Get(nodesSnapshot))
66-
if nodeCount == 0 {
67-
nodeCount = 1
68-
}
6966
input.Values.Set(virtHandlerNodeCountPath, nodeCount)
7067
return nil
7168
}

images/hooks/cmd/discovery-virthandler-nodes/main_test.go

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,15 @@ package main
1919
import (
2020
"bytes"
2121
"context"
22-
"encoding/json"
2322
"os"
2423
"testing"
2524
"time"
2625

2726
"github.com/deckhouse/deckhouse/pkg/log"
2827
"github.com/deckhouse/module-sdk/pkg"
29-
"github.com/deckhouse/module-sdk/pkg/jq"
3028
"github.com/deckhouse/module-sdk/testing/mock"
3129
. "github.com/onsi/ginkgo"
3230
. "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"
3631
)
3732

3833
func TestDiscoveryVirthandlerNodes(t *testing.T) {
@@ -44,28 +39,6 @@ var _ = Describe("Discovery virt-handler nodes", func() {
4439
err := os.Setenv("D8_IS_TESTS_ENVIRONMENT", "true")
4540
Expect(err).ShouldNot(HaveOccurred())
4641

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-
6942
var (
7043
snapshots *mock.SnapshotsMock
7144
values *mock.PatchableValuesCollectorMock
@@ -74,16 +47,6 @@ metadata:
7447
buf *bytes.Buffer
7548
)
7649

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-
8750
BeforeEach(func() {
8851
snapshots = mock.NewSnapshotsMock(GinkgoT())
8952
values = mock.NewPatchableValuesCollectorMock(GinkgoT())
@@ -112,19 +75,19 @@ metadata:
11275
snapshots.GetMock.When(nodesSnapshot).Then(
11376
[]pkg.Snapshot{},
11477
)
115-
values.SetMock.When(virtHandlerNodeCountPath, 1)
78+
values.SetMock.When(virtHandlerNodeCountPath, 0)
11679
err := handleDiscoveryVirtHandkerNodes(context.Background(), input)
11780
Expect(err).ShouldNot(HaveOccurred())
11881
})
11982
})
12083

121-
Context("Four nodes but only two should be patched.", func() {
84+
Context("Two nodes should be discovered.", func() {
12285
It("Hook must execute successfully", func() {
12386

12487
snapshots.GetMock.When(nodesSnapshot).Then(
12588
[]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"),
12891
},
12992
)
13093

@@ -135,34 +98,3 @@ metadata:
13598
})
13699

137100
})
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-
}

images/hooks/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ require (
1616
k8s.io/api v0.30.11
1717
k8s.io/apimachinery v0.30.11
1818
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
19-
sigs.k8s.io/yaml v1.4.0
2019
)
2120

2221
require (
@@ -52,8 +51,6 @@ require (
5251
github.com/google/uuid v1.6.0 // indirect
5352
github.com/imdario/mergo v0.3.16 // indirect
5453
github.com/inconshreveable/mousetrap v1.1.0 // indirect
55-
github.com/itchyny/gojq v0.12.17 // indirect
56-
github.com/itchyny/timefmt-go v0.1.6 // indirect
5754
github.com/jmoiron/sqlx v1.3.5 // indirect
5855
github.com/jonboulle/clockwork v0.4.0 // indirect
5956
github.com/josharian/intern v1.0.0 // indirect
@@ -112,6 +109,7 @@ require (
112109
sigs.k8s.io/controller-runtime v0.18.7 // indirect
113110
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
114111
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
112+
sigs.k8s.io/yaml v1.4.0 // indirect
115113
)
116114

117115
replace golang.org/x/net => golang.org/x/net v0.40.0 // CVE-2025-22870, CVE-2025-22872

0 commit comments

Comments
 (0)