MCPcopy Index your code
hub / github.com/FunctionStream/function-stream / TestFunctionStoreLoading

Function TestFunctionStoreLoading

server/function_store_test.go:103–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

101const yamlSeparator string = "---\n"
102
103func TestFunctionStoreLoading(t *testing.T) {
104 tmpfile, err := os.CreateTemp("", "*.yaml")
105 assert.Nil(t, err)
106 //defer os.Remove(tmpfile.Name())
107
108 fm := newTestFunctionManagerImpl()
109 functionStore, err := NewFunctionStoreImpl(fm, tmpfile.Name())
110 assert.Nil(t, err)
111
112 f1 := createTestFunction("f1")
113
114 f1Data, err := yaml.Marshal(&f1)
115 assert.Nil(t, err)
116
117 _, err = tmpfile.Write(f1Data)
118 assert.Nil(t, err)
119
120 assert.Nil(t, functionStore.Load())
121
122 assert.Len(t, fm.(*testFunctionManagerImpl).functions, 1)
123 assert.Equal(t, f1, fm.(*testFunctionManagerImpl).functions[fs.GetNamespacedName("", "f1")])
124
125 f2 := createTestFunction("f2")
126 _, err = tmpfile.WriteString(yamlSeparator)
127 assert.Nil(t, err)
128 f2Data, err := yaml.Marshal(f2)
129 assert.Nil(t, err)
130 _, err = tmpfile.Write(f2Data)
131 assert.Nil(t, err)
132
133 assert.Nil(t, functionStore.Load())
134 assert.Len(t, fm.(*testFunctionManagerImpl).functions, 2)
135 assert.Equal(t, f1, fm.(*testFunctionManagerImpl).functions[fs.GetNamespacedName("", "f1")])
136 assert.Equal(t, f2, fm.(*testFunctionManagerImpl).functions[fs.GetNamespacedName("", "f2")])
137
138 assert.Nil(t, tmpfile.Close())
139
140 tmpfile, err = os.Create(tmpfile.Name()) // Overwrite the file
141 assert.Nil(t, err)
142
143 _, err = tmpfile.Write(f2Data)
144 assert.Nil(t, err)
145
146 assert.Nil(t, functionStore.Load())
147 assert.Len(t, fm.(*testFunctionManagerImpl).functions, 1)
148 assert.Equal(t, f2, fm.(*testFunctionManagerImpl).functions[fs.GetNamespacedName("", "f2")])
149}

Callers

nothing calls this directly

Calls 7

LoadMethod · 0.95
GetNamespacedNameFunction · 0.92
NewFunctionStoreImplFunction · 0.85
createTestFunctionFunction · 0.85
CloseMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected