Skip to content

Commit e8387b4

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 e8387b4

File tree

9 files changed

+814
-0
lines changed

9 files changed

+814
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
26+
func TestHealthCheck(t *testing.T) {
27+
RegisterFailHandler(Fail)
28+
RunSpecs(t, "HealthCheck Suite")
29+
}

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

0 commit comments

Comments
 (0)