package main import ( "slices" "testing" ) // CARLOS_SIDECAR_ACCOUNTS reaches Config.SidecarAccounts through // sidecarAccounts: trimmed, lower-cased, each a sqid. Unset and the empty // string are nil, which is no gate; any entry that is not a sqid, and any // other value that names no sqid, is an error serve stops on (TestServeStopsOnABadSidecarAccount runs that through the binary). func TestSidecarAccountsParsesTheList(t *testing.T) { for _, tc := range []struct { val string want []string wantErr bool }{ {"", nil, false}, {" ", nil, true}, // set, but names no sqid: refused, never "no gate" {",", nil, true}, // the same, and the review's case {" , ", nil, true}, // ditto {"bab", []string{"bab"}, false}, {" BAB , cdef ,", []string{"bab", "cdef"}, false}, {"bab,ops", nil, true}, // a name, not a sqid: o is not in the alphabet {"bab,ab", nil, true}, // too short {"bab,b-b", nil, true}, // not a letter {"bab;cdef", nil, true}, // wrong separator reads as one bad entry {"x1234567890abcdefg", nil, true}, } { got, err := sidecarAccounts(func(k string) string { if k != "CARLOS_SIDECAR_ACCOUNTS" { t.Fatalf("read %s", k) } return tc.val }) if (err != nil) != tc.wantErr { t.Errorf("CARLOS_SIDECAR_ACCOUNTS=%q: err %v, want error %v", tc.val, err, tc.wantErr) continue } if !slices.Equal(got, tc.want) { t.Errorf("CARLOS_SIDECAR_ACCOUNTS=%q: %v, want %v", tc.val, got, tc.want) } } }