MCPcopy Index your code
hub / github.com/coder/coder / TestEntry

Function TestEntry

coderd/runtimeconfig/entry_test.go:14–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestEntry(t *testing.T) {
15 t.Parallel()
16
17 t.Run("new", func(t *testing.T) {
18 t.Parallel()
19
20 require.Panics(t, func() {
21 // No name should panic
22 runtimeconfig.MustNew[*serpent.Float64]("")
23 })
24
25 require.NotPanics(t, func() {
26 runtimeconfig.MustNew[*serpent.Float64]("my-field")
27 })
28 })
29
30 t.Run("simple", func(t *testing.T) {
31 t.Parallel()
32
33 ctx := testutil.Context(t, testutil.WaitShort)
34 mgr := runtimeconfig.NewManager()
35 db, _ := dbtestutil.NewDB(t)
36
37 override := serpent.String("dogfood@dev.coder.com")
38
39 field := runtimeconfig.MustNew[*serpent.String]("string-field")
40
41 // No value set yet.
42 _, err := field.Resolve(ctx, mgr.Resolver(db))
43 require.ErrorIs(t, err, runtimeconfig.ErrEntryNotFound)
44 // Set an org-level override.
45 require.NoError(t, field.SetRuntimeValue(ctx, mgr.Resolver(db), &override))
46 // Value was updated
47 val, err := field.Resolve(ctx, mgr.Resolver(db))
48 require.NoError(t, err)
49 require.Equal(t, override.String(), val.String())
50 })
51
52 t.Run("complex", func(t *testing.T) {
53 t.Parallel()
54
55 ctx := testutil.Context(t, testutil.WaitShort)
56 mgr := runtimeconfig.NewManager()
57 db, _ := dbtestutil.NewDB(t)
58
59 override := serpent.Struct[map[string]string]{
60 Value: map[string]string{
61 "a": "b",
62 "c": "d",
63 },
64 }
65
66 field := runtimeconfig.MustNew[*serpent.Struct[map[string]string]]("string-field")
67 // Validate that there is no runtime override right now.
68 _, err := field.Resolve(ctx, mgr.Resolver(db))
69 require.ErrorIs(t, err, runtimeconfig.ErrEntryNotFound)
70 // Set a runtime value
71 require.NoError(t, field.SetRuntimeValue(ctx, mgr.Resolver(db), &override))

Callers

nothing calls this directly

Calls 9

ResolverMethod · 0.95
ContextFunction · 0.92
NewManagerFunction · 0.92
NewDBFunction · 0.92
SetRuntimeValueMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45
ResolveMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected