Skip to content

Commit

Permalink
added e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
facchettos committed Apr 8, 2024
1 parent 22ade11 commit 82dc979
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions e2e/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,14 @@ var _ = ginkgo.Describe("Plugin test", func() {
WithTimeout(pollingDurationLong).
Should(gomega.BeTrue())
})

ginkgo.It("check the interceptor", func() {
// wait for secret to become synced
vPod := &corev1.Pod{}
err := f.VclusterCRClient.Get(f.Context, types.NamespacedName{Name: "stuff", Namespace: "test"}, vPod)
framework.ExpectNoError(err)

// check if secret is synced correctly
framework.ExpectEqual(vPod.Name, "definitelynotstuff")
})
})
1 change: 1 addition & 0 deletions e2e/test_plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func main() {
plugin.MustRegister(syncers.NewMyDeploymentSyncer(ctx))
plugin.MustRegister(syncers.NewCarSyncer(ctx))
plugin.MustRegister(syncers.NewImportSecrets(ctx))
plugin.MustRegister(syncers.DummyInterceptor{})
plugin.MustStart()
}

Expand Down
52 changes: 52 additions & 0 deletions e2e/test_plugin/syncers/interceptor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package syncers

import (
"net/http"

"github.com/loft-sh/vcluster-sdk/plugin"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apiserver/pkg/endpoints/handlers/negotiation"
"k8s.io/apiserver/pkg/endpoints/handlers/responsewriters"

v2 "github.com/loft-sh/vcluster/pkg/plugin/v2"
corev1 "k8s.io/api/core/v1"
)

var _ plugin.Interceptor = DummyInterceptor{}

type DummyInterceptor struct {
}

func (d DummyInterceptor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s := serializer.NewCodecFactory(runtime.NewScheme())
responsewriters.WriteObjectNegotiated(
s,
negotiation.DefaultEndpointRestrictions,
schema.GroupVersion{
Group: "",
Version: "v1"},
w,
r,
200,
&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "definitelynotstuff"}},
false)
}

func (d DummyInterceptor) Name() string {
return "test_interceptor"
}

func (d DummyInterceptor) InterceptedRequests() []v2.Interceptor {
return []v2.Interceptor{
{
HandlerName: "test_handler",
APIGroups: []string{""},
Resources: []string{"pods"},
ResourceNames: []string{"stuff"},
Verbs: []string{"list"},
},
}
}

0 comments on commit 82dc979

Please sign in to comment.