MCPcopy
hub / github.com/caddyserver/certmagic / TestFileStorageWriteLock

Function TestFileStorageWriteLock

filestorage_test.go:52–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func 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}

Callers

nothing calls this directly

Calls 4

LockMethod · 0.95
UnlockMethod · 0.95
RequireNoErrorFunction · 0.92
RequireErrorFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…