Skip to content

Commit

Permalink
Modify obj tests for encapsulated secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
amold1 committed Mar 26, 2024
1 parent a95fb4e commit a18c9fa
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions controller/linodeobjectstoragebucket_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/linode/linodego"
"go.uber.org/mock/gomock"
"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -47,6 +48,22 @@ import (
. "github.com/onsi/gomega"
)

type AccessKeySecret struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace"`
} `yaml:"metadata"`
StringData struct {
BucketName string `yaml:"bucket_name"`
AccessKeyRW string `yaml:"access_key_rw"`
SecretKeyRW string `yaml:"secret_key_rw"`
AccessKeyRO string `yaml:"access_key_ro"`
SecretKeyRO string `yaml:"secret_key_ro"`
} `yaml:"stringData"`
}

func mockLinodeClientBuilder(m *mock.MockLinodeObjectStorageClient) scope.LinodeObjectStorageClientBuilder {
return func(_ string) (scope.LinodeObjectStorageClient, error) {
return m, nil
Expand Down Expand Up @@ -157,9 +174,17 @@ var _ = Describe("lifecycle", Label("lifecycle"), func() {

By("creating a secret with access keys")
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&secret), &secret)).To(Succeed())
Expect(secret.Data).To(HaveLen(5))
Expect(string(secret.Data["read_write"])).To(Equal(string("key-0")))
Expect(string(secret.Data["read_only"])).To(Equal(string("key-1")))
Expect(secret.Data).To(HaveLen(1))
var key AccessKeySecret
unMarshallingErr := yaml.Unmarshal(secret.Data["access-keys-secret.yaml"], &key)
if unMarshallingErr != nil {
panic(unMarshallingErr)
}
Expect(key.StringData.BucketName).To(Equal("lifecycle"))
Expect(key.StringData.AccessKeyRW).To(Equal("key-0"))
Expect(key.StringData.SecretKeyRW).To(Equal(""))
Expect(key.StringData.AccessKeyRO).To(Equal("key-1"))
Expect(key.StringData.SecretKeyRO).To(Equal(""))

By("recording the expected events")
Expect(<-recorder.Events).To(ContainSubstring("Object storage keys assigned"))
Expand Down Expand Up @@ -207,9 +232,15 @@ var _ = Describe("lifecycle", Label("lifecycle"), func() {

By("re-creating it when it is deleted")
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&secret), &secret)).To(Succeed())
Expect(secret.Data).To(HaveLen(5))
Expect(string(secret.Data["read_write"])).To(Equal("key-0"))
Expect(string(secret.Data["read_only"])).To(Equal("key-1"))
Expect(secret.Data).To(HaveLen(1))
var key AccessKeySecret
unMarshallingErr := yaml.Unmarshal(secret.Data["access-keys-secret.yaml"], &key)
Expect(unMarshallingErr).NotTo(HaveOccurred())
Expect(key.StringData.BucketName).To(Equal("lifecycle"))
Expect(key.StringData.AccessKeyRW).To(Equal("key-0"))
Expect(key.StringData.SecretKeyRW).To(Equal(""))
Expect(key.StringData.AccessKeyRO).To(Equal("key-1"))
Expect(key.StringData.SecretKeyRO).To(Equal(""))

By("recording the expected events")
Expect(<-recorder.Events).To(ContainSubstring("Object storage keys retrieved"))
Expand Down

0 comments on commit a18c9fa

Please sign in to comment.