Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed Sep 26, 2023
1 parent 1da6328 commit 909ca74
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 25 deletions.
5 changes: 1 addition & 4 deletions pkg/operator/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *Client) runAppStateMonitor() error {
return errors.New("app state monitor shutdown")
}

func (c *Client) RestartNamespacesInformer(namespaces []string, imagePullSecrets []string) {
func (c *Client) ApplyNamespacesInformer(namespaces []string, imagePullSecrets []string) {
for _, ns := range namespaces {
if ns == "*" {
continue
Expand Down Expand Up @@ -180,9 +180,6 @@ func (c *Client) DeployApp(deployArgs operatortypes.DeployAppArgs) (deployed boo
}
}()

c.RestartNamespacesInformer(deployArgs.AdditionalNamespaces, deployArgs.ImagePullSecrets)
c.ApplyHooksInformer(deployArgs.AdditionalNamespaces)

deployRes, deployError = c.deployManifests(deployArgs)
if deployError != nil {
deployRes = &deployResult{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/client/client_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ type ClientInterface interface {
DeployApp(deployArgs operatortypes.DeployAppArgs) (deployed bool, finalError error)
UndeployApp(undeployArgs operatortypes.UndeployAppArgs) error
ApplyAppInformers(args operatortypes.AppInformersArgs)
RestartNamespacesInformer(namespaces []string, imagePullSecrets []string)
ApplyNamespacesInformer(namespaces []string, imagePullSecrets []string)
ApplyHooksInformer(namespaces []string)
}
24 changes: 12 additions & 12 deletions pkg/operator/client/mock/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ func (o *Operator) DeployApp(appID string, sequence int64) (deployed bool, deplo
return false, errors.Wrap(err, "failed to apply status informers")
}

o.client.ApplyNamespacesInformer(kotsKinds.KotsApplication.Spec.AdditionalNamespaces, imagePullSecrets)
o.client.ApplyHooksInformer(kotsKinds.KotsApplication.Spec.AdditionalNamespaces)

deployArgs := operatortypes.DeployAppArgs{
AppID: app.ID,
AppSlug: app.Slug,
Expand Down Expand Up @@ -527,7 +530,7 @@ func (o *Operator) resumeInformersForApp(app *apptypes.App) error {
return errors.Wrapf(err, "failed to apply status informers for app %s", app.ID)
}

o.client.RestartNamespacesInformer(kotsKinds.KotsApplication.Spec.AdditionalNamespaces, imagePullSecrets)
o.client.ApplyNamespacesInformer(kotsKinds.KotsApplication.Spec.AdditionalNamespaces, imagePullSecrets)
o.client.ApplyHooksInformer(kotsKinds.KotsApplication.Spec.AdditionalNamespaces)

return nil
Expand Down
46 changes: 39 additions & 7 deletions pkg/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ spec:
Expect(err).ToNot(HaveOccurred())
})

It("starts the status informers", func() {
It("resumes informers on (re)start", func() {
mockClient.EXPECT().Init().Return(nil)

mockStore.EXPECT().GetClusterIDFromDeployToken(clusterToken).Return("", nil)
Expand Down Expand Up @@ -106,6 +106,16 @@ spec:
wg.Done()
})

wg.Add(1)
mockClient.EXPECT().ApplyNamespacesInformer(gomock.Any(), gomock.Any()).Times(1).Do(func(namespaces []string, imagePullSecrets []string) {
wg.Done()
})

wg.Add(1)
mockClient.EXPECT().ApplyHooksInformer(gomock.Any()).Times(1).Do(func(namespaces []string) {
wg.Done()
})

err := testOperator.Start()
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -169,6 +179,16 @@ spec:
wg.Done()
})

wg.Add(1)
mockClient.EXPECT().ApplyNamespacesInformer(gomock.Any(), gomock.Any()).Times(0).Do(func(namespaces []string, imagePullSecrets []string) {
wg.Done()
})

wg.Add(1)
mockClient.EXPECT().ApplyHooksInformer(gomock.Any()).Times(0).Do(func(namespaces []string) {
wg.Done()
})

err := testOperator.Start()
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -299,9 +319,13 @@ spec:

mockStore.EXPECT().GetPreviouslyDeployedSequence(appID, "").Return(previouslyDeployedSequence, nil)

mockClient.EXPECT().DeployApp(gomock.Any()).Return(true, nil)
mockClient.EXPECT().ApplyAppInformers(gomock.Any()).Times(1)

mockClient.EXPECT().ApplyNamespacesInformer(gomock.Any(), gomock.Any()).Times(1)

mockClient.EXPECT().ApplyAppInformers(gomock.Any())
mockClient.EXPECT().ApplyHooksInformer(gomock.Any()).Times(1)

mockClient.EXPECT().DeployApp(gomock.Any()).Return(true, nil)

deployed, err := testOperator.DeployApp(appID, sequence)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -390,13 +414,17 @@ spec:

mockStore.EXPECT().GetParentSequenceForSequence(appID, "", previouslyDeployedSequence).Return(int64(0), nil)

mockClient.EXPECT().ApplyAppInformers(gomock.Any()).Times(1)

mockClient.EXPECT().ApplyNamespacesInformer(gomock.Any(), gomock.Any()).Times(1)

mockClient.EXPECT().ApplyHooksInformer(gomock.Any()).Times(1)

mockClient.EXPECT().DeployApp(gomock.Any()).DoAndReturn(func(deployArgs operatortypes.DeployAppArgs) (bool, error) {
Expect(deployArgs.PreviousManifests).To(BeEmpty())
return true, nil
})

mockClient.EXPECT().ApplyAppInformers(gomock.Any())

deployed, err := testOperator.DeployApp(appID, sequence)
Expect(err).ToNot(HaveOccurred())
Expect(deployed).To(BeTrue())
Expand Down Expand Up @@ -596,6 +624,12 @@ spec:

mockStore.EXPECT().GetPreviouslyDeployedSequence(appID, "").Return(previouslyDeployedSequence, nil)

mockClient.EXPECT().ApplyAppInformers(gomock.Any()).Times(1)

mockClient.EXPECT().ApplyNamespacesInformer(gomock.Any(), gomock.Any()).Times(1)

mockClient.EXPECT().ApplyHooksInformer(gomock.Any()).Times(1)

mockClient.EXPECT().DeployApp(gomock.Any()).Do(func(deployArgs operatortypes.DeployAppArgs) (bool, error) {
// validate that the namespace and helm upgrade flags are templated when deploying
Expect(deployArgs.KotsKinds.V1Beta1HelmCharts.Items[0].Spec.Namespace).To(Equal(expectedNamespace))
Expand All @@ -605,8 +639,6 @@ spec:
return true, nil
})

mockClient.EXPECT().ApplyAppInformers(gomock.Any())

_, err := testOperator.DeployApp(appID, sequence)
Expect(err).ToNot(HaveOccurred())
})
Expand Down

0 comments on commit 909ca74

Please sign in to comment.