| 1 | //go:build darwin |
| 2 | |
| 3 | package filelock |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "path/filepath" |
| 8 | "strings" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | func TestCanonicalLockPathKeepsLegacyDarwinCase(t *testing.T) { |
| 13 | path := filepath.Join(t.TempDir(), "MixedCase.lock") |
| 14 | got, err := canonicalLockPath(path) |
| 15 | if err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | if !strings.Contains(got, "MixedCase.lock") { |
| 19 | t.Fatalf("canonical lock path = %q, want exact legacy case", got) |
| 20 | } |
| 21 | alias := filepath.Join(filepath.Dir(got), "mixedcase.lock") |
| 22 | release, err := TryAcquireModeWithKey(got, strings.ToLower(got), ModeExclusive) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | defer release() |
| 27 | if aliasRelease, err := TryAcquireModeWithKey(alias, strings.ToLower(alias), ModeExclusive); !errors.Is(err, ErrHeld) { |
| 28 | if aliasRelease != nil { |
| 29 | aliasRelease() |
| 30 | } |
| 31 | t.Fatalf("local registry did not share explicit alias identity: %q / %q: %v", got, alias, err) |
| 32 | } |
| 33 | } |
| 34 |