Skip to content

Commit

Permalink
test: move UUID mapping manager test to the right place
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik authored and hperl committed Jan 17, 2022
1 parent dc2fc54 commit bd9b2e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
7 changes: 7 additions & 0 deletions internal/persistence/sql/full_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"testing"

"github.com/ory/keto/internal/uuidmapping"

"github.com/gofrs/uuid"

"github.com/ory/keto/internal/x/dbx"
Expand Down Expand Up @@ -66,6 +68,11 @@ func TestPersister(t *testing.T) {
// same registry, but different persisters only differing in the network ID
relationtuple.IsolationTest(t, p0, p1, addNamespace(r, nspaces))
})

t.Run("uuidmapping.ManagerTest", func(t *testing.T) {
p, _, _ := setup(t, dsn)
uuidmapping.ManagerTest(t, p)
})
})
}
}
10 changes: 0 additions & 10 deletions internal/persistence/sql/migrations/single_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strconv"
"testing"

"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -97,15 +96,6 @@ func TestToSingleTableMigrator(t *testing.T) {
assert.Equal(t, sSet, rts[1])
})

t.Run("case=uuid mapping", func(t *testing.T) {
id := uuid.Must(uuid.NewV4())
rep1 := "foo"
require.NoError(t, r.UUIDMappingManager().AddUUIDMapping(ctx, id, rep1))
rep2, err := r.UUIDMappingManager().LookupUUID(ctx, id)
assert.NoError(t, err)
assert.Equal(t, rep1, rep2)
})

t.Run("case=paginates", func(t *testing.T) {
n := setup(t)

Expand Down
16 changes: 16 additions & 0 deletions internal/uuidmapping/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package uuidmapping

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/gofrs/uuid"
)
Expand All @@ -15,3 +19,15 @@ type (
LookupUUID(ctx context.Context, id uuid.UUID) (rep string, err error)
}
)

func ManagerTest(t *testing.T, m Manager) {
ctx := context.Background()

id := uuid.Must(uuid.NewV4())
rep1 := "foo"
require.NoError(t, m.AddUUIDMapping(ctx, id, rep1))

rep2, err := m.LookupUUID(ctx, id)
assert.NoError(t, err)
assert.Equal(t, rep1, rep2)
}

0 comments on commit bd9b2e0

Please sign in to comment.