-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/cluster access definitions #74
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
Draft
makdeniss
wants to merge
18
commits into
main
Choose a base branch
from
feat/cluster-access-definitions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8721eec
ensured that we have ClusterAccess CRD installed
vertex451 e78ee20
wait for CRD to be fully registered
vertex451 d13952d
addressed comments
vertex451 b5d4187
removed TOCTOU race
vertex451 483f358
fix(deps): update module sigs.k8s.io/controller-runtime to v0.22.2 (#67)
renovate[bot] 44bd887
fix(deps): update module golang.org/x/text to v0.30.0 (#70)
renovate[bot] 06d9d8c
Fix: relations nil pointer check (#68)
vertex451 dfa9b29
fix(deps): update golang.org/x/exp digest to d2f985d (#71)
renovate[bot] e332a37
improved docs
vertex451 093457e
Merge branch 'main' of github.com:platform-mesh/kubernetes-graphql-ga…
vertex451 59ada28
Merge branch 'main' into feat/script
vertex451 d374320
removed testing script due for the simplicity of support
vertex451 cde201f
feat: cluster access definitions deletion (#69)
9d9185b
feat: refine cluster access definitions deletion (#69)
6ab9646
feat: add tests for cluster access definitions deletion and edit (#69)
1844a5a
Merge branch 'main' into feat/script
vertex451 3935460
Merge branch 'feat/script' into feat/cluster-access-definitions
965d2b2
Merge branch 'main' into feat/cluster-access-definitions
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 hidden or 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 hidden or 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,122 @@ | ||
| package clusteraccess | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/mock" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/client-go/rest" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
|
|
||
| "github.com/platform-mesh/golang-commons/logger" | ||
| gatewayv1alpha1 "github.com/platform-mesh/kubernetes-graphql-gateway/common/apis/v1alpha1" | ||
| workspacefile_mocks "github.com/platform-mesh/kubernetes-graphql-gateway/listener/pkg/workspacefile/mocks" | ||
| "github.com/platform-mesh/kubernetes-graphql-gateway/listener/reconciler" | ||
| ) | ||
|
|
||
| func TestGenerateSchemaSubroutine_Process_InvalidResourceType(t *testing.T) { | ||
| mockIO := workspacefile_mocks.NewMockIOHandler(t) | ||
| log, _ := logger.New(logger.DefaultConfig()) | ||
|
|
||
| r := &ClusterAccessReconciler{ | ||
| ioHandler: mockIO, | ||
| log: log, | ||
| } | ||
| s := &generateSchemaSubroutine{reconciler: r} | ||
|
|
||
| _, opErr := s.Process(context.Background(), &metav1.PartialObjectMetadata{}) | ||
|
|
||
| assert.NotNil(t, opErr) | ||
| } | ||
|
|
||
| func TestGenerateSchemaSubroutine_Process_MissingHostReturnsError(t *testing.T) { | ||
| scheme := runtime.NewScheme() | ||
| _ = gatewayv1alpha1.AddToScheme(scheme) | ||
|
|
||
| ca := &gatewayv1alpha1.ClusterAccess{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-cluster", | ||
| Annotations: map[string]string{}, | ||
| }, | ||
| Spec: gatewayv1alpha1.ClusterAccessSpec{ | ||
| // Host is intentionally empty to trigger validation error | ||
| }, | ||
| } | ||
|
|
||
| fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(ca).Build() | ||
|
|
||
| mockIO := workspacefile_mocks.NewMockIOHandler(t) | ||
| mockIO.EXPECT().Write(mock.Anything, mock.Anything).Maybe().Return(nil) | ||
| mockIO.EXPECT().Delete(mock.Anything).Maybe().Return(nil) | ||
|
|
||
| log, _ := logger.New(logger.DefaultConfig()) | ||
|
|
||
| r := &ClusterAccessReconciler{ | ||
| ioHandler: mockIO, | ||
| log: log, | ||
| opts: reconciler.ReconcilerOpts{ | ||
| Client: fakeClient, | ||
| Config: &rest.Config{Host: "https://unit-test.invalid"}, | ||
| ManagerOpts: ctrl.Options{Scheme: scheme}, | ||
| Scheme: scheme, | ||
| }, | ||
| } | ||
| s := &generateSchemaSubroutine{reconciler: r} | ||
|
|
||
| res, opErr := s.Process(context.Background(), ca) | ||
|
|
||
| assert.NotNil(t, opErr) | ||
| assert.Equal(t, ctrl.Result{}, res) | ||
| } | ||
|
|
||
| func TestGenerateSchemaSubroutine_Finalize_DeletesCurrentAndPreviousPaths(t *testing.T) { | ||
| mockIO := workspacefile_mocks.NewMockIOHandler(t) | ||
| log, _ := logger.New(logger.DefaultConfig()) | ||
|
|
||
| // Expect deletion of both current and previous paths | ||
| mockIO.EXPECT().Delete("current-path").Return(nil).Once() | ||
| mockIO.EXPECT().Delete("previous-path").Return(nil).Once() | ||
|
|
||
| r := &ClusterAccessReconciler{ | ||
| ioHandler: mockIO, | ||
| log: log, | ||
| } | ||
| s := &generateSchemaSubroutine{reconciler: r} | ||
|
|
||
| ca := &gatewayv1alpha1.ClusterAccess{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "my-resource", | ||
| Annotations: map[string]string{ | ||
| lastSchemaPathAnnotation: "previous-path", | ||
| }, | ||
| }, | ||
| Spec: gatewayv1alpha1.ClusterAccessSpec{ | ||
| Path: "current-path", | ||
| }, | ||
| } | ||
|
|
||
| res, opErr := s.Finalize(context.Background(), ca) | ||
|
|
||
| assert.Nil(t, opErr) | ||
| assert.Equal(t, ctrl.Result{}, res) | ||
| } | ||
|
|
||
| func TestGenerateSchemaSubroutine_restMapperFromConfig_SucceedsWithMinimalConfig(t *testing.T) { | ||
| mockIO := workspacefile_mocks.NewMockIOHandler(t) | ||
| log, _ := logger.New(logger.DefaultConfig()) | ||
|
|
||
| r := &ClusterAccessReconciler{ | ||
| ioHandler: mockIO, | ||
| log: log, | ||
| } | ||
| s := &generateSchemaSubroutine{reconciler: r} | ||
|
|
||
| rm, err := s.restMapperFromConfig(&rest.Config{}) | ||
|
|
||
| assert.NotNil(t, rm) | ||
| assert.NoError(t, err) | ||
| } |
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 case, where old file remains? If this code works, we will receive
failed to delete previous schema file during finalizationevery time.I wonder if deletion of previous filename makes sense at all.