MCPcopy
hub / github.com/baetyl/baetyl / TestRecycle

Function TestRecycle

engine/clean_test.go:20–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestRecycle(t *testing.T) {
21 f, err := os.CreateTemp("", t.Name())
22 assert.NoError(t, err)
23 assert.NotNil(t, f)
24 fmt.Println("-->tempfile", f.Name())
25
26 dir := t.TempDir()
27 fmt.Println("-->tempdir", dir)
28
29 sto, err := store.NewBoltHold(f.Name())
30 assert.NoError(t, err)
31 assert.NotNil(t, sto)
32
33 nod, err := node.NewNode(sto)
34 assert.NoError(t, err)
35 assert.NotNil(t, nod)
36
37 cfg1 := specv1.Configuration{Name: "cfg-meta-1", Version: "meta-1", Data: map[string]string{"_object_cfg1": "cfg1"}}
38 cfg2 := specv1.Configuration{Name: "cfg-meta-2", Version: "meta-2", Data: map[string]string{"_object_cfg2": "cfg2"}}
39 cfg3 := specv1.Configuration{Name: "cfg-3", Version: "3", Data: map[string]string{"cfg3": "cfg3"}}
40
41 path1 := filepath.Join(dir, cfg1.Name, cfg1.Version)
42 path2 := filepath.Join(dir, cfg2.Name, cfg2.Version)
43 os.MkdirAll(filepath.Join(dir, cfg1.Name, cfg1.Version), 0755)
44 os.MkdirAll(filepath.Join(dir, cfg2.Name, cfg2.Version), 0755)
45 assert.True(t, utils.DirExists(path1))
46 assert.True(t, utils.DirExists(path2))
47
48 key1 := makeKey(specv1.KindConfiguration, cfg1.Name, cfg1.Version)
49 key2 := makeKey(specv1.KindConfiguration, cfg2.Name, cfg2.Version)
50 key3 := makeKey(specv1.KindConfiguration, cfg3.Name, cfg3.Version)
51 sto.Upsert(key1, cfg1)
52 sto.Upsert(key2, cfg2)
53 sto.Upsert(key3, cfg3)
54
55 app := specv1.Application{Name: "app-1", Version: "1"}
56 vol := specv1.Volume{
57 Name: "cfg1",
58 VolumeSource: specv1.VolumeSource{
59 Config: &specv1.ObjectReference{Name: "cfg-meta-1", Version: "meta-1"},
60 },
61 }
62 app.Volumes = append(app.Volumes, vol)
63 appKey := makeKey(specv1.KindApplication, app.Name, app.Version)
64 sto.Upsert(appKey, app)
65
66 r := specv1.Report{}
67 info := specv1.AppInfo{Name: app.Name, Version: app.Version}
68 r.SetAppInfos(false, []specv1.AppInfo{info})
69 _, err = nod.Report(r, false)
70 assert.NoError(t, err)
71
72 var cfg config.Config
73 cfg.Sync.Download.Path = dir
74 e := engineImpl{sto: sto, nod: nod, cfg: cfg, log: log.With()}
75 err = e.recycle()
76 assert.NoError(t, err)
77

Callers

nothing calls this directly

Calls 6

ReportMethod · 0.95
recycleMethod · 0.95
NewBoltHoldFunction · 0.92
NewNodeFunction · 0.92
makeKeyFunction · 0.70
GetMethod · 0.65

Tested by

no test coverage detected