internal/control/keylabel_test.go

v1.43.1
gitbay/internal/control/keylabel_test.go history · blame · raw

23 lines · 514 bytes

 1package control
 2
 3import "testing"
 4
 5func TestKeyLabel(t *testing.T) {
 6	cases := []struct {
 7		in, want string
 8		ok       bool
 9	}{
10		{"", "", true},
11		{"  laptop  ", "laptop", true},
12		{"you@machine", "you@machine", true},
13		{"two\nlines", "", false},
14		{"tab\there", "", false},
15		{string(make([]byte, 65)), "", false},
16	}
17	for _, c := range cases {
18		got, err := keyLabel(c.in)
19		if (err == nil) != c.ok || got != c.want {
20			t.Errorf("keyLabel(%q) = %q, %v; want %q, ok=%v", c.in, got, err, c.want, c.ok)
21		}
22	}
23}