Пример #1
0
func repoInfoHandler(c web.C, w http.ResponseWriter, r *http.Request) {
	uuid := (c.Env["uuid"]).(dvid.UUID)
	jsonStr, err := datastore.GetRepoJSON(uuid)
	if err != nil {
		BadRequest(w, r, err)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintf(w, jsonStr)
}
Пример #2
0
func TestCommitBranchMergeDelete(t *testing.T) {
	datastore.OpenTest()
	defer datastore.CloseTest()

	uuid := createRepo(t)

	// Shouldn't be able to create branch on open node.
	branchReq := fmt.Sprintf("%snode/%s/branch", WebAPIPath, uuid)
	TestBadHTTP(t, "POST", branchReq, nil)

	// Commit it.
	payload := bytes.NewBufferString(`{"note": "This is my test commit", "log": ["line1", "line2", "some more stuff in a line"]}`)
	apiStr := fmt.Sprintf("%snode/%s/commit", WebAPIPath, uuid)
	TestHTTP(t, "POST", apiStr, payload)

	// Make sure committed nodes can only be read.
	// We shouldn't be able to write to log.
	payload = bytes.NewBufferString(`{"log": ["line1", "line2", "some more stuff in a line"]}`)
	apiStr = fmt.Sprintf("%snode/%s/log", WebAPIPath, uuid)
	TestBadHTTP(t, "POST", apiStr, payload)

	// Should be able to create branch now that we've committed parent.
	respData := TestHTTP(t, "POST", branchReq, nil)
	resp := struct {
		Child string `json:"child"`
	}{}
	if err := json.Unmarshal(respData, &resp); err != nil {
		t.Errorf("Expected 'child' JSON response.  Got %s\n", string(respData))
	}
	parent1 := dvid.UUID(resp.Child)

	// Create a sibling.
	respData = TestHTTP(t, "POST", branchReq, nil)
	if err := json.Unmarshal(respData, &resp); err != nil {
		t.Errorf("Expected 'child' JSON response.  Got %s\n", string(respData))
	}
	parent2 := dvid.UUID(resp.Child)

	// Commit both parents
	payload = bytes.NewBufferString(`{"note": "This is first parent"}`)
	apiStr = fmt.Sprintf("%snode/%s/commit", WebAPIPath, parent1)
	TestHTTP(t, "POST", apiStr, payload)

	payload = bytes.NewBufferString(`{"note": "This is second parent"}`)
	apiStr = fmt.Sprintf("%snode/%s/commit", WebAPIPath, parent2)
	TestHTTP(t, "POST", apiStr, payload)

	// Merge the two disjoint branches.
	mergeJSON := fmt.Sprintf(`{"mergeType": "conflict-free", "note": "This is my merged node", "parents": [%q, %q]}`, parent1[:7], parent2)
	payload = bytes.NewBufferString(mergeJSON)
	apiStr = fmt.Sprintf("%srepo/%s/merge", WebAPIPath, parent1)
	TestHTTP(t, "POST", apiStr, payload)

	// Get root version to check after delete repo.
	rootV, err := datastore.VersionFromUUID(uuid)
	if err != nil {
		t.Errorf("Got unexpected error on getting version from root UUID: %v\n", err)
	}

	// Delete the entire repo including all branches.
	apiStr = fmt.Sprintf("%srepo/%s", WebAPIPath, parent2)
	TestBadHTTP(t, "DELETE", apiStr, nil) // Requires query string
	apiStr = fmt.Sprintf("%srepo/%s?imsure=true", WebAPIPath, parent2)
	TestHTTP(t, "DELETE", apiStr, nil) // Requires query string

	// Make sure none of the repo is still accessible.
	jsonResp, err := datastore.GetRepoJSON(uuid)
	if err == nil {
		t.Errorf("Expected invalid UUID after repo delete but got json back: %s\n", jsonResp)
	}
	if err != datastore.ErrInvalidUUID {
		t.Errorf("Expected invalid UUID after repo delete but got unexpected error: %v\n", err)
	}
	_, err = datastore.VersionFromUUID(uuid)
	if err != datastore.ErrInvalidUUID {
		t.Errorf("Expected invalid rot UUID after repo delete but got unexpected error: %v\n", err)
	}
	_, err = datastore.VersionFromUUID(parent1)
	if err != datastore.ErrInvalidUUID {
		t.Errorf("Expected invalid UUID for 1st parent after repo delete but got unexpected error: %v\n", err)
	}
	_, err = datastore.VersionFromUUID(parent2)
	if err != datastore.ErrInvalidUUID {
		t.Errorf("Expected invalid UUID for 2nd parent after repo delete but got unexpected error: %v\n", err)
	}
	_, err = datastore.UUIDFromVersion(rootV)
	if err != datastore.ErrInvalidVersion {
		t.Errorf("Expected invalid version id for root after repo delete but got unexpected error: %v\n", err)
	}
}