timflannagan / rukpak

Rukpak runs in a Kubernetes cluster and defines an API for installing cloud native bundle content
Apache License 2.0
0 stars 0 forks source link

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

Closed github-actions[bot] closed 2 years ago

github-actions[bot] commented 2 years ago

https://github.com/timflannagan/rukpak/blob/74e3c987bf231314558d3600337ee66f72ac2110/test/e2e/plain_provisioner_test.go#L339


            }).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() {
github-actions[bot] commented 2 years ago

Closed in 21d849e1efec889919653a81e835857656decedd