Release v0.2.0
This commit is contained in:
parent
f0e29d38a4
commit
c24af42fc0
9 changed files with 153 additions and 6 deletions
|
|
@ -4,6 +4,8 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
)
|
||||
|
||||
func TestLoadValidConfig(t *testing.T) {
|
||||
|
|
@ -192,6 +194,65 @@ func TestMissingRequiredFields(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLoadUsesNixCacheLoginConfigEnvWhenPathEmpty(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
cfgFile := filepath.Join(dir, "custom-config.toml")
|
||||
|
||||
content := `
|
||||
issuer = "https://id.example.com/realms/test"
|
||||
client_id = "nix-cache-server"
|
||||
cache_host = "cache.example.com"
|
||||
netrc_path = "/tmp/netrc"
|
||||
`
|
||||
if err := os.WriteFile(cfgFile, []byte(content), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Setenv(configPathEnvVar, cfgFile)
|
||||
cfg, err := Load("")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if cfg.ClientID != "nix-cache-server" {
|
||||
t.Fatalf("client_id = %q, want %q", cfg.ClientID, "nix-cache-server")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFallsBackToSystemConfigPath(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
systemCfg := filepath.Join(dir, "system-config.toml")
|
||||
systemConfigPathOrig := systemConfigPath
|
||||
systemConfigPath = systemCfg
|
||||
defer func() {
|
||||
systemConfigPath = systemConfigPathOrig
|
||||
}()
|
||||
|
||||
content := `
|
||||
issuer = "https://id.example.com/realms/test"
|
||||
client_id = "nix-cache-server"
|
||||
cache_host = "cache.example.com"
|
||||
netrc_path = "/tmp/netrc"
|
||||
`
|
||||
if err := os.WriteFile(systemCfg, []byte(content), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Setenv(configPathEnvVar, "")
|
||||
origConfigHome := xdg.ConfigHome
|
||||
xdg.ConfigHome = filepath.Join(dir, "xdg-missing")
|
||||
defer func() {
|
||||
xdg.ConfigHome = origConfigHome
|
||||
}()
|
||||
|
||||
cfg, err := Load("")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if cfg.ClientID != "nix-cache-server" {
|
||||
t.Fatalf("client_id = %q, want %q", cfg.ClientID, "nix-cache-server")
|
||||
}
|
||||
}
|
||||
|
||||
func contains(s, substr string) bool {
|
||||
return len(s) >= len(substr) && searchString(s, substr)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue