aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/matching_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/krino/matching_test.go')
-rw-r--r--cmd/krino/matching_test.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/cmd/krino/matching_test.go b/cmd/krino/matching_test.go
index 4ce2205..6bdc994 100644
--- a/cmd/krino/matching_test.go
+++ b/cmd/krino/matching_test.go
@@ -4,13 +4,15 @@ package main
import (
"bytes"
+ "context"
"encoding/json"
- "fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"
+
+ "git.labunix.xyz/krino/internal/lock"
)
const dlRules = `
@@ -412,13 +414,13 @@ func TestRefusesWithoutTerminalAndWithoutFlags(t *testing.T) {
func TestSecondRunFailsImmediatelyWithYes(t *testing.T) {
h := matchingFixture(t)
held := filepath.Join(h, ".local", "state", "krino", "dl.lock")
- if err := os.MkdirAll(filepath.Dir(held), 0o755); err != nil {
- t.Fatal(err)
- }
- // A lock held by this very process, so it is not stale.
- if err := os.WriteFile(held, []byte(fmt.Sprintf("pid %d\n", os.Getpid())), 0o644); err != nil {
+ // A lock really held: it is the kernel's, so a file that merely looks
+ // like one holds nothing.
+ l, err := lock.Acquire(context.Background(), held, false)
+ if err != nil {
t.Fatal(err)
}
+ defer l.Release()
code, _, errOut := runCLI(t, "-y")
if code != 1 || !strings.Contains(errOut, "another krino") {
t.Errorf("-y against a held lock: %d %q", code, errOut)