node_test.go 863 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
package merkledag

import (
	"testing"
)

func TestRemoveLink(t *testing.T) {
	nd := &Node{
		Links: []*Link{
			&Link{Name: "a"},
			&Link{Name: "b"},
			&Link{Name: "a"},
			&Link{Name: "a"},
			&Link{Name: "c"},
			&Link{Name: "a"},
		},
	}

	err := nd.RemoveNodeLink("a")
	if err != nil {
		t.Fatal(err)
	}

	if len(nd.Links) != 2 {
		t.Fatal("number of links incorrect")
	}

	if nd.Links[0].Name != "b" {
		t.Fatal("link order wrong")
	}

	if nd.Links[1].Name != "c" {
		t.Fatal("link order wrong")
	}

	// should fail
	err = nd.RemoveNodeLink("a")
	if err != ErrNotFound {
		t.Fatal("should have failed to remove link")
	}

	// ensure nothing else got touched
	if len(nd.Links) != 2 {
		t.Fatal("number of links incorrect")
	}

	if nd.Links[0].Name != "b" {
		t.Fatal("link order wrong")
	}

	if nd.Links[1].Name != "c" {
		t.Fatal("link order wrong")
	}
}