MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestNodeKey

Function TestNodeKey

types/key/node_test.go:15–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestNodeKey(t *testing.T) {
16 k := NewNode()
17 if k.IsZero() {
18 t.Fatal("NodePrivate should not be zero")
19 }
20
21 p := k.Public()
22 if p.IsZero() {
23 t.Fatal("NodePublic should not be zero")
24 }
25
26 bs, err := p.MarshalText()
27 if err != nil {
28 t.Fatal(err)
29 }
30 if full, got := string(bs), ":"+p.UntypedHexString(); !strings.HasSuffix(full, got) {
31 t.Fatalf("NodePublic.UntypedHexString is not a suffix of the typed serialization, got %q want suffix of %q", got, full)
32 }
33 bs, err = p.MarshalBinary()
34 if err != nil {
35 t.Fatal(err)
36 }
37 if got, want := bs, append([]byte(nodePublicBinaryPrefix), p.k[:]...); !bytes.Equal(got, want) {
38 t.Fatalf("Binary-encoded NodePublic = %x, want %x", got, want)
39 }
40 var decoded NodePublic
41 if err := decoded.UnmarshalBinary(bs); err != nil {
42 t.Fatalf("NodePublic.UnmarshalBinary(%x) failed: %v", bs, err)
43 }
44 if decoded != p {
45 t.Errorf("unmarshaled and original NodePublic differ:\noriginal = %v\ndecoded = %v", p, decoded)
46 }
47
48 z := NodePublic{}
49 if !z.IsZero() {
50 t.Fatal("IsZero(NodePublic{}) is false")
51 }
52 if s := z.ShortString(); s != "" {
53 t.Fatalf("NodePublic{}.ShortString() is %q, want \"\"", s)
54 }
55}
56
57func TestNodeSerialization(t *testing.T) {
58 serialized := `{

Callers

nothing calls this directly

Calls 13

UnmarshalBinaryMethod · 0.95
IsZeroMethod · 0.95
ShortStringMethod · 0.95
NewNodeFunction · 0.85
IsZeroMethod · 0.65
FatalMethod · 0.65
FatalfMethod · 0.65
EqualMethod · 0.65
ErrorfMethod · 0.65
PublicMethod · 0.45
MarshalTextMethod · 0.45
UntypedHexStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…