package nix_test import ( "testing" "gensokyo.uk/nix" ) func TestLocal(t *testing.T) { if got := nix.Local("/").String(); got != "/" { t.Errorf("String: %v, want %v", got, "/") } if got := nix.Local("").Environ(); got != nil { t.Errorf("Environ: %v, want %v", got, nil) } } func TestBinaryCache(t *testing.T) { testCases := []struct { name string store *nix.BinaryCache want string wantEnv []string }{ {"example", &nix.BinaryCache{ Compression: "none", ParallelCompression: false, Bucket: "example", Endpoint: "s3.example.org", Region: "us-east-1", Scheme: "http", CredentialsPath: "/dev/null", KeyPath: nonexistent, }, "s3://example?compression=none¶llel-compression=false®ion=us-east-1&scheme=http&endpoint=s3.example.org&secret-key=/proc/nonexistent", []string{nix.EnvAwsSharedCredentialsFile + "=/dev/null"}}, {"gensokyo", &nix.BinaryCache{ Compression: "zstd", ParallelCompression: true, Bucket: "nix-cache", Endpoint: "s3.gensokyo.uk", Region: "ap-northeast-1", Scheme: "https", CredentialsPath: "/var/lib/persist/cache/s3", KeyPath: "/var/lib/persist/cache/key", }, "s3://nix-cache?compression=zstd¶llel-compression=true®ion=ap-northeast-1&scheme=https&endpoint=s3.gensokyo.uk&secret-key=/var/lib/persist/cache/key", []string{nix.EnvAwsSharedCredentialsFile + "=/var/lib/persist/cache/s3"}}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { if got := tc.store.String(); got != tc.want { t.Errorf("String: %q, want %q", got, tc.want) } }) } }