mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-23 16:00:46 +00:00
update tests
This commit is contained in:
@@ -98,11 +98,11 @@ var _ = Describe("Deployment controller", func() {
|
|||||||
err := k8sClient.DeleteAllOf(context.Background(), &onepasswordv1.OnePasswordItem{}, client.InNamespace(namespace))
|
err := k8sClient.DeleteAllOf(context.Background(), &onepasswordv1.OnePasswordItem{}, client.InNamespace(namespace))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
err2 := k8sClient.DeleteAllOf(context.Background(), &v1.Secret{}, client.InNamespace(namespace))
|
err = k8sClient.DeleteAllOf(context.Background(), &v1.Secret{}, client.InNamespace(namespace))
|
||||||
Expect(err2).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
err3 := k8sClient.DeleteAllOf(context.Background(), &appsv1.Deployment{}, client.InNamespace(namespace))
|
err = k8sClient.DeleteAllOf(context.Background(), &appsv1.Deployment{}, client.InNamespace(namespace))
|
||||||
Expect(err3).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
}
|
}
|
||||||
|
|
||||||
mockGetItemFunc := func() {
|
mockGetItemFunc := func() {
|
||||||
@@ -275,7 +275,7 @@ var _ = Describe("Deployment controller", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("Should not delete secret created via deployment if it's used in another container", func() {
|
It("Should not delete secret created via deployment if it's used in another container", func() {
|
||||||
By("Create another POD with created secret")
|
By("Creating another POD with created secret")
|
||||||
anotherDeploymentKey := types.NamespacedName{
|
anotherDeploymentKey := types.NamespacedName{
|
||||||
Name: "other-deployment",
|
Name: "other-deployment",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@@ -347,7 +347,7 @@ var _ = Describe("Deployment controller", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("Should not delete secret created via deployment if it's used in another volume", func() {
|
It("Should not delete secret created via deployment if it's used in another volume", func() {
|
||||||
By("Create another POD with created secret")
|
By("Creating another POD with created secret")
|
||||||
anotherDeploymentKey := types.NamespacedName{
|
anotherDeploymentKey := types.NamespacedName{
|
||||||
Name: "other-deployment",
|
Name: "other-deployment",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
|
@@ -24,13 +24,13 @@ const (
|
|||||||
iceCream = "freezing blue 20%"
|
iceCream = "freezing blue 20%"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("TestItem controller", func() {
|
var _ = Describe("OnePasswordItem controller", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
// failed test runs that don't clean up leave resources behind.
|
// failed test runs that don't clean up leave resources behind.
|
||||||
err := k8sClient.DeleteAllOf(context.Background(), &onepasswordv1.OnePasswordItem{}, client.InNamespace(namespace))
|
err := k8sClient.DeleteAllOf(context.Background(), &onepasswordv1.OnePasswordItem{}, client.InNamespace(namespace))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
err2 := k8sClient.DeleteAllOf(context.Background(), &v1.Secret{}, client.InNamespace(namespace))
|
err = k8sClient.DeleteAllOf(context.Background(), &v1.Secret{}, client.InNamespace(namespace))
|
||||||
Expect(err2).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
mocks.DoGetItemFunc = func(uuid string, vaultUUID string) (*onepassword.Item, error) {
|
mocks.DoGetItemFunc = func(uuid string, vaultUUID string) (*onepassword.Item, error) {
|
||||||
item := onepassword.Item{}
|
item := onepassword.Item{}
|
||||||
@@ -65,7 +65,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
Spec: spec,
|
Spec: spec,
|
||||||
}
|
}
|
||||||
|
|
||||||
By("Creating a new TestItem successfully")
|
By("Creating a new OnePasswordItem successfully")
|
||||||
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
||||||
|
|
||||||
created := &onepasswordv1.OnePasswordItem{}
|
created := &onepasswordv1.OnePasswordItem{}
|
||||||
@@ -123,7 +123,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
}, timeout, interval).Should(BeTrue())
|
}, timeout, interval).Should(BeTrue())
|
||||||
Expect(updatedSecret.Data).Should(Equal(newDataByte))
|
Expect(updatedSecret.Data).Should(Equal(newDataByte))
|
||||||
|
|
||||||
By("Deleting the TestItem successfully")
|
By("Deleting the OnePasswordItem successfully")
|
||||||
Eventually(func() error {
|
Eventually(func() error {
|
||||||
f := &onepasswordv1.OnePasswordItem{}
|
f := &onepasswordv1.OnePasswordItem{}
|
||||||
err := k8sClient.Get(ctx, key, f)
|
err := k8sClient.Get(ctx, key, f)
|
||||||
@@ -191,7 +191,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
return &item, nil
|
return &item, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
By("Creating a new TestItem successfully")
|
By("Creating a new OnePasswordItem successfully")
|
||||||
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
||||||
|
|
||||||
created := &onepasswordv1.OnePasswordItem{}
|
created := &onepasswordv1.OnePasswordItem{}
|
||||||
@@ -214,7 +214,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
}, timeout, interval).Should(BeTrue())
|
}, timeout, interval).Should(BeTrue())
|
||||||
Expect(createdSecret.Data).Should(Equal(expectedData))
|
Expect(createdSecret.Data).Should(Equal(expectedData))
|
||||||
|
|
||||||
By("Deleting the TestItem successfully")
|
By("Deleting the OnePasswordItem successfully")
|
||||||
Eventually(func() error {
|
Eventually(func() error {
|
||||||
f := &onepasswordv1.OnePasswordItem{}
|
f := &onepasswordv1.OnePasswordItem{}
|
||||||
err := k8sClient.Get(ctx, key, f)
|
err := k8sClient.Get(ctx, key, f)
|
||||||
@@ -235,7 +235,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
}, timeout, interval).ShouldNot(Succeed())
|
}, timeout, interval).ShouldNot(Succeed())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("Should not update K8s secret if TestItem Version or VaultPath has not changed", func() {
|
It("Should not update K8s secret if OnePasswordItem Version or VaultPath has not changed", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
spec := onepasswordv1.OnePasswordItemSpec{
|
spec := onepasswordv1.OnePasswordItemSpec{
|
||||||
ItemPath: item1.Path,
|
ItemPath: item1.Path,
|
||||||
@@ -254,7 +254,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
Spec: spec,
|
Spec: spec,
|
||||||
}
|
}
|
||||||
|
|
||||||
By("Creating a new TestItem successfully")
|
By("Creating a new OnePasswordItem successfully")
|
||||||
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
||||||
|
|
||||||
item := &onepasswordv1.OnePasswordItem{}
|
item := &onepasswordv1.OnePasswordItem{}
|
||||||
@@ -271,7 +271,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
}, timeout, interval).Should(BeTrue())
|
}, timeout, interval).Should(BeTrue())
|
||||||
Expect(createdSecret.Data).Should(Equal(item1.SecretData))
|
Expect(createdSecret.Data).Should(Equal(item1.SecretData))
|
||||||
|
|
||||||
By("Updating TestItem type")
|
By("Updating OnePasswordItem type")
|
||||||
Eventually(func() bool {
|
Eventually(func() bool {
|
||||||
err1 := k8sClient.Get(ctx, key, item)
|
err1 := k8sClient.Get(ctx, key, item)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
@@ -291,39 +291,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
Expect(secret.Data).Should(Equal(item1.SecretData))
|
Expect(secret.Data).Should(Equal(item1.SecretData))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("Should update type of existing K8s Secret using TestItem", func() {
|
It("Should create custom K8s Secret type using OnePasswordItem", func() {
|
||||||
ctx := context.Background()
|
|
||||||
spec := onepasswordv1.OnePasswordItemSpec{
|
|
||||||
ItemPath: item1.Path,
|
|
||||||
}
|
|
||||||
|
|
||||||
key := types.NamespacedName{
|
|
||||||
Name: "test5",
|
|
||||||
Namespace: namespace,
|
|
||||||
}
|
|
||||||
|
|
||||||
toCreate := &onepasswordv1.OnePasswordItem{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: key.Name,
|
|
||||||
Namespace: key.Namespace,
|
|
||||||
},
|
|
||||||
Spec: spec,
|
|
||||||
Type: string(v1.SecretTypeBasicAuth),
|
|
||||||
}
|
|
||||||
|
|
||||||
By("Creating a new TestItem successfully")
|
|
||||||
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
|
||||||
|
|
||||||
By("Reading K8s secret")
|
|
||||||
secret := &v1.Secret{}
|
|
||||||
Eventually(func() bool {
|
|
||||||
err := k8sClient.Get(ctx, key, secret)
|
|
||||||
return err == nil
|
|
||||||
}, timeout, interval).Should(BeTrue())
|
|
||||||
Expect(secret.Type).Should(Equal(v1.SecretTypeBasicAuth))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("Should create custom K8s Secret type using TestItem", func() {
|
|
||||||
const customType = "CustomType"
|
const customType = "CustomType"
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
spec := onepasswordv1.OnePasswordItemSpec{
|
spec := onepasswordv1.OnePasswordItemSpec{
|
||||||
@@ -344,7 +312,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
Type: customType,
|
Type: customType,
|
||||||
}
|
}
|
||||||
|
|
||||||
By("Creating a new TestItem successfully")
|
By("Creating a new OnePasswordItem successfully")
|
||||||
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
||||||
|
|
||||||
By("Reading K8s secret")
|
By("Reading K8s secret")
|
||||||
@@ -360,7 +328,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("Failing part", func() {
|
Context("Unhappy part", func() {
|
||||||
It("Should throw an error if K8s Secret type is changed", func() {
|
It("Should throw an error if K8s Secret type is changed", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
spec := onepasswordv1.OnePasswordItemSpec{
|
spec := onepasswordv1.OnePasswordItemSpec{
|
||||||
@@ -380,7 +348,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
Spec: spec,
|
Spec: spec,
|
||||||
}
|
}
|
||||||
|
|
||||||
By("Creating a new TestItem successfully")
|
By("Creating a new OnePasswordItem successfully")
|
||||||
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
Expect(k8sClient.Create(ctx, toCreate)).Should(Succeed())
|
||||||
|
|
||||||
By("Reading K8s secret")
|
By("Reading K8s secret")
|
||||||
@@ -393,7 +361,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
return true
|
return true
|
||||||
}, timeout, interval).Should(BeTrue())
|
}, timeout, interval).Should(BeTrue())
|
||||||
|
|
||||||
By("Updating K8s secret type throw an error")
|
By("Failing to update K8s secret")
|
||||||
Eventually(func() bool {
|
Eventually(func() bool {
|
||||||
secret.Type = v1.SecretTypeBasicAuth
|
secret.Type = v1.SecretTypeBasicAuth
|
||||||
err := k8sClient.Update(ctx, secret)
|
err := k8sClient.Update(ctx, secret)
|
||||||
@@ -404,8 +372,8 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
}, timeout, interval).Should(BeFalse())
|
}, timeout, interval).Should(BeFalse())
|
||||||
})
|
})
|
||||||
|
|
||||||
When("TestItem name contains `_`", func() {
|
When("OnePasswordItem name contains `_`", func() {
|
||||||
It("An error occurred", func() {
|
It("Should fail creating a OnePasswordItem resource", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
spec := onepasswordv1.OnePasswordItemSpec{
|
spec := onepasswordv1.OnePasswordItemSpec{
|
||||||
ItemPath: item1.Path,
|
ItemPath: item1.Path,
|
||||||
@@ -424,14 +392,14 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
Spec: spec,
|
Spec: spec,
|
||||||
}
|
}
|
||||||
|
|
||||||
By("Creating a new TestItem")
|
By("Creating a new OnePasswordItem")
|
||||||
Expect(k8sClient.Create(ctx, toCreate)).To(HaveOccurred())
|
Expect(k8sClient.Create(ctx, toCreate)).To(HaveOccurred())
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
When("TestItem name contains capital letters", func() {
|
When("OnePasswordItem name contains capital letters", func() {
|
||||||
It("An error occurred", func() {
|
It("Should fail creating a OnePasswordItem resource", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
spec := onepasswordv1.OnePasswordItemSpec{
|
spec := onepasswordv1.OnePasswordItemSpec{
|
||||||
ItemPath: item1.Path,
|
ItemPath: item1.Path,
|
||||||
@@ -450,7 +418,7 @@ var _ = Describe("TestItem controller", func() {
|
|||||||
Spec: spec,
|
Spec: spec,
|
||||||
}
|
}
|
||||||
|
|
||||||
By("Creating a new TestItem")
|
By("Creating a new OnePasswordItem")
|
||||||
Expect(k8sClient.Create(ctx, toCreate)).To(HaveOccurred())
|
Expect(k8sClient.Create(ctx, toCreate)).To(HaveOccurred())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user