Skip to content

Commit

Permalink
add test to verify error clears on correct update
Browse files Browse the repository at this point in the history
Signed-off-by: Anik Bhattacharjee <anikbhattacharya93@gmail.com>
  • Loading branch information
anik120 committed Apr 6, 2022
1 parent eb24011 commit c300081
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
4 changes: 0 additions & 4 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,6 @@ func (o *Operator) syncRegistryServer(logger *logrus.Entry, in *v1alpha1.Catalog
if out.Spec.UpdateStrategy.RegistryPoll != nil {
if out.Spec.UpdateStrategy.RegistryPoll.ParsingError != "" && out.Status.Reason != v1alpha1.CatalogSourceIntervalInvalidError {
out.SetError(v1alpha1.CatalogSourceIntervalInvalidError, fmt.Errorf(out.Spec.UpdateStrategy.RegistryPoll.ParsingError))
if _, err := o.client.OperatorsV1alpha1().CatalogSources(out.GetNamespace()).UpdateStatus(context.TODO(), out, metav1.UpdateOptions{}); err != nil {
logger.Errorf("error while updating catalogsource status for an invalid interval - %v", err)
return
}
}
logger.Debugf("requeuing registry server sync based on polling interval %s", out.Spec.UpdateStrategy.Interval.Duration.String())
resyncPeriod := reconciler.SyncRegistryUpdateInterval(out, time.Now())
Expand Down
34 changes: 31 additions & 3 deletions test/e2e/catalog_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,12 +1146,14 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {

})

When("A catalogSource is created with incorrect interval", func() {
FWhen("A catalogSource is created with incorrect interval", func() {

var source *v1alpha1.CatalogSource
var (
source *v1alpha1.CatalogSource
sourceName = genName("catalog-")
)

BeforeEach(func() {
sourceName := genName("catalog-")
source = &v1alpha1.CatalogSource{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.CatalogSourceKind,
Expand Down Expand Up @@ -1190,6 +1192,32 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
return false
}).Should(BeTrue())
})
When("the catalogsource is updated with a valid polling interval", func() {
BeforeEach(func() {
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.TODO(), source.GetName(), metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
catsrc.Spec.UpdateStrategy.RegistryPoll.RawInterval = "45m"
_, err = crc.OperatorsV1alpha1().CatalogSources(catsrc.GetNamespace()).Update(context.TODO(), catsrc, metav1.UpdateOptions{})
Expect(err).ToNot(HaveOccurred())
})
It("the catalogsource spec shows the updated polling interval, and the error message in the status is cleared", func() {
Eventually(func() error {
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.TODO(), source.GetName(), metav1.GetOptions{})
if err != nil {
return err
}
expectedTime, err := time.ParseDuration("45m")
if err != nil {
return err
}
if catsrc.Status.Reason != "" || (catsrc.Spec.UpdateStrategy.Interval != &metav1.Duration{expectedTime}) {
return err
}
return nil

}).Should(Succeed())
})
})
})

It("adding catalog template adjusts image used", func() {
Expand Down

0 comments on commit c300081

Please sign in to comment.