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>
		
			
				
	
	
		
			31 lines
		
	
	
		
			607 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			31 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]
 | 
						|
	}
 | 
						|
}
 |