MCPcopy Create free account
hub / github.com/conforma/cli / TestGet

Function TestGet

internal/policy/cache/cache_test.go:29–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestGet(t *testing.T) {
30 ctx := context.Background()
31
32 tests := []struct {
33 name string
34 setupCache func(*PolicyCache)
35 key string
36 expectedValue string
37 expectedFound bool
38 }{
39 {
40 name: "key does not exist",
41 setupCache: func(c *PolicyCache) {},
42 key: "nonexistent",
43 expectedValue: "",
44 expectedFound: false,
45 },
46 {
47 name: "key exists with valid value",
48 setupCache: func(c *PolicyCache) {
49 c.Set("existing", "value", nil)
50 },
51 key: "existing",
52 expectedValue: "value",
53 expectedFound: true,
54 },
55 {
56 name: "key exists but with wrong type",
57 setupCache: func(c *PolicyCache) {
58 c.Data.Store("wrongtype", "string value")
59 },
60 key: "wrongtype",
61 expectedValue: "",
62 expectedFound: false,
63 },
64 {
65 name: "empty key with value",
66 setupCache: func(c *PolicyCache) {
67 c.Set("", "emptykeyvalue", nil)
68 },
69 key: "",
70 expectedValue: "emptykeyvalue",
71 expectedFound: true,
72 },
73 {
74 name: "key with error",
75 setupCache: func(c *PolicyCache) {
76 c.Set("errorkey", "errorvalue", errors.New("test error"))
77 },
78 key: "errorkey",
79 expectedValue: "errorvalue",
80 expectedFound: true,
81 },
82 {
83 name: "key with empty value",
84 setupCache: func(c *PolicyCache) {
85 c.Set("emptyvalue", "", nil)
86 },

Callers

nothing calls this directly

Calls 4

GetMethod · 0.95
NewPolicyCacheFunction · 0.85
RunMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected