1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package kvstore_test
4
5import (
6 "context"
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/require"
11
12 "bnema.dev/ermite/internal/domain"
13)
14
15func TestDeleteRefTipIfOnlyRemovesTheMatchingRecord(t *testing.T) {
16 ctx := context.Background()
17 s := openStore(t, t.TempDir())
18 n := name(t, "proj")
19 require.NoError(t, s.Create(ctx, domain.Repo{Name: n, Visibility: domain.VisibilityPrivate, CreatedAt: created}))
20 ci := s.CI()
21 ref := "refs/heads/feat"
22
23 require.NoError(t, ci.PutRefTip(ctx, domain.CIRefTip{Repo: n, Ref: ref, Sha: "aaa", Actor: "ada"}))
24 require.NoError(t, ci.DeleteRefTipIf(ctx, n, ref, "bbb"))
25 got, err := ci.GetRefTip(ctx, n, ref)
26 require.NoError(t, err)
27 assert.Equal(t, "aaa", got.Sha, "a record of another object stays")
28
29 require.NoError(t, ci.DeleteRefTipIf(ctx, n, ref, "aaa"))
30 _, err = ci.GetRefTip(ctx, n, ref)
31 assert.ErrorIs(t, err, domain.ErrNotFound)
32
33 require.NoError(t, ci.DeleteRefTipIf(ctx, n, ref, "aaa"), "a missing record is not an error")
34}