Skip to content

Commit

Permalink
backfill tests for workload reconciler
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd Ritchie committed Mar 29, 2023
1 parent 8b33b8c commit fe05ba8
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion pkg/controllers/workload_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ var _ = Describe("WorkloadReconciler", func() {
})
})

Context("of type RetrieveOutputError", func() {
Context("of type RetrieveOutputError with jsonpath", func() {
var retrieveError cerrors.RetrieveOutputError
var stampedObject *unstructured.Unstructured
BeforeEach(func() {
Expand Down Expand Up @@ -890,6 +890,70 @@ var _ = Describe("WorkloadReconciler", func() {
"my-namespace/my-workload-name"))
})
})
Context("of type RetrieveOutputError without stampedobject", func() {
var retrieveError cerrors.RetrieveOutputError
BeforeEach(func() {
jsonPathError := stamp.NewJsonPathError("this.wont.find.anything", errors.New("some error"))
retrieveError = cerrors.RetrieveOutputError{
Err: jsonPathError,
ResourceName: "some-resource",
StampedObject: nil,
BlueprintName: supplyChainName,
BlueprintType: cerrors.SupplyChain,
QualifiedResource: "input",
PassThroughInput: "configs",
}
rlzr.RealizeStub = func(ctx context.Context, resourceRealizer realizer.ResourceRealizer, deliveryName string, resources []realizer.OwnerResource, statuses statuses.ResourceStatuses) error {
statusesVal := reflect.ValueOf(statuses)
existingVal := reflect.ValueOf(resourceStatuses)

reflect.Indirect(statusesVal).Set(reflect.Indirect(existingVal))
return retrieveError
}
})

It("calls the condition manager to report", func() {
_, _ = reconciler.Reconcile(ctx, req)
Expect(conditionManager.AddPositiveArgsForCall(1)).To(
Equal(conditions.MissingPassThroughInputCondition("configs", "input")))
})

It("does not return an error", func() {
_, err := reconciler.Reconcile(ctx, req)
Expect(err).NotTo(HaveOccurred())
})

It("logs the handled error message", func() {
_, _ = reconciler.Reconcile(ctx, req)

Expect(out).To(Say(`"level":"info"`))
Expect(out).To(Say(`"msg":"handled error reconciling workload"`))
Expect(out).To(Say(`"handled error":"unable to retrieve outputs from pass through \[configs\] for resource \[some-resource\] in supply chain \[some-supply-chain\]: failed to evaluate json path 'this.wont.find.anything': some error"`))
})

It("does track the template", func() {
_, _ = reconciler.Reconcile(ctx, req)
Expect(dependencyTracker.TrackCallCount()).To(Equal(3))
key, obj := dependencyTracker.TrackArgsForCall(0)
Expect(key.String()).To(Equal("ServiceAccount/my-namespace/workload-service-account-name"))
Expect(obj.String()).To(Equal("my-namespace/my-workload-name"))

var keys []string
var objs []string
key, obj = dependencyTracker.TrackArgsForCall(1)
keys = append(keys, key.String())
objs = append(objs, obj.String())

key, obj = dependencyTracker.TrackArgsForCall(2)
keys = append(keys, key.String())
objs = append(objs, obj.String())

Expect(keys).To(ContainElements("my-image-kind.carto.run//my-image-template",
"my-config-kind.carto.run//my-config-template"))
Expect(objs).To(ContainElements("my-namespace/my-workload-name",
"my-namespace/my-workload-name"))
})
})

Context("of type ResolveTemplateOptionError", func() {
var resolveOptionErr cerrors.ResolveTemplateOptionError
Expand Down

0 comments on commit fe05ba8

Please sign in to comment.