summaryrefslogtreecommitdiffstats
path: root/cid/cid_test.go
blob: 9be7e1662b2a5b29a9722292dc6e447d31638b50 (plain)
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
// Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved.
// Use of this source code is governed by an MIT-style license that can be
// found in the LICENSE file.

package cid

import (
	"testing"

	"github.com/calmh/syncthing/protocol"
)

func TestGet(t *testing.T) {
	m := NewMap()

	fooID := protocol.NewNodeID([]byte("foo"))
	barID := protocol.NewNodeID([]byte("bar"))

	if i := m.Get(fooID); i != 1 {
		t.Errorf("Unexpected id %d != 1", i)
	}
	if i := m.Get(barID); i != 2 {
		t.Errorf("Unexpected id %d != 2", i)
	}
	if i := m.Get(fooID); i != 1 {
		t.Errorf("Unexpected id %d != 1", i)
	}
	if i := m.Get(barID); i != 2 {
		t.Errorf("Unexpected id %d != 2", i)
	}

	if LocalID != 0 {
		t.Error("LocalID should be 0")
	}
	if i := m.Get(LocalNodeID); i != LocalID {
		t.Errorf("Unexpected id %d != %d", i, LocalID)
	}
}