Files
pipelines/internal/installation/installation_test.go
T

51 lines
1.5 KiB
Go

package installation
import (
"encoding/json"
"os"
"path/filepath"
"testing"
)
func TestCompiledCommandFindsManifestThroughSystemLink(t *testing.T) {
t.Setenv("PIPELINES_PREFIX", "")
root, _ := filepath.EvalSymlinks(t.TempDir())
os.Mkdir(filepath.Join(root, "bin"), 0700)
binary := filepath.Join(root, "bin/pipelines")
os.WriteFile(binary, []byte("binary"), 0700)
config := Config{Format: 1, Prefix: root, ServerPort: 18080, OpenCode: "/host/opencode", Path: "/usr/bin"}
data, _ := json.Marshal(config)
os.WriteFile(filepath.Join(root, "pipelines-install.json"), data, 0600)
link := filepath.Join(t.TempDir(), "pipelines")
os.Symlink(binary, link)
t.Setenv("PIPELINES_PREFIX", root)
loaded, err := Load(link)
if err != nil || loaded == nil || loaded.Prefix != root {
t.Fatal(loaded, err)
}
t.Setenv("PIPELINES_URL", "")
t.Setenv("PIPELINES_OPENCODE", "")
t.Setenv("PATH", os.Getenv("PATH"))
if err = loaded.Environment(); err != nil {
t.Fatal(err)
}
if os.Getenv("PIPELINES_URL") != "ws://127.0.0.1:18080/connect" {
t.Fatal("wrong installation selected")
}
t.Setenv("PIPELINES_URL", "ws://explicit/connect")
loaded.Environment()
if os.Getenv("PIPELINES_URL") != "ws://explicit/connect" {
t.Fatal("explicit server overridden")
}
}
func TestStandaloneGoInstalledCommandHasNoServiceDependency(t *testing.T) {
t.Setenv("PIPELINES_PREFIX", "")
binary := filepath.Join(t.TempDir(), "pipelines")
os.WriteFile(binary, []byte("binary"), 0700)
config, err := Load(binary)
if err != nil || config != nil {
t.Fatal(config, err)
}
}