MCPcopy
hub / github.com/redspread/spread / TestSourceContainersDir

Function TestSourceContainersDir

pkg/input/dir/source_test.go:273–313  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

271}
272
273func TestSourceContainersDir(t *testing.T) {
274 fs := testTempFileSource(t)
275 defer os.RemoveAll(string(fs))
276
277 expected := []*entity.Container{}
278
279 for i := 0; i < 15+rand.Intn(100); i++ {
280 name := randomString(8)
281
282 kubeContainer := kube.Container{
283 Name: name,
284 Image: randomString(6),
285 ImagePullPolicy: kube.PullAlways,
286 }
287 filename := path.Join(string(fs), name+ContainerExtension)
288
289 container, err := entity.NewContainer(kubeContainer, kube.ObjectMeta{}, filename)
290 assert.NoError(t, err)
291
292 expected = append(expected, container)
293
294 testWriteYAMLToFile(t, filename, &kubeContainer)
295 }
296
297 actual, err := fs.Entities(entity.EntityContainer)
298 assert.NoError(t, err, "should be okay")
299 assert.Len(t, actual, len(expected), "should have same number of containers as start")
300
301 for _, expectedContainer := range expected {
302 found := false
303 for _, actualContainer := range actual {
304 if expectedContainer.Source() == actualContainer.Source() {
305 found = testCompareEntity(t, expectedContainer, actualContainer)
306 if found {
307 break
308 }
309 }
310 }
311 assert.True(t, found, "should have found container")
312 }
313}
314
315// TODO: Add test for file
316

Callers

nothing calls this directly

Calls 7

testTempFileSourceFunction · 0.85
testWriteYAMLToFileFunction · 0.85
testCompareEntityFunction · 0.85
EntitiesMethod · 0.80
randomStringFunction · 0.70
SourceMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected