-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: eliminate go-mpatch dependency
Signed-off-by: Michael Crenshaw <michael@crenshaw.dev>
- Loading branch information
1 parent
4ce1091
commit 4c6d557
Showing
4 changed files
with
13 additions
and
61 deletions.
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
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 |
---|---|---|
@@ -1,63 +1,19 @@ | ||
package admin | ||
|
||
import ( | ||
"reflect" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/undefinedlabs/go-mpatch" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/discovery" | ||
restclient "k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
func TestProjectAllowListGen(t *testing.T) { | ||
// go-mpatch only works on platforms with amd64 architecture | ||
if runtime.GOARCH != "amd64" { | ||
t.Skip() | ||
res := metav1.APIResource{ | ||
Name: "services", | ||
Kind: "Service", | ||
} | ||
resourceList := []*metav1.APIResourceList{{APIResources: []metav1.APIResource{res}}} | ||
|
||
useMock := true | ||
rules := clientcmd.NewDefaultClientConfigLoadingRules() | ||
overrides := &clientcmd.ConfigOverrides{} | ||
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides) | ||
|
||
if useMock { | ||
var patchClientConfig *mpatch.Patch | ||
patchClientConfig, err := mpatch.PatchInstanceMethodByName(reflect.TypeOf(clientConfig), "ClientConfig", func(*clientcmd.DeferredLoadingClientConfig) (*restclient.Config, error) { | ||
return nil, nil | ||
}) | ||
assert.NoError(t, err) | ||
|
||
patch, err := mpatch.PatchMethod(discovery.NewDiscoveryClientForConfig, func(c *restclient.Config) (*discovery.DiscoveryClient, error) { | ||
return &discovery.DiscoveryClient{LegacyPrefix: "/api"}, nil | ||
}) | ||
assert.NoError(t, err) | ||
|
||
var patchSeverPreferredResources *mpatch.Patch | ||
discoClient := &discovery.DiscoveryClient{} | ||
patchSeverPreferredResources, err = mpatch.PatchInstanceMethodByName(reflect.TypeOf(discoClient), "ServerPreferredResources", func(*discovery.DiscoveryClient) ([]*metav1.APIResourceList, error) { | ||
res := metav1.APIResource{ | ||
Name: "services", | ||
Kind: "Service", | ||
} | ||
resourceList := []*metav1.APIResourceList{{APIResources: []metav1.APIResource{res}}} | ||
return resourceList, nil | ||
}) | ||
assert.NoError(t, err) | ||
|
||
defer func() { | ||
err = patchClientConfig.Unpatch() | ||
assert.NoError(t, err) | ||
err = patch.Unpatch() | ||
assert.NoError(t, err) | ||
err = patchSeverPreferredResources.Unpatch() | ||
err = patch.Unpatch() | ||
}() | ||
} | ||
|
||
globalProj := generateProjectAllowList(clientConfig, "testdata/test_clusterrole.yaml", "testproj") | ||
globalProj := generateProjectAllowList(resourceList, "testdata/test_clusterrole.yaml", "testproj") | ||
assert.True(t, len(globalProj.Spec.NamespaceResourceWhitelist) > 0) | ||
} |
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