Skip to content

Commit dab3140

Browse files
committed
test(ws): Ensure test files exist in backend for any executed code #381
Signed-off-by: Hen Schwartz (EXT-Nokia) <[email protected]>
1 parent b2bee1d commit dab3140

File tree

5 files changed

+744
-0
lines changed

5 files changed

+744
-0
lines changed

workspaces/backend/internal/models/health_check/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ const (
3131
ServiceStatusHealthy ServiceStatus = "Healthy"
3232
ServiceStatusUnhealthy ServiceStatus = "Unhealthy"
3333
)
34+
35+
func NewHealthCheck(status ServiceStatus, version string) HealthCheck {
36+
return HealthCheck{
37+
Status: status,
38+
SystemInfo: SystemInfo{Version: version},
39+
}
40+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2024.
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+
http://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 health_check_test
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
25+
models "github.com/kubeflow/notebooks/workspaces/backend/internal/models/health_check"
26+
)
27+
28+
func TestHealthCheck(t *testing.T) {
29+
RegisterFailHandler(Fail)
30+
RunSpecs(t, "HealthCheck Suite")
31+
}
32+
33+
var _ = Describe("HealthCheck Types", func() {
34+
Context("ServiceStatus constants", func() {
35+
It("should have expected string values", func() {
36+
Expect(string(models.ServiceStatusHealthy)).To(Equal("Healthy"))
37+
Expect(string(models.ServiceStatusUnhealthy)).To(Equal("Unhealthy"))
38+
})
39+
})
40+
41+
Context("HealthCheck struct", func() {
42+
It("should hold correct values", func() {
43+
hc := models.HealthCheck{
44+
Status: models.ServiceStatusHealthy,
45+
SystemInfo: models.SystemInfo{Version: "1.2.3"},
46+
}
47+
48+
Expect(hc.Status).To(Equal(models.ServiceStatusHealthy))
49+
Expect(hc.SystemInfo.Version).To(Equal("1.2.3"))
50+
})
51+
52+
It("should create a new HealthCheck using the constructor", func() {
53+
hc := models.NewHealthCheck(models.ServiceStatusUnhealthy, "9.9.9")
54+
55+
Expect(hc.Status).To(Equal(models.ServiceStatusUnhealthy))
56+
Expect(hc.SystemInfo.Version).To(Equal("9.9.9"))
57+
})
58+
})
59+
})
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
Copyright 2024.
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+
http://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 workspacekinds_test
18+
19+
import (
20+
"testing"
21+
22+
kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
23+
. "github.com/onsi/ginkgo/v2"
24+
. "github.com/onsi/gomega"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/utils/ptr"
27+
28+
workspacekinds "github.com/kubeflow/notebooks/workspaces/backend/internal/models/workspacekinds"
29+
)
30+
31+
func TestWorkspaceKinds(t *testing.T) {
32+
RegisterFailHandler(Fail)
33+
RunSpecs(t, "WorkspaceKinds Suite")
34+
}
35+
36+
var _ = Describe("WorkspaceKind Types", func() {
37+
Describe("NewWorkspaceKindModelFromWorkspaceKind", func() {
38+
Context("with complete WorkspaceKind", func() {
39+
It("should create a complete WorkspaceKind model with all fields", func() {
40+
wsk := &kubefloworgv1beta1.WorkspaceKind{
41+
ObjectMeta: metav1.ObjectMeta{
42+
Name: "test-workspacekind",
43+
Namespace: "kubeflow",
44+
Labels: map[string]string{
45+
"app": "workspacekind",
46+
"version": "v1",
47+
},
48+
Annotations: map[string]string{
49+
"description": "Complete workspacekind",
50+
},
51+
},
52+
Spec: kubefloworgv1beta1.WorkspaceKindSpec{
53+
Spawner: kubefloworgv1beta1.WorkspaceKindSpawner{
54+
DisplayName: "Complete Workspacekind",
55+
Description: "A complete test workspacekind with all features",
56+
Deprecated: ptr.To(false),
57+
Hidden: ptr.To(false),
58+
Icon: kubefloworgv1beta1.WorkspaceKindIcon{
59+
Url: ptr.To("/workspaces/backend/api/v1/workspacekinds/test-workspacekind/assets/icon"),
60+
},
61+
Logo: kubefloworgv1beta1.WorkspaceKindIcon{
62+
Url: ptr.To("/workspaces/backend/api/v1/workspacekinds/test-workspacekind/assets/logo"),
63+
},
64+
},
65+
PodTemplate: kubefloworgv1beta1.WorkspaceKindPodTemplate{
66+
PodMetadata: &kubefloworgv1beta1.WorkspaceKindPodMetadata{
67+
Labels: map[string]string{
68+
"app": "test-workspacekind",
69+
},
70+
Annotations: map[string]string{
71+
"annotation-key": "annotation-value",
72+
},
73+
},
74+
},
75+
},
76+
}
77+
78+
result := workspacekinds.NewWorkspaceKindModelFromWorkspaceKind(wsk)
79+
80+
Expect(result).ToNot(BeNil())
81+
Expect(result.Name).To(Equal("test-workspacekind"))
82+
Expect(result.DisplayName).To(Equal("Complete Workspacekind"))
83+
Expect(result.Description).To(Equal("A complete test workspacekind with all features"))
84+
Expect(result.Deprecated).To(BeFalse())
85+
Expect(result.DeprecationMessage).To(Equal(""))
86+
Expect(result.Hidden).To(BeFalse())
87+
Expect(result.Icon.URL).To(Equal("/workspaces/backend/api/v1/workspacekinds/test-workspacekind/assets/icon"))
88+
Expect(result.Logo.URL).To(Equal("/workspaces/backend/api/v1/workspacekinds/test-workspacekind/assets/logo"))
89+
Expect(result.PodTemplate.PodMetadata.Labels).To(HaveKeyWithValue("app", "test-workspacekind"))
90+
Expect(result.PodTemplate.PodMetadata.Annotations).To(HaveKeyWithValue("annotation-key", "annotation-value"))
91+
})
92+
})
93+
94+
Context("with empty strings in required fields", func() {
95+
It("should handle empty display name and description", func() {
96+
wsk := &kubefloworgv1beta1.WorkspaceKind{
97+
ObjectMeta: metav1.ObjectMeta{
98+
Name: "empty-fields-workspace",
99+
},
100+
Spec: kubefloworgv1beta1.WorkspaceKindSpec{
101+
Spawner: kubefloworgv1beta1.WorkspaceKindSpawner{
102+
DisplayName: "",
103+
Description: "",
104+
},
105+
},
106+
}
107+
108+
result := workspacekinds.NewWorkspaceKindModelFromWorkspaceKind(wsk)
109+
110+
Expect(result).ToNot(BeNil())
111+
Expect(result.Name).To(Equal("empty-fields-workspace"))
112+
Expect(result.DisplayName).To(Equal(""))
113+
Expect(result.Description).To(Equal(""))
114+
})
115+
})
116+
117+
Context("with special characters in names", func() {
118+
It("should handle names with hyphens and underscores", func() {
119+
wsk := &kubefloworgv1beta1.WorkspaceKind{
120+
ObjectMeta: metav1.ObjectMeta{
121+
Name: "special-chars_workspace-123",
122+
},
123+
Spec: kubefloworgv1beta1.WorkspaceKindSpec{
124+
Spawner: kubefloworgv1beta1.WorkspaceKindSpawner{
125+
DisplayName: "Special-Chars_Workspace 123!",
126+
Description: "Workspace with special characters in name",
127+
},
128+
},
129+
}
130+
131+
result := workspacekinds.NewWorkspaceKindModelFromWorkspaceKind(wsk)
132+
133+
Expect(result).ToNot(BeNil())
134+
Expect(result.Name).To(Equal("special-chars_workspace-123"))
135+
Expect(result.DisplayName).To(Equal("Special-Chars_Workspace 123!"))
136+
})
137+
})
138+
139+
Context("with long descriptions", func() {
140+
It("should handle very long descriptions", func() {
141+
longDescription := "This is a very long description that contains multiple sentences. " +
142+
"It describes a workspace kind that has many features and capabilities. " +
143+
"The description should be preserved exactly as provided without truncation. " +
144+
"This tests the ability to handle larger text fields in the workspace kind model."
145+
146+
wsk := &kubefloworgv1beta1.WorkspaceKind{
147+
ObjectMeta: metav1.ObjectMeta{
148+
Name: "long-description-workspace",
149+
},
150+
Spec: kubefloworgv1beta1.WorkspaceKindSpec{
151+
Spawner: kubefloworgv1beta1.WorkspaceKindSpawner{
152+
DisplayName: "Long Description Workspace",
153+
Description: longDescription,
154+
},
155+
},
156+
}
157+
158+
result := workspacekinds.NewWorkspaceKindModelFromWorkspaceKind(wsk)
159+
160+
Expect(result).ToNot(BeNil())
161+
Expect(result.Description).To(Equal(longDescription))
162+
Expect(len(result.Description)).To(BeNumerically(">", 200))
163+
})
164+
})
165+
166+
})
167+
})

0 commit comments

Comments
 (0)