@@ -19,14 +19,6 @@ import (
1919)
2020
2121const (
22- repoYAML = `
23- apiVersion: v1
24- kind: Config
25- metadata:
26- name: repo-min
27- spec:
28- foo: bar
29- `
3022 helmReleaseYAML = `
3123apiVersion: helm.toolkit.fluxcd.io/v2beta1
3224kind: HelmRelease
@@ -100,24 +92,6 @@ spec:
10092 },
10193 true ,
10294 },
103- {"manifest: invalid YAML" , "manifest" , "this: is: : invalid: yaml" , nil , true },
104- {
105- "manifest: patch error wrapped" ,
106- "manifest" ,
107- trim (`
108- apiVersion: v1
109- kind: Config
110- metadata:
111- name: test-manifest
112- spec:
113- foo: bar
114- ` ),
115- func (m * mocks.MockClient ) {
116- m .EXPECT ().Patch (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
117- Return (errors .New ("simulated patch error for manifest" )).Once ()
118- },
119- true ,
120- },
12195 }
12296
12397 for _ , tc := range cases {
@@ -133,13 +107,6 @@ spec:
133107 } else {
134108 require .NoError (t , err )
135109 }
136- case "manifest" :
137- err := applyManifestWithMergedValues (ctx , tc .content , clientMock , nil )
138- if tc .expectErr {
139- require .Error (t , err )
140- } else {
141- require .NoError (t , err )
142- }
143110 default :
144111 t .Fatalf ("unknown call type %q" , tc .call )
145112 }
@@ -148,20 +115,13 @@ spec:
148115}
149116
150117func TestRealmSubroutine_ProcessAndFinalize (t * testing.T ) {
151- origRepo , origHR := repository , helmRelease
152- defer func () { repository , helmRelease = origRepo , origHR }()
118+ origHR := helmRelease
119+ defer func () { helmRelease = origHR }()
153120
154121 t .Run ("Process" , func (t * testing.T ) {
155122 t .Run ("success create repo then helmrelease" , func (t * testing.T ) {
156123 t .Parallel ()
157124 clientMock := newClientMock (t , func (m * mocks.MockClient ) {
158- m .EXPECT ().Patch (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
159- RunAndReturn (func (_ context.Context , obj client.Object , _ client.Patch , _ ... client.PatchOption ) error {
160- _ , ok := obj .(* unstructured.Unstructured )
161- require .True (t , ok )
162- return nil
163- }).Once ()
164-
165125 m .EXPECT ().Patch (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
166126 RunAndReturn (func (_ context.Context , obj client.Object , _ client.Patch , _ ... client.PatchOption ) error {
167127 hr := obj .(* unstructured.Unstructured )
@@ -174,7 +134,7 @@ func TestRealmSubroutine_ProcessAndFinalize(t *testing.T) {
174134 }).Once ()
175135 })
176136
177- repository , helmRelease = trim ( repoYAML ), trim (helmReleaseYAML )
137+ helmRelease = trim (helmReleaseYAML )
178138
179139 rs := NewRealmSubroutine (clientMock , & config.Config {}, baseDomain )
180140 lc := & kcpv1alpha1.LogicalCluster {}
@@ -188,7 +148,7 @@ func TestRealmSubroutine_ProcessAndFinalize(t *testing.T) {
188148 t .Run ("success create with SMTP config" , func (t * testing.T ) {
189149 t .Parallel ()
190150 clientMock := newClientMock (t , func (m * mocks.MockClient ) {
191- m .EXPECT ().Patch (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil ).Twice ()
151+ m .EXPECT ().Patch (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil ).Once ()
192152 })
193153
194154 cfg := & config.Config {}
@@ -205,14 +165,14 @@ func TestRealmSubroutine_ProcessAndFinalize(t *testing.T) {
205165 require .Equal (t , ctrl.Result {}, res )
206166 })
207167
208- t .Run ("oci repository apply fails" , func (t * testing.T ) {
168+ t .Run ("helmrelease apply fails" , func (t * testing.T ) {
209169 t .Parallel ()
210170 clientMock := newClientMock (t , func (m * mocks.MockClient ) {
211171 m .EXPECT ().Patch (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
212- Return (errors .New ("simulated patch failure for OCI repo " )).Once ()
172+ Return (errors .New ("simulated patch failure for HelmRelease " )).Once ()
213173 })
214174
215- repository , helmRelease = trim ( repoYAML ), trim (helmReleaseYAML )
175+ helmRelease = trim (helmReleaseYAML )
216176 rs := NewRealmSubroutine (clientMock , & config.Config {}, baseDomain )
217177 lc := & kcpv1alpha1.LogicalCluster {}
218178 lc .Annotations = map [string ]string {"kcp.io/path" : "root:orgs:test" }
@@ -250,26 +210,17 @@ func TestRealmSubroutine_ProcessAndFinalize(t *testing.T) {
250210 expectErr bool
251211 expectedResult ctrl.Result
252212 }{
253- {
254- "OCI delete error" ,
255- func (m * mocks.MockClient ) {
256- m .EXPECT ().Delete (mock .Anything , mock .Anything ).Return (errors .New ("failed to delete oci repository" )).Once ()
257- },
258- true ,
259- ctrl.Result {},
260- },
261213 {
262214 "HelmRelease delete error" ,
263215 func (m * mocks.MockClient ) {
264- m .EXPECT ().Delete (mock .Anything , mock .Anything ).Return (nil ).Once ()
265216 m .EXPECT ().Delete (mock .Anything , mock .Anything ).Return (errors .New ("failed to delete helmRelease" )).Once ()
266217 },
267218 true ,
268219 ctrl.Result {},
269220 },
270221 {
271- "Both deletes succeed " ,
272- func (m * mocks.MockClient ) { m .EXPECT ().Delete (mock .Anything , mock .Anything ).Return (nil ).Twice () },
222+ "Delete succeeds " ,
223+ func (m * mocks.MockClient ) { m .EXPECT ().Delete (mock .Anything , mock .Anything ).Return (nil ).Once () },
273224 false ,
274225 ctrl.Result {},
275226 },
0 commit comments