Skip to content

Commit

Permalink
fix(ws): Fix lint errors and typo
Browse files Browse the repository at this point in the history
Signed-off-by: mohamedch7 <121046693+mohamedch7@users.noreply.github.com>
  • Loading branch information
mohamedch7 committed Feb 13, 2025
1 parent 42e3ef9 commit 5752fb0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
4 changes: 2 additions & 2 deletions workspaces/backend/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ func (a *App) Routes() http.Handler {
router.GET(WorkspacesByNamePath, a.GetWorkspaceHandler)
router.POST(WorkspacesByNamespacePath, a.CreateWorkspaceHandler)
router.DELETE(WorkspacesByNamePath, a.DeleteWorkspaceHandler)
router.GET(WorkspaceYAMLPath, a.GetWorkspaceYAMLHandler)
router.GET(WorkspaceYAMLPath, a.GetWorkspaceYAMLHandler)

// workspacekinds
router.GET(AllWorkspaceKindsPath, a.GetWorkspaceKindsHandler)
router.GET(WorkspaceKindsByNamePath, a.GetWorkspaceKindHandler)

return a.RecoverPanic(a.enableCORS(router))
return a.recoverPanic(a.enableCORS(router))
}
18 changes: 16 additions & 2 deletions workspaces/backend/api/workspace_yaml_handler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package api

import (
Expand All @@ -8,7 +22,7 @@ import (

"errors"

"github.com/kubeflow/notebooks/workspaces/backend/internal/repositories"
"github.com/kubeflow/notebooks/workspaces/backend/internal/repositories/workspaces"

"sigs.k8s.io/yaml"
)
Expand All @@ -28,7 +42,7 @@ func (a *App) GetWorkspaceYAMLHandler(w http.ResponseWriter, r *http.Request, ps

workspace, err := a.repositories.Workspace.GetWorkspace(r.Context(), namespace, workspaceName)
if err != nil {
if errors.Is(err, repositories.ErrWorkspaceNotFound) {
if errors.Is(err, workspaces.ErrWorkspaceNotFound) {
a.notFoundResponse(w, r)
return
}
Expand Down
25 changes: 20 additions & 5 deletions workspaces/backend/api/workspace_yaml_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package api

import (
Expand All @@ -9,15 +23,16 @@ import (
"os"

"github.com/julienschmidt/httprouter"
"github.com/kubeflow/notebooks/workspaces/backend/internal/config"
"github.com/kubeflow/notebooks/workspaces/backend/internal/repositories"
kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kubeflow/notebooks/workspaces/backend/internal/config"
"github.com/kubeflow/notebooks/workspaces/backend/internal/repositories"
)

var _ = Describe("Workspace YAML Handler", Ordered, func() {
Expand All @@ -38,7 +53,7 @@ var _ = Describe("Workspace YAML Handler", Ordered, func() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
repos := repositories.NewRepositories(k8sClient)
a = &App{
Config: config.EnvConfig{
Config: &config.EnvConfig{
Port: 4000,
},
repositories: repos,
Expand Down Expand Up @@ -90,7 +105,7 @@ var _ = Describe("Workspace YAML Handler", Ordered, func() {
})

It("should retrieve the workspace YAML successfully", func() {
req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/workspaces/%s/%s/details/yaml", namespaceName, workspaceKey.Name), nil)
req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/workspaces/%s/%s/details/yaml", namespaceName, workspaceKey.Name), http.NoBody)
rr := httptest.NewRecorder()

ps := httprouter.Params{
Expand All @@ -110,7 +125,7 @@ var _ = Describe("Workspace YAML Handler", Ordered, func() {
})

It("should return 404 when workspace doesn't exist", func() {
req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/workspaces/%s/non-existent/details/yaml", namespaceName), nil)
req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/workspaces/%s/non-existent/details/yaml", namespaceName), http.NoBody)
rr := httptest.NewRecorder()

ps := httprouter.Params{
Expand Down

0 comments on commit 5752fb0

Please # to comment.