Remove noise.socket, now unused.
[champa.git] / noise / noise_test.go
blobdac100d59e26d33d9b653b0d7d753570aa522d9f
1 package noise
3 import (
4 "bytes"
5 "testing"
8 func TestReadKey(t *testing.T) {
9 for _, test := range []struct {
10 input string
11 output []byte
13 {"", nil},
14 {"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde", nil},
15 {"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", []byte("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef")},
16 {"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\n", []byte("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef")},
17 {"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0", nil},
18 {"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\nX", nil},
19 {"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\n\n", nil},
20 {"\n0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", nil},
21 {"X123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", nil},
22 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", nil},
23 } {
24 output, err := ReadKey(bytes.NewReader([]byte(test.input)))
25 if test.output == nil {
26 if err == nil {
27 t.Errorf("%+q expected error", test.input)
29 } else {
30 if err != nil {
31 t.Errorf("%+q returned error %v", test.input, err)
32 } else if !bytes.Equal(output, test.output) {
33 t.Errorf("%+q got %x, expected %x", test.input, output, test.output)