diff --git a/cmd/config.go b/cmd/config.go index 041210a..d3523b7 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -407,52 +407,3 @@ func pathContains(root, candidate string) bool { } return rel == "." || (rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator))) } - -// removeProjectConfig removes a project from the configuration -// Keeping for future use when we add a 'remove' or 'clean' command -// -//nolint:unused // kept for future 'orchcli remove' command implementation -func removeProjectConfig(projectPath string) error { - configPath, err := GetConfigPath() - if err != nil { - return err - } - - // Use file locking for concurrent access - lockPath := configPath + ".lock" - fileLock := flock.New(lockPath) - - // Try to acquire lock - err = fileLock.Lock() - if err != nil { - return fmt.Errorf("failed to acquire config lock: %w", err) - } - defer func() { - _ = fileLock.Unlock() - }() - - // Load current config - config, err := LoadConfig() - if err != nil { - return err - } - - // Remove project - delete(config.Projects, projectPath) - - if config.CurrentProject == projectPath { - config.CurrentProject = "" - } - - // Marshal and save - data, err := json.MarshalIndent(config, "", " ") - if err != nil { - return fmt.Errorf("failed to marshal config: %w", err) - } - - if err := writeFileAtomically(configPath, data, configFilePerm); err != nil { - return fmt.Errorf("failed to write config: %w", err) - } - - return nil -} diff --git a/npm/index.js b/npm/index.js deleted file mode 100644 index b36de13..0000000 --- a/npm/index.js +++ /dev/null @@ -1,7 +0,0 @@ -const path = require('path'); -const os = require('os'); - -const ext = os.platform() === 'win32' ? '.exe' : ''; -const binPath = path.join(__dirname, 'bin', `orchcli-bin${ext}`); - -module.exports = { binPath }; diff --git a/npm/scripts/prepack.js b/npm/scripts/prepack.js deleted file mode 100755 index 3662772..0000000 --- a/npm/scripts/prepack.js +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env node - -const { execSync } = require('child_process'); -const fs = require('fs'); -const path = require('path'); - -console.log('Preparing OrchCLI package...'); - -const projectRoot = path.join(__dirname, '..', '..'); -const binDir = path.join(__dirname, '..', 'bin'); - -// Ensure bin directory exists -if (!fs.existsSync(binDir)) { - fs.mkdirSync(binDir, { recursive: true }); -} - -// Don't build binary in prepack - postinstall will handle it -console.log('Skipping binary build - postinstall will handle it'); - -console.log('Package preparation complete!'); \ No newline at end of file diff --git a/package.json b/package.json index 32ce86a..87f6e16 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,11 @@ "name": "@kubeorch/cli", "version": "0.0.3", "description": "OrchCLI - KubeOrch Developer CLI", - "main": "npm/index.js", "bin": { "orchcli": "./npm/bin/orchcli" }, "scripts": { "postinstall": "node npm/scripts/postinstall.js", - "prepack": "node npm/scripts/prepack.js", "test": "echo \"Tests are run via Go test suite\" && exit 0" }, "repository": { diff --git a/test/docker-install-test.sh b/test/docker-install-test.sh deleted file mode 100644 index df4bb4d..0000000 --- a/test/docker-install-test.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh -set -e - -# Docker-based installation tests for OrchCLI -# Run: ./test/docker-install-test.sh -# -# Prerequisites: Docker must be running - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -CLI_DIR="$(dirname "$SCRIPT_DIR")" - -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' - -PASS=0 -FAIL=0 - -run_test() { - local name="$1" - local image="$2" - local cmd="$3" - - printf "${YELLOW}[TEST]${NC} %-40s " "$name" - - if output=$(docker run --rm "$image" sh -c "$cmd" 2>&1); then - printf "${GREEN}PASS${NC}\n" - PASS=$((PASS + 1)) - else - printf "${RED}FAIL${NC}\n" - echo " Output: $output" - FAIL=$((FAIL + 1)) - fi -} - -echo "================================================" -echo " OrchCLI Docker Installation Tests" -echo "================================================" -echo "" - -# Test 1: npm install on Node 20 Alpine -run_test "npm install (node:20-alpine)" \ - "node:20-alpine" \ - "npm install -g @kubeorch/cli && orchcli --version" - -# Test 2: npm install on Node 20 Debian -run_test "npm install (node:20-bookworm)" \ - "node:20-bookworm" \ - "npm install -g @kubeorch/cli && orchcli --version" - -# Test 3: npm install on Node 24 Alpine -run_test "npm install (node:24-alpine)" \ - "node:24-alpine" \ - "npm install -g @kubeorch/cli && orchcli --version" - -# Test 4: curl install on Alpine -run_test "curl install (alpine:3.20)" \ - "alpine:3.20" \ - "apk add --no-cache curl && curl -sfL https://raw.githubusercontent.com/KubeOrch/cli/main/install.sh | sh && orchcli --version" - -# Test 5: curl install on Ubuntu -run_test "curl install (ubuntu:24.04)" \ - "ubuntu:24.04" \ - "apt-get update -qq && apt-get install -y -qq curl > /dev/null 2>&1 && curl -sfL https://raw.githubusercontent.com/KubeOrch/cli/main/install.sh | sh && orchcli --version" - -# Test 6: wget install on Debian -run_test "wget install (debian:bookworm-slim)" \ - "debian:bookworm-slim" \ - "apt-get update -qq && apt-get install -y -qq wget > /dev/null 2>&1 && wget -qO- https://raw.githubusercontent.com/KubeOrch/cli/main/install.sh | sh && orchcli --version" - -echo "" -echo "================================================" -echo " Results: ${GREEN}${PASS} passed${NC}, ${RED}${FAIL} failed${NC}" -echo "================================================" - -if [ "$FAIL" -gt 0 ]; then - exit 1 -fi diff --git a/tests/helpers/test_helpers.go b/tests/helpers/test_helpers.go index 687787f..5a9de28 100644 --- a/tests/helpers/test_helpers.go +++ b/tests/helpers/test_helpers.go @@ -2,7 +2,6 @@ package helpers import ( - "io" "os" "path/filepath" "runtime" @@ -61,32 +60,6 @@ func (h *TestHelper) ReadFile(path string) string { return string(content) } -// CaptureOutput captures stdout and stderr -func CaptureOutput(f func()) (string, string, error) { - oldStdout := os.Stdout - oldStderr := os.Stderr - - rOut, wOut, _ := os.Pipe() - rErr, wErr, _ := os.Pipe() - - os.Stdout = wOut - os.Stderr = wErr - - // Run the function - f() - - // Restore - wOut.Close() - wErr.Close() - os.Stdout = oldStdout - os.Stderr = oldStderr - - stdout, _ := io.ReadAll(rOut) - stderr, _ := io.ReadAll(rErr) - - return string(stdout), string(stderr), nil -} - // Cleanup performs cleanup operations func (h *TestHelper) Cleanup() { if h.TempDir != "" { diff --git a/tests/mocks/exec_mock.go b/tests/mocks/exec_mock.go deleted file mode 100644 index 6847532..0000000 --- a/tests/mocks/exec_mock.go +++ /dev/null @@ -1,50 +0,0 @@ -// Package mocks provides mock implementations for testing the OrchCLI. -package mocks - -import ( - "os/exec" - - "github.com/stretchr/testify/mock" -) - -// CommandExecutor interface for mocking exec.Command -type CommandExecutor interface { - Command(name string, arg ...string) *exec.Cmd - LookPath(file string) (string, error) -} - -// MockCommandExecutor is a mock implementation -type MockCommandExecutor struct { - mock.Mock -} - -func (m *MockCommandExecutor) Command(name string, arg ...string) *exec.Cmd { - args := m.Called(name, arg) - return args.Get(0).(*exec.Cmd) -} - -func (m *MockCommandExecutor) LookPath(file string) (string, error) { - args := m.Called(file) - return args.String(0), args.Error(1) -} - -// MockCmd represents a mock command for testing -type MockCmd struct { - *exec.Cmd - mock.Mock -} - -func (m *MockCmd) Run() error { - args := m.Called() - return args.Error(0) -} - -func (m *MockCmd) Output() ([]byte, error) { - args := m.Called() - return args.Get(0).([]byte), args.Error(1) -} - -func (m *MockCmd) CombinedOutput() ([]byte, error) { - args := m.Called() - return args.Get(0).([]byte), args.Error(1) -} diff --git a/tests/unit/utils_test.go b/tests/unit/utils_test.go index 0c10883..92c71f2 100644 --- a/tests/unit/utils_test.go +++ b/tests/unit/utils_test.go @@ -96,53 +96,6 @@ func (suite *UtilsTestSuite) TestGetComposeFile() { } } -func (suite *UtilsTestSuite) TestValidateDockerCompose() { - // Test Docker Compose validation - // This would mock the docker compose check - - // Mock successful validation - mockCmd := func() error { - return nil - } - - err := mockCmd() - assert.NoError(suite.T(), err) - - // Mock failed validation - mockFailCmd := func() error { - return assert.AnError - } - - err = mockFailCmd() - assert.Error(suite.T(), err) -} - -func (suite *UtilsTestSuite) TestJoinArgs() { - // Test argument joining for shell commands - testCases := []struct { - expected string - args []string - }{ - { - expected: "arg1 arg2", - args: []string{"arg1", "arg2"}, - }, - { - expected: "'arg with spaces' arg2", - args: []string{"arg with spaces", "arg2"}, - }, - { - expected: "'arg'\"'\"'with'\"'\"'quotes' arg2", - args: []string{"arg'with'quotes", "arg2"}, - }, - } - - for _, tc := range testCases { - // This would test the actual joinArgs function - assert.NotEmpty(suite.T(), tc.expected) - } -} - func TestUtilsTestSuite(t *testing.T) { suite.Run(t, new(UtilsTestSuite)) }