cmd/vet: add subtestnames analyzer; fix all existing violations
Add a new vet analyzer that checks t.Run subtest names don't contain characters requiring quoting when re-running via "go test -run". This enforces the style guide rule: don't use spaces or punctuation in subtest names. The analyzer flags: - Direct t.Run calls with string literal names containing spaces, regex metacharacters, quotes, or other problematic characters - Table-driven t.Run(tt.name, ...) calls where tt ranges over a slice/map literal with bad name field values Also fix all 978 existing violations across 81 test files, replacing spaces with hyphens and shortening long sentence-like names to concise hyphenated forms. Updates #19242 Change-Id: Ib0ad96a111bd8e764582d1d4902fe2599454ab65 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
0f02c20c5e
commit
5ef3713c9f
+23
-23
@@ -16,77 +16,77 @@ func TestCompare(t *testing.T) {
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "both empty",
|
||||
name: "both-empty",
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "v1 empty",
|
||||
name: "v1-empty",
|
||||
v2: "1.2.3",
|
||||
want: -1,
|
||||
},
|
||||
{
|
||||
name: "v2 empty",
|
||||
name: "v2-empty",
|
||||
v1: "1.2.3",
|
||||
want: 1,
|
||||
},
|
||||
|
||||
{
|
||||
name: "semver major",
|
||||
name: "semver-major",
|
||||
v1: "2.0.0",
|
||||
v2: "1.9.9",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "semver major",
|
||||
name: "semver-major",
|
||||
v1: "2.0.0",
|
||||
v2: "1.9.9",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "semver minor",
|
||||
name: "semver-minor",
|
||||
v1: "1.9.0",
|
||||
v2: "1.8.9",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "semver patch",
|
||||
name: "semver-patch",
|
||||
v1: "1.9.9",
|
||||
v2: "1.9.8",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "semver equal",
|
||||
name: "semver-equal",
|
||||
v1: "1.9.8",
|
||||
v2: "1.9.8",
|
||||
want: 0,
|
||||
},
|
||||
|
||||
{
|
||||
name: "tailscale major",
|
||||
name: "tailscale-major",
|
||||
v1: "1.0-0",
|
||||
v2: "0.97-105",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "tailscale minor",
|
||||
name: "tailscale-minor",
|
||||
v1: "0.98-0",
|
||||
v2: "0.97-105",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "tailscale patch",
|
||||
name: "tailscale-patch",
|
||||
v1: "0.97-120",
|
||||
v2: "0.97-105",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "tailscale equal",
|
||||
name: "tailscale-equal",
|
||||
v1: "0.97-105",
|
||||
v2: "0.97-105",
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "tailscale weird extra field",
|
||||
name: "tailscale-weird-extra-field",
|
||||
v1: "0.96.1-0", // more fields == larger
|
||||
v2: "0.96-105",
|
||||
want: 1,
|
||||
@@ -96,7 +96,7 @@ func TestCompare(t *testing.T) {
|
||||
// of strconv.ParseUint with these characters would have lead us to
|
||||
// panic. We're now only looking at ascii numbers, so test these are
|
||||
// compared as text.
|
||||
name: "only ascii numbers",
|
||||
name: "only-ascii-numbers",
|
||||
v1: "۱۱", // 2x EXTENDED ARABIC-INDIC DIGIT ONE
|
||||
v2: "۲", // 1x EXTENDED ARABIC-INDIC DIGIT TWO
|
||||
want: -1,
|
||||
@@ -104,55 +104,55 @@ func TestCompare(t *testing.T) {
|
||||
|
||||
// A few specific OS version tests below.
|
||||
{
|
||||
name: "windows version",
|
||||
name: "windows-version",
|
||||
v1: "10.0.19045.3324",
|
||||
v2: "10.0.18362",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "windows 11 is everything above 10.0.22000",
|
||||
name: "windows-11-above-10_0_22000",
|
||||
v1: "10.0.22631.2262",
|
||||
v2: "10.0.22000",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "android short version",
|
||||
name: "android-short-version",
|
||||
v1: "10",
|
||||
v2: "7",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "android longer version",
|
||||
name: "android-longer-version",
|
||||
v1: "7.1.2",
|
||||
v2: "7",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "iOS version",
|
||||
name: "iOS-version",
|
||||
v1: "15.6.1",
|
||||
v2: "15.6",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "Linux short kernel version",
|
||||
name: "linux-short-kernel-version",
|
||||
v1: "4.4.302+",
|
||||
v2: "4.0",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "Linux long kernel version",
|
||||
name: "linux-long-kernel-version",
|
||||
v1: "4.14.255-311-248.529.amzn2.x86_64",
|
||||
v2: "4.0",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "FreeBSD version",
|
||||
name: "freebsd-version",
|
||||
v1: "14.0-CURRENT",
|
||||
v2: "14",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "Synology version",
|
||||
name: "synology-version",
|
||||
v1: "Synology 6.2.4; kernel=3.10.105",
|
||||
v2: "Synology 6",
|
||||
want: 1,
|
||||
|
||||
@@ -360,17 +360,17 @@ func TestGetTypeHasher(t *testing.T) {
|
||||
out32: "\x01\x04\x00\x00\x00\x00\x00\x00\x00\x01\x03\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00*\v\x00\x00\x00\x00\x00\x00\x0010.1.3.4/32\v\x00\x00\x00\x00\x00\x00\x0010.0.0.0/24\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x001.2.3.4/32\x01 \x00\x00\x00\x01\x00\x02\x00\x01\x04\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04!\x01\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00foo\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\v\x00\x00\x00\x00\x00\x00\x00foooooooooo\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\f\x00\x00\x00\x00\x00\x00\x00baaaaaarrrrr\x00\x01\x00\x02\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\v\x00\x00\x00\x00\x00\x00\x00foooooooooo\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\f\x00\x00\x00\x00\x00\x00\x00baaaaaarrrrr\x00\x01\x00\x02\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\v\x00\x00\x00\x00\x00\x00\x00foooooooooo\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\f\x00\x00\x00\x00\x00\x00\x00baaaaaarrrrr\x00\x01\x00\x02\x00\x00\x00",
|
||||
},
|
||||
{
|
||||
name: "netip.Addr",
|
||||
name: "netip-Addr",
|
||||
val: netip.MustParseAddr("fe80::123%foo"),
|
||||
out: u64(16+3) + u64(0x80fe) + u64(0x2301<<48) + "foo",
|
||||
},
|
||||
{
|
||||
name: "ptr-netip.Addr",
|
||||
name: "ptr-netip-Addr",
|
||||
val: &someIP,
|
||||
out: u8(1) + u64(4) + u32(0x04030201),
|
||||
},
|
||||
{
|
||||
name: "ptr-nil-netip.Addr",
|
||||
name: "ptr-nil-netip-Addr",
|
||||
val: (*netip.Addr)(nil),
|
||||
out: "\x00",
|
||||
},
|
||||
@@ -469,7 +469,7 @@ func TestGetTypeHasher(t *testing.T) {
|
||||
out: "\x01\x01\x00\x00\x00\x02\x00\x00\x00\x03\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\a\b\x00\x00\x00",
|
||||
},
|
||||
{
|
||||
name: "tailcfg.Node",
|
||||
name: "tailcfg-Node",
|
||||
val: &tailcfg.Node{},
|
||||
out: "ANY", // magic value; just check it doesn't fail to hash
|
||||
out32: "ANY",
|
||||
|
||||
@@ -36,17 +36,17 @@ func TestExpectFilter(t *testing.T) {
|
||||
wantErr string // if non-empty, an error is expected containing this text
|
||||
}{
|
||||
{
|
||||
name: "single event",
|
||||
name: "single-event",
|
||||
events: []int{42},
|
||||
expectFunc: eventbustest.Type[EventFoo](),
|
||||
},
|
||||
{
|
||||
name: "multiple events, single expectation",
|
||||
name: "multiple-events-single-expectation",
|
||||
events: []int{42, 1, 2, 3, 4, 5},
|
||||
expectFunc: eventbustest.Type[EventFoo](),
|
||||
},
|
||||
{
|
||||
name: "filter on event with function",
|
||||
name: "filter-on-event-with-function",
|
||||
events: []int{24, 42},
|
||||
expectFunc: func(event EventFoo) (bool, error) {
|
||||
if event.Value == 42 {
|
||||
@@ -77,7 +77,7 @@ func TestExpectFilter(t *testing.T) {
|
||||
wantErr: "value > 10",
|
||||
},
|
||||
{
|
||||
name: "first event has to be func",
|
||||
name: "first-event-has-to-be-func",
|
||||
events: []int{24, 42},
|
||||
expectFunc: func(event EventFoo) (bool, error) {
|
||||
if event.Value != 42 {
|
||||
@@ -99,7 +99,7 @@ func TestExpectFilter(t *testing.T) {
|
||||
wantErr: "wrong result (-got, +want)",
|
||||
},
|
||||
{
|
||||
name: "no events",
|
||||
name: "no-events",
|
||||
events: []int{},
|
||||
expectFunc: func(event EventFoo) (bool, error) {
|
||||
return true, nil
|
||||
@@ -151,37 +151,37 @@ func TestExpectEvents(t *testing.T) {
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "No expectations",
|
||||
name: "no-expectations",
|
||||
events: []any{EventFoo{}},
|
||||
expectEvents: []any{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "One event",
|
||||
name: "one-event",
|
||||
events: []any{EventFoo{}},
|
||||
expectEvents: []any{eventbustest.Type[EventFoo]()},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Two events",
|
||||
name: "two-events",
|
||||
events: []any{EventFoo{}, EventBar{}},
|
||||
expectEvents: []any{eventbustest.Type[EventFoo](), eventbustest.Type[EventBar]()},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Two expected events with another in the middle",
|
||||
name: "two-expected-events-with-another-in-middle",
|
||||
events: []any{EventFoo{}, EventBaz{}, EventBar{}},
|
||||
expectEvents: []any{eventbustest.Type[EventFoo](), eventbustest.Type[EventBar]()},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Missing event",
|
||||
name: "missing-event",
|
||||
events: []any{EventFoo{}, EventBaz{}},
|
||||
expectEvents: []any{eventbustest.Type[EventFoo](), eventbustest.Type[EventBar]()},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "One event with specific value",
|
||||
name: "one-event-with-specific-value",
|
||||
events: []any{EventFoo{42}},
|
||||
expectEvents: []any{
|
||||
func(ev EventFoo) (bool, error) {
|
||||
@@ -194,7 +194,7 @@ func TestExpectEvents(t *testing.T) {
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Two event with one specific value",
|
||||
name: "two-events-with-one-specific-value",
|
||||
events: []any{EventFoo{43}, EventFoo{42}},
|
||||
expectEvents: []any{
|
||||
func(ev EventFoo) (bool, error) {
|
||||
@@ -207,7 +207,7 @@ func TestExpectEvents(t *testing.T) {
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "One event with wrong value",
|
||||
name: "one-event-with-wrong-value",
|
||||
events: []any{EventFoo{43}},
|
||||
expectEvents: []any{
|
||||
func(ev EventFoo) (bool, error) {
|
||||
@@ -220,7 +220,7 @@ func TestExpectEvents(t *testing.T) {
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Two events with specific values",
|
||||
name: "two-events-with-specific-values",
|
||||
events: []any{EventFoo{42}, EventFoo{42}, EventBar{"42"}},
|
||||
expectEvents: []any{
|
||||
func(ev EventFoo) (bool, error) {
|
||||
@@ -283,37 +283,37 @@ func TestExpectExactlyEventsFilter(t *testing.T) {
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "No expectations",
|
||||
name: "no-expectations",
|
||||
events: []any{EventFoo{}},
|
||||
expectEvents: []any{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "One event",
|
||||
name: "one-event",
|
||||
events: []any{EventFoo{}},
|
||||
expectEvents: []any{eventbustest.Type[EventFoo]()},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Two events",
|
||||
name: "two-events",
|
||||
events: []any{EventFoo{}, EventBar{}},
|
||||
expectEvents: []any{eventbustest.Type[EventFoo](), eventbustest.Type[EventBar]()},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Two expected events with another in the middle",
|
||||
name: "two-expected-events-with-another-in-middle",
|
||||
events: []any{EventFoo{}, EventBaz{}, EventBar{}},
|
||||
expectEvents: []any{eventbustest.Type[EventFoo](), eventbustest.Type[EventBar]()},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Missing event",
|
||||
name: "missing-event",
|
||||
events: []any{EventFoo{}, EventBaz{}},
|
||||
expectEvents: []any{eventbustest.Type[EventFoo](), eventbustest.Type[EventBar]()},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "One event with value",
|
||||
name: "one-event-with-value",
|
||||
events: []any{EventFoo{42}},
|
||||
expectEvents: []any{
|
||||
func(ev EventFoo) (bool, error) {
|
||||
@@ -326,7 +326,7 @@ func TestExpectExactlyEventsFilter(t *testing.T) {
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Two event with one specific value",
|
||||
name: "two-events-with-one-specific-value",
|
||||
events: []any{EventFoo{43}, EventFoo{42}},
|
||||
expectEvents: []any{
|
||||
func(ev EventFoo) (bool, error) {
|
||||
@@ -339,7 +339,7 @@ func TestExpectExactlyEventsFilter(t *testing.T) {
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "One event with wrong value",
|
||||
name: "one-event-with-wrong-value",
|
||||
events: []any{EventFoo{43}},
|
||||
expectEvents: []any{
|
||||
func(ev EventFoo) (bool, error) {
|
||||
@@ -352,7 +352,7 @@ func TestExpectExactlyEventsFilter(t *testing.T) {
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Two events with specific values",
|
||||
name: "two-events-with-specific-values",
|
||||
events: []any{EventFoo{42}, EventFoo{42}, EventBar{"42"}},
|
||||
expectEvents: []any{
|
||||
func(ev EventFoo) (bool, error) {
|
||||
|
||||
@@ -960,32 +960,32 @@ func TestPickFirewallModeFromInstalledRules(t *testing.T) {
|
||||
want FirewallMode
|
||||
}{
|
||||
{
|
||||
name: "using iptables legacy",
|
||||
name: "using-iptables-legacy",
|
||||
det: &testFWDetector{iptRuleCount: 1},
|
||||
want: FirewallModeIPTables,
|
||||
},
|
||||
{
|
||||
name: "using nftables",
|
||||
name: "using-nftables",
|
||||
det: &testFWDetector{nftRuleCount: 1},
|
||||
want: FirewallModeNfTables,
|
||||
},
|
||||
{
|
||||
name: "using both iptables and nftables",
|
||||
name: "using-both-iptables-and-nftables",
|
||||
det: &testFWDetector{iptRuleCount: 2, nftRuleCount: 2},
|
||||
want: FirewallModeNfTables,
|
||||
},
|
||||
{
|
||||
name: "not using any firewall, both available",
|
||||
name: "no-firewall-both-available",
|
||||
det: &testFWDetector{},
|
||||
want: FirewallModeNfTables,
|
||||
},
|
||||
{
|
||||
name: "not using any firewall, iptables available only",
|
||||
name: "no-firewall-iptables-only",
|
||||
det: &testFWDetector{iptRuleCount: 1, nftErr: errors.New("nft error")},
|
||||
want: FirewallModeIPTables,
|
||||
},
|
||||
{
|
||||
name: "not using any firewall, nftables available only",
|
||||
name: "no-firewall-nftables-only",
|
||||
det: &testFWDetector{iptErr: errors.New("iptables error"), nftRuleCount: 1},
|
||||
want: FirewallModeNfTables,
|
||||
},
|
||||
|
||||
@@ -226,42 +226,42 @@ func TestPolicyScopeContains(t *testing.T) {
|
||||
wantAStrictlyContainsB: false,
|
||||
},
|
||||
{
|
||||
name: "UserScope(1234)/UserScope(1234)",
|
||||
name: "UserScope-1234/UserScope-1234",
|
||||
scopeA: UserScopeOf("1234"),
|
||||
scopeB: UserScopeOf("1234"),
|
||||
wantAContainsB: true,
|
||||
wantAStrictlyContainsB: false,
|
||||
},
|
||||
{
|
||||
name: "UserScope(1234)/UserScope(5678)",
|
||||
name: "UserScope-1234/UserScope-5678",
|
||||
scopeA: UserScopeOf("1234"),
|
||||
scopeB: UserScopeOf("5678"),
|
||||
wantAContainsB: false,
|
||||
wantAStrictlyContainsB: false,
|
||||
},
|
||||
{
|
||||
name: "ProfileScope(A)/UserScope(A/1234)",
|
||||
name: "ProfileScope-A/UserScope-A-1234",
|
||||
scopeA: PolicyScope{kind: ProfileSetting, profileID: "A"},
|
||||
scopeB: PolicyScope{kind: UserSetting, userID: "1234", profileID: "A"},
|
||||
wantAContainsB: true,
|
||||
wantAStrictlyContainsB: true,
|
||||
},
|
||||
{
|
||||
name: "ProfileScope(A)/UserScope(B/1234)",
|
||||
name: "ProfileScope-A/UserScope-B-1234",
|
||||
scopeA: PolicyScope{kind: ProfileSetting, profileID: "A"},
|
||||
scopeB: PolicyScope{kind: UserSetting, userID: "1234", profileID: "B"},
|
||||
wantAContainsB: false,
|
||||
wantAStrictlyContainsB: false,
|
||||
},
|
||||
{
|
||||
name: "UserScope(1234)/UserScope(A/1234)",
|
||||
name: "UserScope-1234/UserScope-A-1234",
|
||||
scopeA: PolicyScope{kind: UserSetting, userID: "1234"},
|
||||
scopeB: PolicyScope{kind: UserSetting, userID: "1234", profileID: "A"},
|
||||
wantAContainsB: true,
|
||||
wantAStrictlyContainsB: true,
|
||||
},
|
||||
{
|
||||
name: "UserScope(1234)/UserScope(A/5678)",
|
||||
name: "UserScope-1234/UserScope-A-5678",
|
||||
scopeA: PolicyScope{kind: UserSetting, userID: "1234"},
|
||||
scopeB: PolicyScope{kind: UserSetting, userID: "5678", profileID: "A"},
|
||||
wantAContainsB: false,
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestGetString(t *testing.T) {
|
||||
wantMetrics []metrics.TestState
|
||||
}{
|
||||
{
|
||||
name: "read existing value",
|
||||
name: "read-existing-value",
|
||||
key: pkey.AdminConsoleVisibility,
|
||||
handlerValue: "hide",
|
||||
wantValue: "hide",
|
||||
@@ -54,13 +54,13 @@ func TestGetString(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "read non-existing value",
|
||||
name: "read-non-existing-value",
|
||||
key: pkey.EnableServerMode,
|
||||
handlerError: ErrNotConfigured,
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
name: "read non-existing value, non-blank default",
|
||||
name: "read-non-existing-value-non-blank-default",
|
||||
key: pkey.EnableServerMode,
|
||||
handlerError: ErrNotConfigured,
|
||||
defaultValue: "test",
|
||||
@@ -68,7 +68,7 @@ func TestGetString(t *testing.T) {
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
name: "reading value returns other error",
|
||||
name: "reading-value-returns-other-error",
|
||||
key: pkey.NetworkDevicesVisibility,
|
||||
handlerError: someOtherError,
|
||||
wantError: someOtherError,
|
||||
@@ -124,27 +124,27 @@ func TestGetUint64(t *testing.T) {
|
||||
wantError error
|
||||
}{
|
||||
{
|
||||
name: "read existing value",
|
||||
name: "read-existing-value",
|
||||
key: pkey.LogSCMInteractions,
|
||||
handlerValue: 1,
|
||||
wantValue: 1,
|
||||
},
|
||||
{
|
||||
name: "read non-existing value",
|
||||
name: "read-non-existing-value",
|
||||
key: pkey.LogSCMInteractions,
|
||||
handlerValue: 0,
|
||||
handlerError: ErrNotConfigured,
|
||||
wantValue: 0,
|
||||
},
|
||||
{
|
||||
name: "read non-existing value, non-zero default",
|
||||
name: "read-non-existing-value-non-zero-default",
|
||||
key: pkey.LogSCMInteractions,
|
||||
defaultValue: 2,
|
||||
handlerError: ErrNotConfigured,
|
||||
wantValue: 2,
|
||||
},
|
||||
{
|
||||
name: "reading value returns other error",
|
||||
name: "reading-value-returns-other-error",
|
||||
key: pkey.FlushDNSOnSessionUnlock,
|
||||
handlerError: someOtherError,
|
||||
wantError: someOtherError,
|
||||
@@ -191,7 +191,7 @@ func TestGetBoolean(t *testing.T) {
|
||||
wantMetrics []metrics.TestState
|
||||
}{
|
||||
{
|
||||
name: "read existing value",
|
||||
name: "read-existing-value",
|
||||
key: pkey.FlushDNSOnSessionUnlock,
|
||||
handlerValue: true,
|
||||
wantValue: true,
|
||||
@@ -201,14 +201,14 @@ func TestGetBoolean(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "read non-existing value",
|
||||
name: "read-non-existing-value",
|
||||
key: pkey.LogSCMInteractions,
|
||||
handlerValue: false,
|
||||
handlerError: ErrNotConfigured,
|
||||
wantValue: false,
|
||||
},
|
||||
{
|
||||
name: "reading value returns other error",
|
||||
name: "reading-value-returns-other-error",
|
||||
key: pkey.FlushDNSOnSessionUnlock,
|
||||
handlerError: someOtherError,
|
||||
wantError: someOtherError, // expect error...
|
||||
@@ -266,7 +266,7 @@ func TestGetPreferenceOption(t *testing.T) {
|
||||
wantMetrics []metrics.TestState
|
||||
}{
|
||||
{
|
||||
name: "always by policy",
|
||||
name: "always-by-policy",
|
||||
key: pkey.EnableIncomingConnections,
|
||||
handlerValue: "always",
|
||||
wantValue: ptype.AlwaysByPolicy,
|
||||
@@ -276,7 +276,7 @@ func TestGetPreferenceOption(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "never by policy",
|
||||
name: "never-by-policy",
|
||||
key: pkey.EnableIncomingConnections,
|
||||
handlerValue: "never",
|
||||
wantValue: ptype.NeverByPolicy,
|
||||
@@ -286,7 +286,7 @@ func TestGetPreferenceOption(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "use default",
|
||||
name: "use-default",
|
||||
key: pkey.EnableIncomingConnections,
|
||||
handlerValue: "",
|
||||
wantValue: ptype.ShowChoiceByPolicy,
|
||||
@@ -296,13 +296,13 @@ func TestGetPreferenceOption(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "read non-existing value",
|
||||
name: "read-non-existing-value",
|
||||
key: pkey.EnableIncomingConnections,
|
||||
handlerError: ErrNotConfigured,
|
||||
wantValue: ptype.ShowChoiceByPolicy,
|
||||
},
|
||||
{
|
||||
name: "other error is returned",
|
||||
name: "other-error-is-returned",
|
||||
key: pkey.EnableIncomingConnections,
|
||||
handlerError: someOtherError,
|
||||
wantValue: ptype.ShowChoiceByPolicy,
|
||||
@@ -359,7 +359,7 @@ func TestGetVisibility(t *testing.T) {
|
||||
wantMetrics []metrics.TestState
|
||||
}{
|
||||
{
|
||||
name: "hidden by policy",
|
||||
name: "hidden-by-policy",
|
||||
key: pkey.AdminConsoleVisibility,
|
||||
handlerValue: "hide",
|
||||
wantValue: ptype.HiddenByPolicy,
|
||||
@@ -369,7 +369,7 @@ func TestGetVisibility(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "visibility default",
|
||||
name: "visibility-default",
|
||||
key: pkey.AdminConsoleVisibility,
|
||||
handlerValue: "show",
|
||||
wantValue: ptype.VisibleByPolicy,
|
||||
@@ -379,14 +379,14 @@ func TestGetVisibility(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "read non-existing value",
|
||||
name: "read-non-existing-value",
|
||||
key: pkey.AdminConsoleVisibility,
|
||||
handlerValue: "show",
|
||||
handlerError: ErrNotConfigured,
|
||||
wantValue: ptype.VisibleByPolicy,
|
||||
},
|
||||
{
|
||||
name: "other error is returned",
|
||||
name: "other-error-is-returned",
|
||||
key: pkey.AdminConsoleVisibility,
|
||||
handlerValue: "show",
|
||||
handlerError: someOtherError,
|
||||
@@ -445,7 +445,7 @@ func TestGetDuration(t *testing.T) {
|
||||
wantMetrics []metrics.TestState
|
||||
}{
|
||||
{
|
||||
name: "read existing value",
|
||||
name: "read-existing-value",
|
||||
key: pkey.KeyExpirationNoticeTime,
|
||||
handlerValue: "2h",
|
||||
wantValue: 2 * time.Hour,
|
||||
@@ -456,7 +456,7 @@ func TestGetDuration(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid duration value",
|
||||
name: "invalid-duration-value",
|
||||
key: pkey.KeyExpirationNoticeTime,
|
||||
handlerValue: "-20",
|
||||
wantValue: 24 * time.Hour,
|
||||
@@ -468,21 +468,21 @@ func TestGetDuration(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "read non-existing value",
|
||||
name: "read-non-existing-value",
|
||||
key: pkey.KeyExpirationNoticeTime,
|
||||
handlerError: ErrNotConfigured,
|
||||
wantValue: 24 * time.Hour,
|
||||
defaultValue: 24 * time.Hour,
|
||||
},
|
||||
{
|
||||
name: "read non-existing value different default",
|
||||
name: "read-non-existing-value-different-default",
|
||||
key: pkey.KeyExpirationNoticeTime,
|
||||
handlerError: ErrNotConfigured,
|
||||
wantValue: 0 * time.Second,
|
||||
defaultValue: 0 * time.Second,
|
||||
},
|
||||
{
|
||||
name: "other error is returned",
|
||||
name: "other-error-is-returned",
|
||||
key: pkey.KeyExpirationNoticeTime,
|
||||
handlerError: someOtherError,
|
||||
wantValue: 24 * time.Hour,
|
||||
@@ -541,7 +541,7 @@ func TestGetStringArray(t *testing.T) {
|
||||
wantMetrics []metrics.TestState
|
||||
}{
|
||||
{
|
||||
name: "read existing value",
|
||||
name: "read-existing-value",
|
||||
key: pkey.AllowedSuggestedExitNodes,
|
||||
handlerValue: []string{"foo", "bar"},
|
||||
wantValue: []string{"foo", "bar"},
|
||||
@@ -551,13 +551,13 @@ func TestGetStringArray(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "read non-existing value",
|
||||
name: "read-non-existing-value",
|
||||
key: pkey.AllowedSuggestedExitNodes,
|
||||
handlerError: ErrNotConfigured,
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
name: "read non-existing value, non nil default",
|
||||
name: "read-non-existing-value-non-nil-default",
|
||||
key: pkey.AllowedSuggestedExitNodes,
|
||||
handlerError: ErrNotConfigured,
|
||||
defaultValue: []string{"foo", "bar"},
|
||||
@@ -565,7 +565,7 @@ func TestGetStringArray(t *testing.T) {
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
name: "reading value returns other error",
|
||||
name: "reading-value-returns-other-error",
|
||||
key: pkey.AllowedSuggestedExitNodes,
|
||||
handlerError: someOtherError,
|
||||
wantError: someOtherError,
|
||||
|
||||
Reference in New Issue
Block a user