Example #1
0
func fmtDir() {
	if len(os.Args) != 2 {
		help()
		os.Exit(1)
	}

	err := storedir.CreateDirectory(os.Args[1])
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(1)
	}
}
Example #2
0
func TestHandlerBasics(t *testing.T) {
	tmpdir, err := ioutil.TempDir("", "")
	if err != nil {
		t.Fatalf("Couldn't create temporary directory: %v", err)
	}
	defer os.RemoveAll(tmpdir)

	err = storedir.CreateDirectory(tmpdir)
	if err != nil {
		t.Fatalf("Couldn't initialize directory store in %v: %v", tmpdir, err)
	}

	uuidBytes, err := ioutil.ReadFile(filepath.Join(tmpdir, "uuid"))
	if err != nil {
		t.Fatalf("Couldn't read uuid file: %v", err)
	}
	uuid := string(uuidBytes)

	ds, err := storedir.OpenDirectory(tmpdir, 0, 0)
	if err != nil {
		t.Fatalf("Couldn't OpenDirectory %v: %v", tmpdir, err)
	}
	defer ds.Close()

	h, err := New([]store.Store{ds})
	if err != nil {
		t.Fatalf("Couldn't create Handler: %v", err)
	}
	defer h.Close()

	h.WaitAllAvailable()

	shouldRespond(t, h, "GET", "/", "",
		200, "Howdy, slime chunk server here!\n")

	shouldRespond(t, h, "GET", "/uuids", "", 200, uuid+"\n")
	shouldRespond(t, h, "GET", "/"+uuid+"/?mode=list", "", 200, "")

	shouldRespond(t, h, "PUT", "/"+uuid+"/file", "contents", 204, "")
	shouldRespond(t, h, "GET", "/"+uuid+"/file", "", 200, "contents")
	shouldRespond(t, h, "GET", "/"+uuid+"/?mode=list", "", 200, "file\n")

	shouldRespond(t, h, "DELETE", "/"+uuid+"/file", "", 204, "")
	shouldRespond(t, h, "GET", "/"+uuid+"/file", "", 404, "not found\n")
	shouldRespond(t, h, "DELETE", "/"+uuid+"/file", "", 404, "not found\n")
	shouldRespond(t, h, "GET", "/"+uuid+"/?mode=list", "", 200, "")

	shouldRespond(t, h, "PUT", "/"+uuid+"/z", "z", 204, "")
	shouldRespond(t, h, "PUT", "/"+uuid+"/y", "y", 204, "")
	shouldRespond(t, h, "PUT", "/"+uuid+"/a", "a", 204, "")
	shouldRespond(t, h, "PUT", "/"+uuid+"/c", "c", 204, "")
	shouldRespond(t, h, "PUT", "/"+uuid+"/x", "x", 204, "")
	shouldRespond(t, h, "PUT", "/"+uuid+"/b", "b", 204, "")
	shouldRespond(t, h, "GET", "/"+uuid+"/?mode=list", "",
		200, "a\nb\nc\nx\ny\nz\n")
	shouldRespond(t, h, "GET", "/"+uuid+"/?mode=list&limit=3", "",
		200, "a\nb\nc\n")
	shouldRespond(t, h, "GET", "/"+uuid+"/?mode=list&limit=2&after=b", "",
		200, "c\nx\n")
	shouldRespond(t, h, "GET", "/"+uuid+"/?mode=list&limit=3&after=y", "",
		200, "z\n")

	shouldRespondInteger(t, h, "GET", "/"+uuid+"/?mode=free", 200)
}