Skip to content

Commit bf28068

Browse files
Add e2e test for component filtering
Signed-off-by: Kate Goldenring <[email protected]>
1 parent 03def79 commit bf28068

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

e2e/selective_deployment_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"testing"
6+
"time"
7+
8+
v1 "k8s.io/api/core/v1"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
"sigs.k8s.io/e2e-framework/klient"
11+
"sigs.k8s.io/e2e-framework/klient/wait"
12+
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
13+
"sigs.k8s.io/e2e-framework/pkg/envconf"
14+
"sigs.k8s.io/e2e-framework/pkg/features"
15+
16+
spinapps_v1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1"
17+
"github.com/spinkube/spin-operator/e2e/helper"
18+
"github.com/stretchr/testify/require"
19+
)
20+
21+
// TestSelectiveDeployment checks that the operator and shim have support for running a subset of a Spin app's components
22+
func TestSelectiveDeployment(t *testing.T) {
23+
var client klient.Client
24+
25+
// TODO: Use an image from a sample app in this repository
26+
appImage := "ghcr.io/kate-goldenring/spin-operator/examples/spin-salutations:20241022-144454"
27+
testSpinAppName := "test-component-filtering"
28+
29+
defaultTest := features.New("default and most minimal setup").
30+
Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
31+
32+
client = cfg.Client()
33+
34+
if err := spinapps_v1alpha1.AddToScheme(client.Resources(testNamespace).GetScheme()); err != nil {
35+
t.Fatalf("failed to register the spinapps_v1alpha1 types with Kubernetes scheme: %s", err)
36+
}
37+
38+
return ctx
39+
}).
40+
Assess("spin app custom resource is created", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
41+
testSpinApp := newSpinAppCR(testSpinAppName, appImage, "containerd-shim-spin", []string{"hello"})
42+
43+
if err := client.Resources().Create(ctx, testSpinApp); err != nil {
44+
t.Fatalf("Failed to create spinapp: %s", err)
45+
}
46+
return ctx
47+
}).
48+
Assess("spin app deployment and service are available", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
49+
// wait for deployment to be ready
50+
if err := wait.For(
51+
conditions.New(client.Resources()).DeploymentAvailable(testSpinAppName, testNamespace),
52+
wait.WithTimeout(3*time.Minute),
53+
wait.WithInterval(time.Second),
54+
); err != nil {
55+
t.Fatal(err)
56+
}
57+
58+
svc := &v1.ServiceList{
59+
Items: []v1.Service{
60+
{ObjectMeta: metav1.ObjectMeta{Name: testSpinAppName, Namespace: testNamespace}},
61+
},
62+
}
63+
64+
if err := wait.For(
65+
conditions.New(client.Resources()).ResourcesFound(svc),
66+
wait.WithTimeout(3*time.Minute),
67+
wait.WithInterval(500*time.Millisecond),
68+
); err != nil {
69+
t.Fatal(err)
70+
}
71+
return ctx
72+
}).
73+
Assess("spin app is only serving hello component", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
74+
helper.EnsureDebugContainer(t, ctx, cfg, testNamespace)
75+
76+
_, status, err := helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/hi", "")
77+
78+
require.NoError(t, err)
79+
require.Equal(t, 200, status)
80+
81+
_, status, err = helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/bye", "")
82+
83+
require.NoError(t, err)
84+
require.Equal(t, 404, status)
85+
86+
return ctx
87+
}).
88+
Feature()
89+
testEnv.Test(t, defaultTest)
90+
}

0 commit comments

Comments
 (0)