github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/loader/loader_mock_test.go (about) 1 package loader 2 3 import ( 4 toolkit "github.com/konflux-ci/operator-toolkit/loader" 5 6 v1alpha12 "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1" 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 applicationapiv1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1" 10 "github.com/redhat-appstudio/release-service/api/v1alpha1" 11 tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" 12 rbac "k8s.io/api/rbac/v1" 13 ) 14 15 var _ = Describe("Release Adapter", Ordered, func() { 16 var ( 17 loader ObjectLoader 18 ) 19 20 BeforeAll(func() { 21 loader = NewMockLoader() 22 }) 23 24 When("calling GetActiveReleasePlanAdmission", func() { 25 It("returns the resource and error from the context", func() { 26 releasePlanAdmission := &v1alpha1.ReleasePlanAdmission{} 27 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 28 { 29 ContextKey: ReleasePlanAdmissionContextKey, 30 Resource: releasePlanAdmission, 31 }, 32 }) 33 resource, err := loader.GetActiveReleasePlanAdmission(mockContext, nil, nil) 34 Expect(resource).To(Equal(releasePlanAdmission)) 35 Expect(err).To(BeNil()) 36 }) 37 }) 38 39 When("calling GetActiveReleasePlanAdmissionFromRelease", func() { 40 It("returns the resource and error from the context", func() { 41 releasePlanAdmission := &v1alpha1.ReleasePlanAdmission{} 42 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 43 { 44 ContextKey: ReleasePlanAdmissionContextKey, 45 Resource: releasePlanAdmission, 46 }, 47 }) 48 resource, err := loader.GetActiveReleasePlanAdmissionFromRelease(mockContext, nil, nil) 49 Expect(resource).To(Equal(releasePlanAdmission)) 50 Expect(err).To(BeNil()) 51 }) 52 }) 53 54 When("calling GetApplication", func() { 55 It("returns the resource and error from the context", func() { 56 application := &applicationapiv1alpha1.Application{} 57 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 58 { 59 ContextKey: ApplicationContextKey, 60 Resource: application, 61 }, 62 }) 63 resource, err := loader.GetApplication(mockContext, nil, nil) 64 Expect(resource).To(Equal(application)) 65 Expect(err).To(BeNil()) 66 }) 67 }) 68 69 When("calling GetEnterpriseContractPolicy", func() { 70 It("returns the resource and error from the context", func() { 71 enterpriseContractPolicy := &v1alpha12.EnterpriseContractPolicy{} 72 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 73 { 74 ContextKey: EnterpriseContractPolicyContextKey, 75 Resource: enterpriseContractPolicy, 76 }, 77 }) 78 resource, err := loader.GetEnterpriseContractPolicy(mockContext, nil, nil) 79 Expect(resource).To(Equal(enterpriseContractPolicy)) 80 Expect(err).To(BeNil()) 81 }) 82 }) 83 84 When("calling GetMatchingReleasePlanAdmission", func() { 85 It("returns the resource and error from the context", func() { 86 releasePlanAdmission := &v1alpha1.ReleasePlanAdmission{} 87 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 88 { 89 ContextKey: MatchedReleasePlanAdmissionContextKey, 90 Resource: releasePlanAdmission, 91 }, 92 }) 93 resource, err := loader.GetMatchingReleasePlanAdmission(mockContext, nil, nil) 94 Expect(resource).To(Equal(releasePlanAdmission)) 95 Expect(err).To(BeNil()) 96 }) 97 }) 98 99 When("calling GetMatchingReleasePlans", func() { 100 It("returns the resource and error from the context", func() { 101 releasePlans := &v1alpha1.ReleasePlanList{} 102 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 103 { 104 ContextKey: MatchedReleasePlansContextKey, 105 Resource: releasePlans, 106 }, 107 }) 108 resource, err := loader.GetMatchingReleasePlans(mockContext, nil, nil) 109 Expect(resource).To(Equal(releasePlans)) 110 Expect(err).To(BeNil()) 111 }) 112 }) 113 114 When("calling GetRelease", func() { 115 It("returns the resource and error from the context", func() { 116 release := &v1alpha1.Release{} 117 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 118 { 119 ContextKey: ReleaseContextKey, 120 Resource: release, 121 }, 122 }) 123 resource, err := loader.GetRelease(mockContext, nil, "", "") 124 Expect(resource).To(Equal(release)) 125 Expect(err).To(BeNil()) 126 }) 127 }) 128 129 When("calling GetRoleBindingFromReleaseStatus", func() { 130 It("returns the resource and error from the context", func() { 131 roleBinding := &rbac.RoleBinding{} 132 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 133 { 134 ContextKey: RoleBindingContextKey, 135 Resource: roleBinding, 136 }, 137 }) 138 resource, err := loader.GetRoleBindingFromReleaseStatus(mockContext, nil, nil) 139 Expect(resource).To(Equal(roleBinding)) 140 Expect(err).To(BeNil()) 141 }) 142 }) 143 144 When("calling GetManagedReleasePipelineRun", func() { 145 It("returns the resource and error from the context", func() { 146 pipelineRun := &tektonv1.PipelineRun{} 147 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 148 { 149 ContextKey: ReleasePipelineRunContextKey, 150 Resource: pipelineRun, 151 }, 152 }) 153 resource, err := loader.GetManagedReleasePipelineRun(mockContext, nil, nil) 154 Expect(resource).To(Equal(pipelineRun)) 155 Expect(err).To(BeNil()) 156 }) 157 }) 158 159 When("calling GetReleasePlan", func() { 160 It("returns the resource and error from the context", func() { 161 releasePlan := &v1alpha1.ReleasePlan{} 162 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 163 { 164 ContextKey: ReleasePlanContextKey, 165 Resource: releasePlan, 166 }, 167 }) 168 resource, err := loader.GetReleasePlan(mockContext, nil, nil) 169 Expect(resource).To(Equal(releasePlan)) 170 Expect(err).To(BeNil()) 171 }) 172 }) 173 174 When("calling GetReleaseServiceConfig", func() { 175 It("returns the resource and error from the context", func() { 176 releaseServiceConfig := &v1alpha1.ReleaseServiceConfig{} 177 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 178 { 179 ContextKey: ReleaseServiceConfigContextKey, 180 Resource: releaseServiceConfig, 181 }, 182 }) 183 resource, err := loader.GetReleaseServiceConfig(mockContext, nil, "", "") 184 Expect(resource).To(Equal(releaseServiceConfig)) 185 Expect(err).To(BeNil()) 186 }) 187 }) 188 189 When("calling GetSnapshot", func() { 190 It("returns the resource and error from the context", func() { 191 snapshot := &applicationapiv1alpha1.Snapshot{} 192 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 193 { 194 ContextKey: SnapshotContextKey, 195 Resource: snapshot, 196 }, 197 }) 198 resource, err := loader.GetSnapshot(mockContext, nil, nil) 199 Expect(resource).To(Equal(snapshot)) 200 Expect(err).To(BeNil()) 201 }) 202 }) 203 204 // Composite functions 205 206 When("calling GetProcessingResources", func() { 207 It("returns the resource and error from the context", func() { 208 processingResources := &ProcessingResources{} 209 mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{ 210 { 211 ContextKey: ProcessingResourcesContextKey, 212 Resource: processingResources, 213 }, 214 }) 215 resource, err := loader.GetProcessingResources(mockContext, nil, nil) 216 Expect(resource).To(Equal(processingResources)) 217 Expect(err).To(BeNil()) 218 }) 219 }) 220 221 })