55
66 . "github.com/onsi/ginkgo"
77 . "github.com/onsi/gomega"
8+ "github.com/tidwall/gjson"
89
910 "github.com/deckhouse/deckhouse/pkg/log"
1011
@@ -20,35 +21,57 @@ const (
2021)
2122
2223var _ = Describe ("handle hook single file example" , func () {
23- snapshots := mock .NewSnapshotsMock (GinkgoT ())
24- snapshots .GetMock .When (singlefileappexample .SnapshotKey ).Then (
25- []pkg.Snapshot {
26- mock .NewSnapshotMock (GinkgoT ()).UnmarshalToMock .Set (func (v any ) error {
27- str := v .(* string )
28- * str = firstSnapshot
29-
30- return nil
31- }),
32- mock .NewSnapshotMock (GinkgoT ()).UnmarshalToMock .Set (func (v any ) error {
33- str := v .(* string )
34- * str = secondSnapshot
35-
36- return nil
37- }),
38- },
39- )
40-
41- values := mock .NewOutputPatchableValuesCollectorMock (GinkgoT ())
42- values .SetMock .When ("test.internal.apiServers" , []string {firstSnapshot , secondSnapshot })
43-
44- var input = & pkg.ApplicationHookInput {
45- Snapshots : snapshots ,
46- Values : values ,
47- Logger : log .NewNop (),
48- }
49-
50- Context ("reconcile func" , func () {
51- It ("reconcile func executed correctly" , func () {
24+ Context ("settings gate closed" , func () {
25+ settings := mock .NewOutputPatchableValuesCollectorMock (GinkgoT ())
26+ settings .GetOkMock .When ("apiServersDiscovery.enabled" ).Then (gjson.Result {}, false )
27+
28+ values := mock .NewOutputPatchableValuesCollectorMock (GinkgoT ())
29+
30+ var input = & pkg.ApplicationHookInput {
31+ Values : values ,
32+ Settings : settings ,
33+ Logger : log .NewNop (),
34+ }
35+
36+ It ("does not touch values when the gate is closed" , func () {
37+ err := singlefileappexample .Handle (context .Background (), input )
38+ Expect (err ).ShouldNot (HaveOccurred ())
39+ })
40+ })
41+
42+ Context ("settings gate open" , func () {
43+ snapshots := mock .NewSnapshotsMock (GinkgoT ())
44+ snapshots .GetMock .When (singlefileappexample .SnapshotKey ).Then (
45+ []pkg.Snapshot {
46+ mock .NewSnapshotMock (GinkgoT ()).UnmarshalToMock .Set (func (v any ) error {
47+ str := v .(* string )
48+ * str = firstSnapshot
49+
50+ return nil
51+ }),
52+ mock .NewSnapshotMock (GinkgoT ()).UnmarshalToMock .Set (func (v any ) error {
53+ str := v .(* string )
54+ * str = secondSnapshot
55+
56+ return nil
57+ }),
58+ },
59+ )
60+
61+ settings := mock .NewOutputPatchableValuesCollectorMock (GinkgoT ())
62+ settings .GetOkMock .When ("apiServersDiscovery.enabled" ).Then (gjson.Result {Type : gjson .True }, true )
63+
64+ values := mock .NewOutputPatchableValuesCollectorMock (GinkgoT ())
65+ values .SetMock .When ("test.internal.apiServers" , []string {firstSnapshot , secondSnapshot })
66+
67+ var input = & pkg.ApplicationHookInput {
68+ Snapshots : snapshots ,
69+ Values : values ,
70+ Settings : settings ,
71+ Logger : log .NewNop (),
72+ }
73+
74+ It ("writes discovered pods into values when the gate is open" , func () {
5275 err := singlefileappexample .Handle (context .Background (), input )
5376 Expect (err ).ShouldNot (HaveOccurred ())
5477 })
0 commit comments