Exemplo n.º 1
0
func (suite *GraphTestSuite) BenchmarkWrite(t *C) {
	var err error
	var info graph.NodeInfo

	info.ParentId = graph.RootNodeId
	info.Mode = os.FileMode(0755)
	info.Type = "application/json"
	for i := 0; err == nil && i < t.N; i++ {
		info.Name = fmt.Sprint(i)
		_, err = suite.ng.NewNodeWithNodeInfo(info)
	}

	if err != nil {
		panic(err)
	}
}
Exemplo n.º 2
0
func (suite *ApiTestSuite) TestUpdateNode_movesFileSuccessfully(t *C) {
	folder, err := suite.ng.CreateDirectory(suite.ng.RootNode.Id, "folder 1")
	t.Check(err, IsNil)

	nodeInfo := graph.NodeInfo{
		Name: "file.txt",
		Mode: 0755,
	}
	id, err := suite.createNodeWithSize(suite.ng.RootNode.Id, nodeInfo, 1024)
	t.Check(err, IsNil)

	nodeInfo.ParentId = folder.Id

	req := suite.request(api.UpdateNode.Build(id), encode(nodeInfo))
	resp, err := suite.client.Do(req)
	t.Check(err, IsNil)
	t.Check(msg(resp), Equals, "")

	t.Check(folder.Children(), HasLen, 1)
	t.Check(folder.Children()[0].Name(), Equals, "file.txt")
}
Exemplo n.º 3
0
// POST v1/node/{parentId}
// body -> {nodeInfo}
// returns -> {nodeInfo}
func (restApi OlympusApi) CreateNode(writer http.ResponseWriter, req *http.Request) {
	parent := restApi.graph.NodeWithId(paramFromRequest("parentId", req))
	if !parent.Exists() {
		writeNodeNotFoundError(parent.Id, writer)
		return
	}

	var nodeInfo graph.NodeInfo
	defer req.Body.Close()
	decoder := decoderFromHeader(req.Body, req.Header)

	if err := decoder.Decode(&nodeInfo); err != nil {
		writer.WriteHeader(http.StatusBadRequest)
		writer.Write([]byte(err.Error()))
		return
	} else if node := restApi.graph.NodeWithName(parent.Id, nodeInfo.Name); node != nil && node.Exists() {
		http.Error(writer, fmt.Sprintf("Node exists, call /v1/touch/%s/ to update this object", node.Id),
			http.StatusBadRequest)
	} else {
		nodeInfo.ParentId = parent.Id
		nodeInfo.MTime = time.Now()

		if nodeInfo.Type == "" {
			nodeInfo.Type = util.MimeType(nodeInfo.Name)
		}

		if newNode, err := restApi.graph.NewNodeWithNodeInfo(nodeInfo); err != nil {
			http.Error(writer, err.Error(), http.StatusBadRequest)
		} else {
			encoder := encoderFromHeader(writer, req.Header)
			writer.WriteHeader(http.StatusCreated)
			nodeInfo = newNode.NodeInfo()
			encoder.Encode(nodeInfo)
		}
	}
}