(t *testing.T)
| 50 | } |
| 51 | |
| 52 | func TestFileStorageWriteLock(t *testing.T) { |
| 53 | ctx := context.Background() |
| 54 | tmpDir, err := os.MkdirTemp(os.TempDir(), "certmagic*") |
| 55 | testutil.RequireNoError(t, err, "allocating tmp dir") |
| 56 | defer os.RemoveAll(tmpDir) |
| 57 | s := &certmagic.FileStorage{ |
| 58 | Path: tmpDir, |
| 59 | } |
| 60 | // cctx is a cancelled ctx. so if we can't immediately get the lock, it will fail |
| 61 | cctx, cn := context.WithCancel(ctx) |
| 62 | cn() |
| 63 | // should success |
| 64 | err = s.Lock(cctx, "foo") |
| 65 | testutil.RequireNoError(t, err) |
| 66 | // should fail |
| 67 | err = s.Lock(cctx, "foo") |
| 68 | testutil.RequireError(t, err) |
| 69 | |
| 70 | err = s.Unlock(cctx, "foo") |
| 71 | testutil.RequireNoError(t, err) |
| 72 | // shouldn't fail |
| 73 | err = s.Lock(cctx, "foo") |
| 74 | testutil.RequireNoError(t, err) |
| 75 | |
| 76 | err = s.Unlock(cctx, "foo") |
| 77 | testutil.RequireNoError(t, err) |
| 78 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…