MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestWriteAndReadUserIndex

Function TestWriteAndReadUserIndex

pkg/util/users/index_test.go:16–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestWriteAndReadUserIndex(t *testing.T) {
17 t.Parallel()
18
19 ctx := context.Background()
20 bkt, _ := cortex_testutil.PrepareFilesystemBucket(t)
21
22 // Create a test index
23 now := time.Now()
24 idx := &UserIndex{
25 Version: userIndexVersion,
26 UpdatedAt: now.Unix(),
27 ActiveUsers: []string{"user-1", "user-2"},
28 DeletingUsers: []string{"user-3"},
29 DeletedUsers: []string{"user-4"},
30 }
31
32 // Test writing the index
33 err := WriteUserIndex(ctx, bkt, idx)
34 require.NoError(t, err)
35
36 // Verify the index was written with the correct filename
37 _, err = bkt.Get(ctx, UserIndexFilename)
38 require.Error(t, err)
39 require.True(t, bkt.IsObjNotFoundErr(err))
40
41 // Test reading the index
42 readIdx, err := ReadUserIndex(ctx, bkt, log.NewNopLogger())
43 require.NoError(t, err)
44 require.NotNil(t, readIdx)
45
46 // Verify the read index matches the written one
47 assert.Equal(t, idx.Version, readIdx.Version)
48 assert.Equal(t, idx.UpdatedAt, readIdx.UpdatedAt)
49 assert.Equal(t, idx.ActiveUsers, readIdx.ActiveUsers)
50 assert.Equal(t, idx.DeletingUsers, readIdx.DeletingUsers)
51 assert.Equal(t, idx.DeletedUsers, readIdx.DeletedUsers)
52}
53
54func TestReadUserIndex_NotFound(t *testing.T) {
55 t.Parallel()

Callers

nothing calls this directly

Calls 6

WriteUserIndexFunction · 0.85
ReadUserIndexFunction · 0.85
GetMethod · 0.65
EqualMethod · 0.65
ErrorMethod · 0.45
IsObjNotFoundErrMethod · 0.45

Tested by

no test coverage detected