Exemplo n.º 1
0
func nodeListHandler(w http.ResponseWriter, r *http.Request) {
	list := make([]*models.Node, 4)
	for i := 0; i < 4; i++ {
		list[i] = testutil.MakeDPNNode()
	}
	data := listResponseData()
	data["results"] = list
	listJson, _ := json.Marshal(data)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(listJson))
}
Exemplo n.º 2
0
func TestChooseNodesForReplication(t *testing.T) {
	node := testutil.MakeDPNNode()
	for i := 1; i <= 4; i++ {
		selectedNodes, err := node.ChooseNodesForReplication(i)
		assert.Nil(t, err)
		assert.Equal(t, i, len(selectedNodes))
	}
	selectedNodes, err := node.ChooseNodesForReplication(1000)
	assert.NotNil(t, err)
	require.NotNil(t, selectedNodes)
	assert.Empty(t, selectedNodes)
}
Exemplo n.º 3
0
func TestNodeFQDN(t *testing.T) {
	node := testutil.MakeDPNNode()

	node.APIRoot = "https://example.com"
	host, err := node.FQDN()
	assert.Nil(t, err)
	assert.Equal(t, "example.com", host)

	node.APIRoot = "https://abc.example.com:8080"
	host, err = node.FQDN()
	assert.Nil(t, err)
	assert.Equal(t, "abc.example.com", host)

}
Exemplo n.º 4
0
func nodeGetHandler(w http.ResponseWriter, r *http.Request) {
	obj := testutil.MakeDPNNode()
	objJson, _ := json.Marshal(obj)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(objJson))
}