-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E2e test #241
+470
−1
Merged
E2e test #241
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4368b40
add resource cache e2e tests
zreigz 30077a8
init e2e test for resource cache
zreigz 767fbcb
Merge branch 'main' into e2e
zreigz 475e558
check kind cluster
zreigz 4e0e719
create cluster
zreigz d7ebf31
update with retry
zreigz c1d739c
fix linter
zreigz e409be1
fix anntation
zreigz 99db50f
add CRD test
zreigz 20e007a
fix CRD test
zreigz fe7241b
add resource cache entry test
zreigz a450530
add e2e tag
zreigz eb9e276
add cache test
zreigz 9e15dce
add cache test
zreigz 1efe1ec
add cache tag for unit tests
zreigz 00a8ecc
fix update with retry
zreigz c94566e
improve retry
zreigz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: E2E | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
create-cluster: | ||
name: Create Kind cluster | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Install GO | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: go.mod | ||
cache: false | ||
- name: Create kind cluster | ||
uses: helm/[email protected] | ||
- run: kind get clusters | ||
- run: go test -v -race ./pkg/cache/... -tags="e2e" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//go:build cache | ||
|
||
package cache | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
. "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" | ||
) | ||
|
||
func TestCache(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Test cache") | ||
} | ||
|
||
var _ = Describe("Resource cache", Ordered, func() { | ||
Context("Resource cache", func() { | ||
const ( | ||
resourceName = "default" | ||
namespace = "default" | ||
key = "key" | ||
) | ||
rce := &ResourceCacheEntry{} | ||
pod := v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: resourceName, | ||
Namespace: namespace, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "test", | ||
Image: "test", | ||
}, | ||
}, | ||
}, | ||
} | ||
cache := NewCache[*ResourceCacheEntry](context.Background(), time.Second) | ||
|
||
It("check cache", 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()) | ||
|
||
cache.Set(key, rce) | ||
cachedResource, ok := cache.Get(key) | ||
Expect(ok).To(BeTrue()) | ||
Expect(cachedResource).To(Equal(rce)) | ||
// should expire and clean applySHA and manifestSHA | ||
time.Sleep(1 * time.Second) | ||
cachedResource, ok = cache.Get(key) | ||
Expect(ok).To(BeTrue()) | ||
Expect(cachedResource.applySHA).Should(BeNil()) | ||
Expect(cachedResource.manifestSHA).Should(BeNil()) | ||
Expect(cachedResource.serverSHA).ShouldNot(BeNil()) | ||
}) | ||
|
||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build cache | ||
|
||
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()) | ||
}) | ||
|
||
}) | ||
|
||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to get rid of these sleep calls? Looks like potential race condition and it will make tests run longer.