mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 03:25:35 +00:00
afce773aae
It was unused in this repo. The Windows client used it, but it can move there. Change-Id: I572816fd80cbbf1b8db734879b6280857d5bd2a7 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ipn
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"tailscale.com/tstest"
|
|
)
|
|
|
|
func TestReadWrite(t *testing.T) {
|
|
tstest.PanicOnLog()
|
|
tstest.ResourceCheck(t)
|
|
|
|
buf := bytes.Buffer{}
|
|
err := WriteMsg(&buf, []byte("Test string1"))
|
|
if err != nil {
|
|
t.Fatalf("write1: %v\n", err)
|
|
}
|
|
err = WriteMsg(&buf, []byte(""))
|
|
if err != nil {
|
|
t.Fatalf("write2: %v\n", err)
|
|
}
|
|
err = WriteMsg(&buf, []byte("Test3"))
|
|
if err != nil {
|
|
t.Fatalf("write3: %v\n", err)
|
|
}
|
|
|
|
b, err := ReadMsg(&buf)
|
|
if err != nil {
|
|
t.Fatalf("read1 error: %v", err)
|
|
}
|
|
if want, got := "Test string1", string(b); want != got {
|
|
t.Fatalf("read1: %#v != %#v\n", want, got)
|
|
}
|
|
b, err = ReadMsg(&buf)
|
|
if err != nil {
|
|
t.Fatalf("read2 error: %v", err)
|
|
}
|
|
if want, got := "", string(b); want != got {
|
|
t.Fatalf("read2: %#v != %#v\n", want, got)
|
|
}
|
|
b, err = ReadMsg(&buf)
|
|
if err != nil {
|
|
t.Fatalf("read3 error: %v", err)
|
|
}
|
|
if want, got := "Test3", string(b); want != got {
|
|
t.Fatalf("read3: %#v != %#v\n", want, got)
|
|
}
|
|
|
|
b, err = ReadMsg(&buf)
|
|
if err == nil {
|
|
t.Fatalf("read4: expected error, got %#v\n", b)
|
|
}
|
|
}
|
|
|
|
func TestNilBackend(t *testing.T) {
|
|
var called *Notify
|
|
bs := NewBackendServer(t.Logf, nil, func(n Notify) {
|
|
called = &n
|
|
})
|
|
bs.SendErrorMessage("Danger, Will Robinson!")
|
|
if called == nil {
|
|
t.Errorf("expect callback to be called, wasn't")
|
|
}
|
|
if called.ErrMessage == nil || *called.ErrMessage != "Danger, Will Robinson!" {
|
|
t.Errorf("callback got wrong error: %v", called.ErrMessage)
|
|
}
|
|
}
|