carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package main
2
3import (
4 "slices"
5 "testing"
6)
7
8// CARLOS_SIDECAR_ACCOUNTS reaches Config.SidecarAccounts through
9// sidecarAccounts: trimmed, lower-cased, each a sqid. Unset and the empty
10// string are nil, which is no gate; any entry that is not a sqid, and any
11// other value that names no sqid, is an error serve stops on (TestServeStopsOnABadSidecarAccount runs that through the binary).
12func TestSidecarAccountsParsesTheList(t *testing.T) {
13 for _, tc := range []struct {
14 val string
15 want []string
16 wantErr bool
17 }{
18 {"", nil, false},
19 {" ", nil, true}, // set, but names no sqid: refused, never "no gate"
20 {",", nil, true}, // the same, and the review's case
21 {" , ", nil, true}, // ditto
22 {"bab", []string{"bab"}, false},
23 {" BAB , cdef ,", []string{"bab", "cdef"}, false},
24 {"bab,ops", nil, true}, // a name, not a sqid: o is not in the alphabet
25 {"bab,ab", nil, true}, // too short
26 {"bab,b-b", nil, true}, // not a letter
27 {"bab;cdef", nil, true}, // wrong separator reads as one bad entry
28 {"x1234567890abcdefg", nil, true},
29 } {
30 got, err := sidecarAccounts(func(k string) string {
31 if k != "CARLOS_SIDECAR_ACCOUNTS" {
32 t.Fatalf("read %s", k)
33 }
34 return tc.val
35 })
36 if (err != nil) != tc.wantErr {
37 t.Errorf("CARLOS_SIDECAR_ACCOUNTS=%q: err %v, want error %v", tc.val, err, tc.wantErr)
38 continue
39 }
40 if !slices.Equal(got, tc.want) {
41 t.Errorf("CARLOS_SIDECAR_ACCOUNTS=%q: %v, want %v", tc.val, got, tc.want)
42 }
43 }
44}
45