/* Copyright 2026 The kcp Authors. 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 workspace import ( "testing" "github.com/stretchr/testify/require" "github.com/kcp-dev/kcp/test/e2e/framework" ) func TestCreateWorkspace(t *testing.T) { t.Parallel() framework.Suite(t, "cli") tc := framework.NewCli(t) wsName := "test-create-workspace" t.Log("Creating a workspace does not error") _, _, err := tc.RunPlugin(t, "create-workspace", wsName) require.NoError(t, err) t.Log("Creating the same workspace again fails") _, stderr, err := tc.RunPlugin(t, "create-workspace", wsName) require.Error(t, err) require.Contains(t, stderr.String(), "already exists") t.Log("Creating the same workspace with --ignore-existing does not error") _, _, err = tc.RunPlugin(t, "create-workspace", wsName, "--ignore-existing") require.NoError(t, err) } func TestCreateWorkspaceEnter(t *testing.T) { t.Parallel() framework.Suite(t, "cli") tc := framework.NewCli(t) wsName := "test-create-workspace-enter" t.Log("Creating a workspace and entering it does not error") _, _, err := tc.RunPlugin(t, "create-workspace", wsName, "--enter") require.NoError(t, err) t.Log("The current workspace is set to the new workspace") stdout, _, err := tc.RunPlugin(t, "ws", ".", "--short") require.NoError(t, err) require.Contains(t, stdout.String(), wsName) } func TestUseWorkspace(t *testing.T) { t.Parallel() framework.Suite(t, "cli") tc := framework.NewCli(t) wsName := "test-use-workspace" _, _, err := tc.RunPlugin(t, "create-workspace", wsName) require.NoError(t, err) _, _, err = tc.RunPlugin(t, "kcp", "ws", "use", wsName) require.NoError(t, err) stdout, _, err := tc.RunPlugin(t, "kcp", "ws", ".") require.NoError(t, err) require.Contains(t, stdout.String(), wsName) }