package docker //nolint:testpackage // tests unexported buildAuthConfigs import ( "testing" ) func TestBuildAuthConfigsEmpty(t *testing.T) { t.Parallel() result := buildAuthConfigs(nil) if len(result) != 0 { t.Errorf("expected empty map, got %d entries", len(result)) } } func TestBuildAuthConfigsSingle(t *testing.T) { t.Parallel() auths := []RegistryAuth{ { Registry: "registry.example.com", Username: "user", Password: "pass", }, } result := buildAuthConfigs(auths) if len(result) != 1 { t.Fatalf("expected 1 entry, got %d", len(result)) } cfg, ok := result["registry.example.com"] if !ok { t.Fatal("expected registry.example.com key") } if cfg.Username != "user" { t.Errorf("expected username 'user', got %q", cfg.Username) } if cfg.Password != "pass" { t.Errorf("expected password 'pass', got %q", cfg.Password) } if cfg.ServerAddress != "registry.example.com" { t.Errorf("expected server address 'registry.example.com', got %q", cfg.ServerAddress) } } func TestBuildAuthConfigsMultiple(t *testing.T) { t.Parallel() auths := []RegistryAuth{ {Registry: "ghcr.io", Username: "ghuser", Password: "ghtoken"}, {Registry: "docker.io", Username: "dkuser", Password: "dktoken"}, } result := buildAuthConfigs(auths) if len(result) != 2 { t.Fatalf("expected 2 entries, got %d", len(result)) } ghcr := result["ghcr.io"] if ghcr.Username != "ghuser" || ghcr.Password != "ghtoken" { t.Errorf("unexpected ghcr.io config: %+v", ghcr) } dkr := result["docker.io"] if dkr.Username != "dkuser" || dkr.Password != "dktoken" { t.Errorf("unexpected docker.io config: %+v", dkr) } } func TestRegistryAuthStruct(t *testing.T) { t.Parallel() auth := RegistryAuth{ Registry: "registry.example.com", Username: "testuser", Password: "testpass", } if auth.Registry != "registry.example.com" { t.Errorf("expected registry 'registry.example.com', got %q", auth.Registry) } if auth.Username != "testuser" { t.Errorf("expected username 'testuser', got %q", auth.Username) } if auth.Password != "testpass" { t.Errorf("expected password 'testpass', got %q", auth.Password) } }