Skip to content

Commit 07e2981

Browse files
Add unit test for scheduledsparkapplication_validator (#2694)
bump test coverage to 90%.5% Signed-off-by: 世行 <shixing.gm@alibaba-inc.com> Co-authored-by: 世行 <shixing.gm@alibaba-inc.com>
1 parent 827bdd3 commit 07e2981

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Copyright 2025 The Kubeflow authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package webhook
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/kubeflow/spark-operator/v2/api/v1beta2"
24+
)
25+
26+
func TestScheduledSparkApplicationValidatorValidateCreate(t *testing.T) {
27+
validator := NewScheduledSparkApplicationValidator()
28+
29+
t.Run("returns nil for unrelated object types", func(t *testing.T) {
30+
warnings, err := validator.ValidateCreate(context.Background(), &v1beta2.SparkApplication{})
31+
if err != nil {
32+
t.Fatalf("expected no error, got %v", err)
33+
}
34+
if len(warnings) != 0 {
35+
t.Fatalf("expected no warnings, got %v", warnings)
36+
}
37+
})
38+
39+
t.Run("accepts ScheduledSparkApplication instances", func(t *testing.T) {
40+
app := &v1beta2.ScheduledSparkApplication{}
41+
warnings, err := validator.ValidateCreate(context.Background(), app)
42+
if err != nil {
43+
t.Fatalf("expected no error, got %v", err)
44+
}
45+
if len(warnings) != 0 {
46+
t.Fatalf("expected no warnings, got %v", warnings)
47+
}
48+
})
49+
}
50+
51+
func TestScheduledSparkApplicationValidatorValidateUpdate(t *testing.T) {
52+
validator := NewScheduledSparkApplicationValidator()
53+
54+
t.Run("returns nil for unrelated object types", func(t *testing.T) {
55+
warnings, err := validator.ValidateUpdate(
56+
context.Background(),
57+
&v1beta2.ScheduledSparkApplication{},
58+
&v1beta2.SparkApplication{},
59+
)
60+
if err != nil {
61+
t.Fatalf("expected no error, got %v", err)
62+
}
63+
if len(warnings) != 0 {
64+
t.Fatalf("expected no warnings, got %v", warnings)
65+
}
66+
})
67+
68+
t.Run("accepts ScheduledSparkApplication instances", func(t *testing.T) {
69+
oldApp := &v1beta2.ScheduledSparkApplication{}
70+
newApp := &v1beta2.ScheduledSparkApplication{}
71+
warnings, err := validator.ValidateUpdate(context.Background(), oldApp, newApp)
72+
if err != nil {
73+
t.Fatalf("expected no error, got %v", err)
74+
}
75+
if len(warnings) != 0 {
76+
t.Fatalf("expected no warnings, got %v", warnings)
77+
}
78+
})
79+
}
80+
81+
func TestScheduledSparkApplicationValidatorValidateDelete(t *testing.T) {
82+
validator := NewScheduledSparkApplicationValidator()
83+
84+
t.Run("returns nil for unrelated object types", func(t *testing.T) {
85+
warnings, err := validator.ValidateDelete(context.Background(), &v1beta2.SparkApplication{})
86+
if err != nil {
87+
t.Fatalf("expected no error, got %v", err)
88+
}
89+
if len(warnings) != 0 {
90+
t.Fatalf("expected no warnings, got %v", warnings)
91+
}
92+
})
93+
94+
t.Run("accepts ScheduledSparkApplication instances", func(t *testing.T) {
95+
warnings, err := validator.ValidateDelete(context.Background(), &v1beta2.ScheduledSparkApplication{})
96+
if err != nil {
97+
t.Fatalf("expected no error, got %v", err)
98+
}
99+
if len(warnings) != 0 {
100+
t.Fatalf("expected no warnings, got %v", warnings)
101+
}
102+
})
103+
}

0 commit comments

Comments
 (0)