Skip to content

Commit

Permalink
up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samirtahir91 committed Apr 1, 2024
1 parent 1a0c157 commit 233b8c7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/controller/githubapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,46 @@ func (r *GithubAppReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Watch access token secrets owned by GithubApps.
Owns(&corev1.Secret{}, builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}, accessTokenSecretPredicate())).
Complete(r)

Context("When encountering errors while restarting pods", func() {

Check failure on line 641 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint and staticcheck

undefined: Context

Check failure on line 641 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: Context

Check failure on line 641 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: Context
It("Should return an error when listing pods fails", func() {

Check failure on line 642 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint and staticcheck

undefined: It

Check failure on line 642 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: It

Check failure on line 642 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: It
ctx := context.Background()

// Create a GithubApp instance with the RestartPods field initialized
githubApp := &githubappv1.GithubApp{
ObjectMeta: metav1.ObjectMeta{
Name: githubAppName,

Check failure on line 648 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint and staticcheck

undefined: githubAppName

Check failure on line 648 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: githubAppName

Check failure on line 648 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: githubAppName
Namespace: sourceNamespace,

Check failure on line 649 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint and staticcheck

undefined: sourceNamespace

Check failure on line 649 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: sourceNamespace

Check failure on line 649 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: sourceNamespace
},
Spec: githubappv1.GithubAppSpec{
AppId: appId,

Check failure on line 652 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint and staticcheck

undefined: appId

Check failure on line 652 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: appId

Check failure on line 652 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: appId
InstallId: installId,

Check failure on line 653 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint and staticcheck

undefined: installId

Check failure on line 653 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: installId

Check failure on line 653 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: installId
PrivateKeySecret: privateKeySecret,

Check failure on line 654 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint and staticcheck

undefined: privateKeySecret

Check failure on line 654 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: privateKeySecret

Check failure on line 654 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: privateKeySecret
RestartPods: &githubappv1.RestartPodsSpec{
Labels: map[string]string{
"foo": "bar",
},
},
},
}

// Mock the List method of the client to return an error
mockErr := fmt.Errorf("mock error: failed to list pods")
r := &GithubAppReconciler{
Client: &fakeClient{

Check failure on line 666 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint and staticcheck

undefined: fakeClient

Check failure on line 666 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: fakeClient

Check failure on line 666 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: fakeClient
ListFunc: func(ctx context.Context, list runtime.Object, opts ...client.ListOption) error {
return mockErr
},
},
}

// Call the restartPods function
err := r.restartPods(ctx, githubApp)

// Check if the error is as expected
Expect(err).To(HaveOccurred())

Check failure on line 677 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint and staticcheck

undefined: Expect

Check failure on line 677 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: Expect

Check failure on line 677 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: HaveOccurred

Check failure on line 677 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: Expect

Check failure on line 677 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / macos-latest

undefined: HaveOccurred
Expect(err.Error()).To(Equal(fmt.Sprintf("failed to list pods with label foo=bar: %v", mockErr)))
})
})

}

0 comments on commit 233b8c7

Please sign in to comment.