timflannagan/rukpak

add helpful message when invalid spec.source.type is specified

github-actions opened this issue · 1 comments

// TODO add helpful message when invalid spec.source.type is specified

			}).Should(BeTrue())
		})
	})

	When("a Bundle is backed by a git repository", func() {
		var (
			bundle *rukpakv1alpha1.Bundle
			ctx    context.Context
		)
		BeforeEach(func() {
			ctx = context.Background()

			By("creating the git based Bundle")
			bundle = &rukpakv1alpha1.Bundle{
				ObjectMeta: metav1.ObjectMeta{
					GenerateName: "combo-git",
				},
				Spec: rukpakv1alpha1.BundleSpec{
					ProvisionerClassName: plainProvisionerID,
					Source: rukpakv1alpha1.BundleSource{
						Type: "git",
						Git: rukpakv1alpha1.GitSource{
							Repository: "https://github.com/operator-framework/combo",
							Directory:  "/manifests",
							Ref: rukpakv1alpha1.GitRef{
								Commit: "4567031e158b42263e70a7c63e29f8981a4a6135",
							},
						},
					},
				},
			}
			err := c.Create(ctx, bundle)
			Expect(err).To(BeNil())
		})
		AfterEach(func() {
			By("deleting the testing Bundle resource")
			err := c.Delete(ctx, bundle)
			Expect(err).To(BeNil())
		})

		It("should source the git content specified and unpack it to the cluster successfully", func() {
			By("eventually reporting an Unpacked phase", func() {
				Eventually(func() bool {
					if err := c.Get(ctx, client.ObjectKeyFromObject(bundle), bundle); err != nil {
						return false
					}
					return bundle.Status.Phase == rukpakv1alpha1.PhaseUnpacked
				}).Should(BeTrue())
			})

			By("eventually writing a non-empty list of unpacked objects to the status", func() {
				Eventually(func() bool {
					if err := c.Get(ctx, client.ObjectKeyFromObject(bundle), bundle); err != nil {
						return false
					}
					if bundle.Status.Info == nil {
						return false
					}
					return len(bundle.Status.Info.Objects) == 6
				}).Should(BeTrue())
			})
		})

		It("should go into a failed state if the spec.source.type is unsupported", func() {
			By("updating the bundle spec")
			Eventually(func() error {
				if err := c.Get(ctx, client.ObjectKeyFromObject(bundle), bundle); err != nil {
					return err
				}
				bundle.Spec.Source.Type = "random"
				err := c.Update(ctx, bundle)
				return err
			}).Should(Succeed())

			Eventually(func() bool {
				if err := c.Get(ctx, client.ObjectKeyFromObject(bundle), bundle); err != nil {
					return false
				}
				if bundle.Status.Phase != rukpakv1alpha1.PhaseFailing {
					return false
				}
				unpackPending := meta.FindStatusCondition(bundle.Status.Conditions, rukpakv1alpha1.PhaseUnpacked)
				if unpackPending == nil {
					return false
				}
				if unpackPending.Type == "True" {
					return false
				}
				// TODO add helpful message when invalid spec.source.type is specified
				if unpackPending.Message != fmt.Sprintf(`Invalid type specified "%s"`, bundle.Spec.Source.Type) {
					return false
				}
				return true
			}).Should(BeTrue())
		})
	})
})

var _ = Describe("plain provisioner bundleinstance", func() {