mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-22 07:28:06 +00:00
Add test case for item with file
This commit is contained in:
@@ -2,6 +2,7 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
@@ -303,6 +304,54 @@ var _ = Describe("OnePasswordItem controller", func() {
|
|||||||
}, timeout, interval).Should(BeTrue())
|
}, timeout, interval).Should(BeTrue())
|
||||||
Expect(secret.Type).Should(Equal(v1.SecretType(customType)))
|
Expect(secret.Type).Should(Equal(v1.SecretType(customType)))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("Should handle 1Password Item with a file and populate secret correctly", func() {
|
||||||
|
ctx := context.Background()
|
||||||
|
spec := onepasswordv1.OnePasswordItemSpec{
|
||||||
|
ItemPath: item1.Path,
|
||||||
|
}
|
||||||
|
|
||||||
|
key := types.NamespacedName{
|
||||||
|
Name: "item-with-file",
|
||||||
|
Namespace: namespace,
|
||||||
|
}
|
||||||
|
|
||||||
|
toCreate := &onepasswordv1.OnePasswordItem{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: key.Name,
|
||||||
|
Namespace: key.Namespace,
|
||||||
|
},
|
||||||
|
Spec: spec,
|
||||||
|
}
|
||||||
|
|
||||||
|
fileContent := []byte("dummy-cert-content")
|
||||||
|
item := item1.ToModel()
|
||||||
|
item.Files = []model.File{
|
||||||
|
{
|
||||||
|
ID: "file-id-123",
|
||||||
|
Name: "server.crt",
|
||||||
|
ContentPath: fmt.Sprintf("/v1/vaults/%s/items/%s/files/file-id-123/content", item.VaultID, item.ID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
item.Files[0].SetContent(fileContent)
|
||||||
|
|
||||||
|
mockGetItemByIDFunc.Return(item, nil)
|
||||||
|
mockGetItemByIDFunc.On("GetFileContent", item.VaultID, item.ID, "file-id-123").Return(fileContent, nil)
|
||||||
|
|
||||||
|
By("Creating a new OnePasswordItem with file successfully")
|
||||||
|
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
||||||
|
|
||||||
|
createdSecret := &v1.Secret{}
|
||||||
|
Eventually(func() bool {
|
||||||
|
err := k8sClient.Get(ctx, key, createdSecret)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}, timeout, interval).Should(BeTrue())
|
||||||
|
|
||||||
|
Expect(createdSecret.Data).Should(HaveKeyWithValue("server.crt", fileContent))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("Unhappy path", func() {
|
Context("Unhappy path", func() {
|
||||||
|
Reference in New Issue
Block a user