MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / getTestValkey

Function getTestValkey

lib/valkeycache/cache_test.go:33–76  ·  view source on GitHub ↗

nolint: exhaustruct // No need to use every option of 3rd party struct.

(t testing.TB)

Source from the content-addressed store, hash-verified

31
32// nolint: exhaustruct // No need to use every option of 3rd party struct.
33func getTestValkey(t testing.TB) *ValkeyDataCache[string, []byte] {
34 ctx := context.Background()
35 repoRoot, err := filepath.Abs(filepath.Join(".", "..", ".."))
36 if err != nil {
37 t.Error(err)
38 }
39 req := testcontainers.ContainerRequest{
40 FromDockerfile: testcontainers.FromDockerfile{
41 Dockerfile: filepath.Join(".dev", "valkey", "Dockerfile"),
42 Context: repoRoot,
43 },
44 ExposedPorts: []string{"6379/tcp"},
45 WaitingFor: wait.ForLog("Ready to accept connections"),
46 Name: "webstatus-dev-test-valkey",
47 }
48 container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
49 ContainerRequest: req,
50 Started: true,
51 })
52 if err != nil {
53 t.Error(err)
54 }
55
56 mappedPort, err := container.MappedPort(ctx, "6379")
57 if err != nil {
58 t.Error(err)
59 }
60
61 cache, err := NewValkeyDataCache[string, []byte](
62 "testPrefix",
63 "localhost",
64 mappedPort.Port(),
65 getDefatulTTL(),
66 )
67 if err != nil {
68 t.Error(err)
69 }
70
71 t.Cleanup(func() {
72 cache.client.Close()
73 })
74
75 return cache
76}
77
78func TestValkeyDataCache(t *testing.T) {
79 cache := getTestValkey(t)

Callers 1

TestValkeyDataCacheFunction · 0.85

Calls 4

NewValkeyDataCacheFunction · 0.85
getDefatulTTLFunction · 0.85
ErrorMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected