cli/pkg/repos/workspace_test.go
Snider 699c0933f6
fix(docs): respect workspace.yaml packages_dir setting (fixes #46) (#55)
* fix(docs): respect workspace.yaml packages_dir setting (fixes #46)

* fix(workspace): improve config loading logic (CR feedback)

- Expand ~ before resolving relative paths in cmd_registry
- Handle LoadWorkspaceConfig errors properly
- Update Repo.Path when PackagesDir overrides default
- Validate workspace config version
- Add unit tests for workspace config loading

* docs: add comments and increase test coverage (CR feedback)

- Add docstrings to exported functions in pkg/cli
- Add unit tests for Semantic Output (pkg/cli/output.go)
- Add unit tests for CheckBuilder (pkg/cli/check.go)
- Add unit tests for IPC Query/Perform (pkg/framework/core)

* fix(test): fix panics and failures in php package tests

- Fix panic in TestLookupLinuxKit_Bad by mocking paths
- Fix assertion errors in TestGetSSLDir_Bad and TestGetPackageInfo_Bad
- Fix formatting in test files

* fix(test): correct syntax in services_extended_test.go

* fix(ci): point coverage workflow to go.mod instead of go.work

* fix(ci): build CLI before running coverage

* fix(ci): run go generate for updater package in coverage workflow

* fix(github): allow dry-run publish without gh CLI authentication

Moves validation check after dry-run check so tests can verify dry-run behavior in CI environments.
2026-02-01 01:59:27 +00:00

56 lines
1.3 KiB
Go

package repos
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadWorkspaceConfig_Good(t *testing.T) {
// Setup temp dir
tmpDir := t.TempDir()
coreDir := filepath.Join(tmpDir, ".core")
err := os.MkdirAll(coreDir, 0755)
assert.NoError(t, err)
// Write valid config
configContent := `
version: 1
active: core-php
packages_dir: ./custom-packages
`
err = os.WriteFile(filepath.Join(coreDir, "workspace.yaml"), []byte(configContent), 0644)
assert.NoError(t, err)
// Load
cfg, err := LoadWorkspaceConfig(tmpDir)
assert.NoError(t, err)
assert.Equal(t, 1, cfg.Version)
assert.Equal(t, "core-php", cfg.Active)
assert.Equal(t, "./custom-packages", cfg.PackagesDir)
}
func TestLoadWorkspaceConfig_Default(t *testing.T) {
tmpDir := t.TempDir()
// Load non-existent
cfg, err := LoadWorkspaceConfig(tmpDir)
assert.NoError(t, err)
assert.Equal(t, 1, cfg.Version)
assert.Equal(t, "./packages", cfg.PackagesDir)
}
func TestLoadWorkspaceConfig_BadVersion(t *testing.T) {
tmpDir := t.TempDir()
coreDir := filepath.Join(tmpDir, ".core")
os.MkdirAll(coreDir, 0755)
configContent := `version: 2`
os.WriteFile(filepath.Join(coreDir, "workspace.yaml"), []byte(configContent), 0644)
_, err := LoadWorkspaceConfig(tmpDir)
assert.Error(t, err)
assert.Contains(t, err.Error(), "unsupported workspace config version")
}