Skip to content

Commit

Permalink
add resource cache entry test
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz committed Jul 22, 2024
1 parent 20e007a commit fe7241b
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pkg/cache/resource_cache_entry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cache

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)

var _ = Describe("Resource cache entry", Ordered, func() {
Context("Resource cache entry", func() {
const (
resourceName = "default"
namespace = "default"
)
rce := ResourceCacheEntry{}
pod := v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: resourceName,
Namespace: namespace,
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "test",
Image: "test",
},
},
},
}

It("check ResourceCacheEntry", func() {
res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&pod)
Expect(err).ToNot(HaveOccurred())
unstructuredPod := unstructured.Unstructured{Object: res}
Expect(rce.SetSHA(unstructuredPod, ApplySHA)).ToNot(HaveOccurred())
Expect(rce.SetSHA(unstructuredPod, ManifestSHA)).ToNot(HaveOccurred())
Expect(rce.SetSHA(unstructuredPod, ServerSHA)).ToNot(HaveOccurred())

Expect(rce.RequiresApply("test")).Should(BeTrue())
Expect(rce.RequiresApply("U33NQLAAPDEC5RDDKQ2KUHCUHIQUOC4PLMCQ5QVBYZ53B6V5UI5A====")).Should(BeFalse())

rce.Expire()
Expect(rce.applySHA).Should(BeNil())
Expect(rce.manifestSHA).Should(BeNil())
Expect(rce.serverSHA).ShouldNot(BeNil())
})

})

})

0 comments on commit fe7241b

Please sign in to comment.