containerd/gc/gc_test.go
Stephen J Day b542cc19ad
gc: add toy tri-color GC implementation
As a minimum, we would like to maintain generic garbage collection of
containerd resources. This includes images, bundles, containers and
arbitrary content.

The included implementation is just a textbook toy that we can use to
inform the requirements of gc. It implements a simple, stack-based
tricolor algorithm. Nothing special.

Mostly, this is to ensure we think about garbage collection from the
start, rather than as an afterthought or follow on feature.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2016-12-06 16:20:40 -08:00

30 lines
607 B
Go

package gc
import (
"reflect"
"testing"
)
func TestTricolorBasic(t *testing.T) {
roots := []string{"A", "C"}
all := []string{"A", "B", "C", "D", "E", "F", "G"}
refs := map[string][]string{
"A": {"B"},
"B": {"A"},
"C": {"D", "F", "B"},
"E": {"F", "G"},
}
unreachable := Tricolor(roots, all, lookup(refs))
expected := []string{"E", "G"}
if !reflect.DeepEqual(unreachable, expected) {
t.Fatalf("incorrect unreachable set: %v != %v", unreachable, expected)
}
}
func lookup(refs map[string][]string) func(id string) []string {
return func(ref string) []string {
return refs[ref]
}
}