Skip to content

Commit ddff5d4

Browse files
committed
test: add DeepCopy roundtrip tests for experimental packages
Add basic coverage for aiservicev1alpha1, backendlbv1alpha2, tokenpolicyv1alpha1, and wasmpluginv1alpha1.
1 parent 527f21c commit ddff5d4

4 files changed

Lines changed: 124 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package aiservicev1alpha1
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
func TestDeepCopyRoundtrip(t *testing.T) {
11+
original := &AIService{
12+
ObjectMeta: metav1.ObjectMeta{
13+
Name: "test-ai",
14+
Namespace: "default",
15+
},
16+
Spec: AIServiceSpec{
17+
Provider: "openai",
18+
Format: "openai",
19+
Model: "gpt-4",
20+
Auth: AIServiceAuth{
21+
Type: "apiKey",
22+
Secret: "my-secret",
23+
Header: "Authorization",
24+
},
25+
Timeout: "30s",
26+
Retry: AIRetryConfig{
27+
MaxRetries: 3,
28+
Backoff: "exponential",
29+
},
30+
},
31+
}
32+
copied := original.DeepCopy()
33+
assert.Equal(t, original, copied)
34+
assert.NotSame(t, original, copied)
35+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package backendlbv1alpha2
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
func TestDeepCopyRoundtrip(t *testing.T) {
11+
lbType := LoadBalancingStrategyTypeRoundRobin
12+
original := &BackendLBPolicy{
13+
ObjectMeta: metav1.ObjectMeta{
14+
Name: "test-lb",
15+
Namespace: "default",
16+
},
17+
Spec: BackendLBPolicySpec{
18+
LoadBalancing: &LoadBalancingPolicy{
19+
Type: &lbType,
20+
},
21+
},
22+
}
23+
copied := original.DeepCopy()
24+
assert.Equal(t, original, copied)
25+
assert.NotSame(t, original, copied)
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tokenpolicyv1alpha1
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
9+
)
10+
11+
func TestDeepCopyRoundtrip(t *testing.T) {
12+
original := &TokenPolicy{
13+
ObjectMeta: metav1.ObjectMeta{
14+
Name: "test-policy",
15+
Namespace: "default",
16+
},
17+
Spec: TokenPolicySpec{
18+
TargetRefs: []gatewayv1.LocalPolicyTargetReference{
19+
{Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", Name: "my-route"},
20+
},
21+
TokensPerMinute: 1000,
22+
RequestsPerMinute: 100,
23+
Scope: "per-user",
24+
Burst: 1.5,
25+
},
26+
}
27+
copied := original.DeepCopy()
28+
assert.Equal(t, original, copied)
29+
assert.NotSame(t, original, copied)
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package wasmpluginv1alpha1
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
func TestDeepCopyRoundtrip(t *testing.T) {
11+
original := &WasmPlugin{
12+
ObjectMeta: metav1.ObjectMeta{
13+
Name: "test-plugin",
14+
Namespace: "default",
15+
},
16+
Spec: WasmPluginSpec{
17+
Wasm: WasmSource{
18+
URL: "https://example.com/plugin.wasm",
19+
SHA256: "abcdef",
20+
},
21+
Hooks: []WasmHook{HookOnRequest, HookOnResponse},
22+
Config: `{"key": "value"}`,
23+
Sandbox: WasmSandbox{
24+
MaxMemoryBytes: 65536,
25+
MaxExecutionTimeMs: 100,
26+
AllowNetwork: true,
27+
},
28+
},
29+
}
30+
copied := original.DeepCopy()
31+
assert.Equal(t, original, copied)
32+
assert.NotSame(t, original, copied)
33+
}

0 commit comments

Comments
 (0)