diff --git a/.golangci.yml b/.golangci.yml index 5573610570..30bcd9e449 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,7 +23,7 @@ issues: linters-settings: gofmt: - simplify: false + simplify: true run: timeout: 10m diff --git a/acl/acl_test.go b/acl/acl_test.go index 2dacb6f884..8e50f75f57 100644 --- a/acl/acl_test.go +++ b/acl/acl_test.go @@ -460,15 +460,15 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "root", Policy: PolicyRead, }, - &AgentRule{ + { Node: "root-nope", Policy: PolicyDeny, }, - &AgentRule{ + { Node: "root-rw", Policy: PolicyWrite, }, @@ -500,15 +500,15 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "root", Policy: PolicyRead, }, - &AgentRule{ + { Node: "root-nope", Policy: PolicyDeny, }, - &AgentRule{ + { Node: "root-rw", Policy: PolicyWrite, }, @@ -540,7 +540,7 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ PreparedQueries: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "other", Policy: PolicyDeny, }, @@ -564,19 +564,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "root-nope", Policy: PolicyDeny, }, - &AgentRule{ + { Node: "root-ro", Policy: PolicyRead, }, - &AgentRule{ + { Node: "root-rw", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "override", Policy: PolicyDeny, }, @@ -586,19 +586,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "child-nope", Policy: PolicyDeny, }, - &AgentRule{ + { Node: "child-ro", Policy: PolicyRead, }, - &AgentRule{ + { Node: "child-rw", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "override", Policy: PolicyWrite, }, @@ -644,19 +644,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "root-nope", Policy: PolicyDeny, }, - &AgentRule{ + { Node: "root-ro", Policy: PolicyRead, }, - &AgentRule{ + { Node: "root-rw", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "override", Policy: PolicyDeny, }, @@ -666,19 +666,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "child-nope", Policy: PolicyDeny, }, - &AgentRule{ + { Node: "child-ro", Policy: PolicyRead, }, - &AgentRule{ + { Node: "child-rw", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "override", Policy: PolicyWrite, }, @@ -721,7 +721,7 @@ func TestACL(t *testing.T) { name: "KeyringDefaultAllowPolicyDeny", defaultPolicy: AllowAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Keyring: PolicyDeny, }, @@ -737,7 +737,7 @@ func TestACL(t *testing.T) { name: "KeyringDefaultAllowPolicyRead", defaultPolicy: AllowAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Keyring: PolicyRead, }, @@ -753,7 +753,7 @@ func TestACL(t *testing.T) { name: "KeyringDefaultAllowPolicyWrite", defaultPolicy: AllowAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Keyring: PolicyWrite, }, @@ -768,7 +768,7 @@ func TestACL(t *testing.T) { name: "KeyringDefaultAllowPolicyNone", defaultPolicy: AllowAll(), policyStack: []*Policy{ - &Policy{}, + {}, }, checks: []aclCheck{ {name: "ReadAllowed", check: checkAllowKeyringRead}, @@ -779,7 +779,7 @@ func TestACL(t *testing.T) { name: "KeyringDefaultDenyPolicyDeny", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Keyring: PolicyDeny, }, @@ -794,7 +794,7 @@ func TestACL(t *testing.T) { name: "KeyringDefaultDenyPolicyRead", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Keyring: PolicyRead, }, @@ -809,7 +809,7 @@ func TestACL(t *testing.T) { name: "KeyringDefaultDenyPolicyWrite", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Keyring: PolicyWrite, }, @@ -824,7 +824,7 @@ func TestACL(t *testing.T) { name: "KeyringDefaultDenyPolicyNone", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{}, + {}, }, checks: []aclCheck{ {name: "ReadDenied", check: checkDenyKeyringRead}, @@ -835,7 +835,7 @@ func TestACL(t *testing.T) { name: "OperatorDefaultAllowPolicyDeny", defaultPolicy: AllowAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Operator: PolicyDeny, }, @@ -851,7 +851,7 @@ func TestACL(t *testing.T) { name: "OperatorDefaultAllowPolicyRead", defaultPolicy: AllowAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Operator: PolicyRead, }, @@ -867,7 +867,7 @@ func TestACL(t *testing.T) { name: "OperatorDefaultAllowPolicyWrite", defaultPolicy: AllowAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Operator: PolicyWrite, }, @@ -882,7 +882,7 @@ func TestACL(t *testing.T) { name: "OperatorDefaultAllowPolicyNone", defaultPolicy: AllowAll(), policyStack: []*Policy{ - &Policy{}, + {}, }, checks: []aclCheck{ {name: "ReadAllowed", check: checkAllowOperatorRead}, @@ -893,7 +893,7 @@ func TestACL(t *testing.T) { name: "OperatorDefaultDenyPolicyDeny", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Operator: PolicyDeny, }, @@ -908,7 +908,7 @@ func TestACL(t *testing.T) { name: "OperatorDefaultDenyPolicyRead", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Operator: PolicyRead, }, @@ -923,7 +923,7 @@ func TestACL(t *testing.T) { name: "OperatorDefaultDenyPolicyWrite", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Operator: PolicyWrite, }, @@ -938,7 +938,7 @@ func TestACL(t *testing.T) { name: "OperatorDefaultDenyPolicyNone", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{}, + {}, }, checks: []aclCheck{ {name: "ReadDenied", check: checkDenyOperatorRead}, @@ -952,19 +952,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Nodes: []*NodeRule{ - &NodeRule{ + { Name: "root-nope", Policy: PolicyDeny, }, - &NodeRule{ + { Name: "root-ro", Policy: PolicyRead, }, - &NodeRule{ + { Name: "root-rw", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "override", Policy: PolicyDeny, }, @@ -974,19 +974,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Nodes: []*NodeRule{ - &NodeRule{ + { Name: "child-nope", Policy: PolicyDeny, }, - &NodeRule{ + { Name: "child-ro", Policy: PolicyRead, }, - &NodeRule{ + { Name: "child-rw", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "override", Policy: PolicyWrite, }, @@ -1032,19 +1032,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Nodes: []*NodeRule{ - &NodeRule{ + { Name: "root-nope", Policy: PolicyDeny, }, - &NodeRule{ + { Name: "root-ro", Policy: PolicyRead, }, - &NodeRule{ + { Name: "root-rw", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "override", Policy: PolicyDeny, }, @@ -1054,19 +1054,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Nodes: []*NodeRule{ - &NodeRule{ + { Name: "child-nope", Policy: PolicyDeny, }, - &NodeRule{ + { Name: "child-ro", Policy: PolicyRead, }, - &NodeRule{ + { Name: "child-rw", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "override", Policy: PolicyWrite, }, @@ -1112,19 +1112,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Sessions: []*SessionRule{ - &SessionRule{ + { Node: "root-nope", Policy: PolicyDeny, }, - &SessionRule{ + { Node: "root-ro", Policy: PolicyRead, }, - &SessionRule{ + { Node: "root-rw", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "override", Policy: PolicyDeny, }, @@ -1134,19 +1134,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Sessions: []*SessionRule{ - &SessionRule{ + { Node: "child-nope", Policy: PolicyDeny, }, - &SessionRule{ + { Node: "child-ro", Policy: PolicyRead, }, - &SessionRule{ + { Node: "child-rw", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "override", Policy: PolicyWrite, }, @@ -1192,19 +1192,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Sessions: []*SessionRule{ - &SessionRule{ + { Node: "root-nope", Policy: PolicyDeny, }, - &SessionRule{ + { Node: "root-ro", Policy: PolicyRead, }, - &SessionRule{ + { Node: "root-rw", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "override", Policy: PolicyDeny, }, @@ -1214,19 +1214,19 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Sessions: []*SessionRule{ - &SessionRule{ + { Node: "child-nope", Policy: PolicyDeny, }, - &SessionRule{ + { Node: "child-ro", Policy: PolicyRead, }, - &SessionRule{ + { Node: "child-rw", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "override", Policy: PolicyWrite, }, @@ -1272,31 +1272,31 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo/", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "bar/", Policy: PolicyRead, }, }, PreparedQueries: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "other", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "foo", Policy: PolicyRead, }, }, Services: []*ServiceRule{ - &ServiceRule{ + { Name: "other", Policy: PolicyWrite, }, - &ServiceRule{ + { Name: "foo", Policy: PolicyRead, }, @@ -1306,27 +1306,27 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo/priv/", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "bar/", Policy: PolicyDeny, }, - &KeyRule{ + { Prefix: "zip/", Policy: PolicyRead, }, }, PreparedQueries: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "bar", Policy: PolicyDeny, }, }, Services: []*ServiceRule{ - &ServiceRule{ + { Name: "bar", Policy: PolicyDeny, }, @@ -1383,78 +1383,78 @@ func TestACL(t *testing.T) { legacyPolicy(&Policy{ PolicyRules: PolicyRules{ Events: []*EventRule{ - &EventRule{ + { Event: "", Policy: PolicyRead, }, - &EventRule{ + { Event: "foo", Policy: PolicyWrite, }, - &EventRule{ + { Event: "bar", Policy: PolicyDeny, }, }, Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo/", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "foo/priv/", Policy: PolicyDeny, }, - &KeyRule{ + { Prefix: "bar/", Policy: PolicyDeny, }, - &KeyRule{ + { Prefix: "zip/", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "zap/", Policy: PolicyList, }, }, PreparedQueries: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "bar", Policy: PolicyDeny, }, - &PreparedQueryRule{ + { Prefix: "zoo", Policy: PolicyWrite, }, }, Services: []*ServiceRule{ - &ServiceRule{ + { Name: "", Policy: PolicyWrite, }, - &ServiceRule{ + { Name: "foo", Policy: PolicyRead, }, - &ServiceRule{ + { Name: "bar", Policy: PolicyDeny, }, - &ServiceRule{ + { Name: "barfoo", Policy: PolicyWrite, Intentions: PolicyWrite, }, - &ServiceRule{ + { Name: "intbaz", Policy: PolicyWrite, Intentions: PolicyDeny, @@ -1559,147 +1559,147 @@ func TestACL(t *testing.T) { name: "ExactMatchPrecedence", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "foo", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "football", Policy: PolicyDeny, }, }, AgentPrefixes: []*AgentRule{ - &AgentRule{ + { Node: "foot", Policy: PolicyRead, }, - &AgentRule{ + { Node: "fo", Policy: PolicyRead, }, }, Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "football", Policy: PolicyDeny, }, }, KeyPrefixes: []*KeyRule{ - &KeyRule{ + { Prefix: "foot", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "fo", Policy: PolicyRead, }, }, Nodes: []*NodeRule{ - &NodeRule{ + { Name: "foo", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "football", Policy: PolicyDeny, }, }, NodePrefixes: []*NodeRule{ - &NodeRule{ + { Name: "foot", Policy: PolicyRead, }, - &NodeRule{ + { Name: "fo", Policy: PolicyRead, }, }, Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyWrite, Intentions: PolicyWrite, }, - &ServiceRule{ + { Name: "football", Policy: PolicyDeny, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "foot", Policy: PolicyRead, Intentions: PolicyRead, }, - &ServiceRule{ + { Name: "fo", Policy: PolicyRead, Intentions: PolicyRead, }, }, Sessions: []*SessionRule{ - &SessionRule{ + { Node: "foo", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "football", Policy: PolicyDeny, }, }, SessionPrefixes: []*SessionRule{ - &SessionRule{ + { Node: "foot", Policy: PolicyRead, }, - &SessionRule{ + { Node: "fo", Policy: PolicyRead, }, }, Events: []*EventRule{ - &EventRule{ + { Event: "foo", Policy: PolicyWrite, }, - &EventRule{ + { Event: "football", Policy: PolicyDeny, }, }, EventPrefixes: []*EventRule{ - &EventRule{ + { Event: "foot", Policy: PolicyRead, }, - &EventRule{ + { Event: "fo", Policy: PolicyRead, }, }, PreparedQueries: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "football", Policy: PolicyDeny, }, }, PreparedQueryPrefixes: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "foot", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "fo", Policy: PolicyRead, }, @@ -1848,7 +1848,7 @@ func TestACL(t *testing.T) { name: "ACLRead", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ ACL: PolicyRead, }, @@ -1864,7 +1864,7 @@ func TestACL(t *testing.T) { name: "ACLRead", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ ACL: PolicyWrite, }, @@ -1880,36 +1880,36 @@ func TestACL(t *testing.T) { name: "KeyWritePrefixDefaultDeny", defaultPolicy: DenyAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ KeyPrefixes: []*KeyRule{ - &KeyRule{ + { Prefix: "fo", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "foo/", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "bar/", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "baz/", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "test/", Policy: PolicyWrite, }, }, Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo/bar", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "bar/baz", Policy: PolicyRead, }, @@ -1943,10 +1943,10 @@ func TestACL(t *testing.T) { name: "KeyWritePrefixDefaultAllow", defaultPolicy: AllowAll(), policyStack: []*Policy{ - &Policy{ + { PolicyRules: PolicyRules{ Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo/bar", Policy: PolicyRead, }, diff --git a/acl/authorizer_test.go b/acl/authorizer_test.go index f5227769db..8ce3ce5161 100644 --- a/acl/authorizer_test.go +++ b/acl/authorizer_test.go @@ -202,391 +202,391 @@ func TestACL_Enforce(t *testing.T) { } cases := []testCase{ - testCase{ + { method: "ACLRead", resource: ResourceACL, access: "read", ret: Deny, }, - testCase{ + { method: "ACLRead", resource: ResourceACL, access: "read", ret: Allow, }, - testCase{ + { method: "ACLWrite", resource: ResourceACL, access: "write", ret: Deny, }, - testCase{ + { method: "ACLWrite", resource: ResourceACL, access: "write", ret: Allow, }, - testCase{ + { resource: ResourceACL, access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "OperatorRead", resource: ResourceOperator, access: "read", ret: Deny, }, - testCase{ + { method: "OperatorRead", resource: ResourceOperator, access: "read", ret: Allow, }, - testCase{ + { method: "OperatorWrite", resource: ResourceOperator, access: "write", ret: Deny, }, - testCase{ + { method: "OperatorWrite", resource: ResourceOperator, access: "write", ret: Allow, }, - testCase{ + { resource: ResourceOperator, access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "KeyringRead", resource: ResourceKeyring, access: "read", ret: Deny, }, - testCase{ + { method: "KeyringRead", resource: ResourceKeyring, access: "read", ret: Allow, }, - testCase{ + { method: "KeyringWrite", resource: ResourceKeyring, access: "write", ret: Deny, }, - testCase{ + { method: "KeyringWrite", resource: ResourceKeyring, access: "write", ret: Allow, }, - testCase{ + { resource: ResourceKeyring, access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "AgentRead", resource: ResourceAgent, segment: "foo", access: "read", ret: Deny, }, - testCase{ + { method: "AgentRead", resource: ResourceAgent, segment: "foo", access: "read", ret: Allow, }, - testCase{ + { method: "AgentWrite", resource: ResourceAgent, segment: "foo", access: "write", ret: Deny, }, - testCase{ + { method: "AgentWrite", resource: ResourceAgent, segment: "foo", access: "write", ret: Allow, }, - testCase{ + { resource: ResourceAgent, segment: "foo", access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "EventRead", resource: ResourceEvent, segment: "foo", access: "read", ret: Deny, }, - testCase{ + { method: "EventRead", resource: ResourceEvent, segment: "foo", access: "read", ret: Allow, }, - testCase{ + { method: "EventWrite", resource: ResourceEvent, segment: "foo", access: "write", ret: Deny, }, - testCase{ + { method: "EventWrite", resource: ResourceEvent, segment: "foo", access: "write", ret: Allow, }, - testCase{ + { resource: ResourceEvent, segment: "foo", access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "IntentionRead", resource: ResourceIntention, segment: "foo", access: "read", ret: Deny, }, - testCase{ + { method: "IntentionRead", resource: ResourceIntention, segment: "foo", access: "read", ret: Allow, }, - testCase{ + { method: "IntentionWrite", resource: ResourceIntention, segment: "foo", access: "write", ret: Deny, }, - testCase{ + { method: "IntentionWrite", resource: ResourceIntention, segment: "foo", access: "write", ret: Allow, }, - testCase{ + { resource: ResourceIntention, segment: "foo", access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "NodeRead", resource: ResourceNode, segment: "foo", access: "read", ret: Deny, }, - testCase{ + { method: "NodeRead", resource: ResourceNode, segment: "foo", access: "read", ret: Allow, }, - testCase{ + { method: "NodeWrite", resource: ResourceNode, segment: "foo", access: "write", ret: Deny, }, - testCase{ + { method: "NodeWrite", resource: ResourceNode, segment: "foo", access: "write", ret: Allow, }, - testCase{ + { resource: ResourceNode, segment: "foo", access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "PreparedQueryRead", resource: ResourceQuery, segment: "foo", access: "read", ret: Deny, }, - testCase{ + { method: "PreparedQueryRead", resource: ResourceQuery, segment: "foo", access: "read", ret: Allow, }, - testCase{ + { method: "PreparedQueryWrite", resource: ResourceQuery, segment: "foo", access: "write", ret: Deny, }, - testCase{ + { method: "PreparedQueryWrite", resource: ResourceQuery, segment: "foo", access: "write", ret: Allow, }, - testCase{ + { resource: ResourceQuery, segment: "foo", access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "ServiceRead", resource: ResourceService, segment: "foo", access: "read", ret: Deny, }, - testCase{ + { method: "ServiceRead", resource: ResourceService, segment: "foo", access: "read", ret: Allow, }, - testCase{ + { method: "ServiceWrite", resource: ResourceService, segment: "foo", access: "write", ret: Deny, }, - testCase{ + { method: "ServiceWrite", resource: ResourceService, segment: "foo", access: "write", ret: Allow, }, - testCase{ + { resource: ResourceSession, segment: "foo", access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "SessionRead", resource: ResourceSession, segment: "foo", access: "read", ret: Deny, }, - testCase{ + { method: "SessionRead", resource: ResourceSession, segment: "foo", access: "read", ret: Allow, }, - testCase{ + { method: "SessionWrite", resource: ResourceSession, segment: "foo", access: "write", ret: Deny, }, - testCase{ + { method: "SessionWrite", resource: ResourceSession, segment: "foo", access: "write", ret: Allow, }, - testCase{ + { resource: ResourceSession, segment: "foo", access: "list", ret: Deny, err: "Invalid access level", }, - testCase{ + { method: "KeyRead", resource: ResourceKey, segment: "foo", access: "read", ret: Deny, }, - testCase{ + { method: "KeyRead", resource: ResourceKey, segment: "foo", access: "read", ret: Allow, }, - testCase{ + { method: "KeyWrite", resource: ResourceKey, segment: "foo", access: "write", ret: Deny, }, - testCase{ + { method: "KeyWrite", resource: ResourceKey, segment: "foo", access: "write", ret: Allow, }, - testCase{ + { method: "KeyList", resource: ResourceKey, segment: "foo", access: "list", ret: Deny, }, - testCase{ + { method: "KeyList", resource: ResourceKey, segment: "foo", access: "list", ret: Allow, }, - testCase{ + { resource: ResourceKey, segment: "foo", access: "deny", ret: Deny, err: "Invalid access level", }, - testCase{ + { resource: "not-a-real-resource", access: "read", ret: Deny, diff --git a/acl/policy_authorizer_test.go b/acl/policy_authorizer_test.go index 0318c5d791..0f074e49aa 100644 --- a/acl/policy_authorizer_test.go +++ b/acl/policy_authorizer_test.go @@ -30,7 +30,7 @@ func TestPolicyAuthorizer(t *testing.T) { // This test ensures that if the policy doesn't define a rule then the policy authorizer will // return no concrete enforcement decision. This allows deferring to some defaults in another // authorizer including usage of a default overall policy of "deny" - "Defaults": aclTest{ + "Defaults": { policy: &Policy{}, checks: []aclCheck{ {name: "DefaultACLRead", prefix: "foo", check: checkDefaultACLRead}, @@ -61,147 +61,147 @@ func TestPolicyAuthorizer(t *testing.T) { {name: "DefaultSnapshot", prefix: "foo", check: checkDefaultSnapshot}, }, }, - "Prefer Exact Matches": aclTest{ + "Prefer Exact Matches": { policy: &Policy{PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "foo", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "football", Policy: PolicyDeny, }, }, AgentPrefixes: []*AgentRule{ - &AgentRule{ + { Node: "foot", Policy: PolicyRead, }, - &AgentRule{ + { Node: "fo", Policy: PolicyRead, }, }, Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "football", Policy: PolicyDeny, }, }, KeyPrefixes: []*KeyRule{ - &KeyRule{ + { Prefix: "foot", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "fo", Policy: PolicyRead, }, }, Nodes: []*NodeRule{ - &NodeRule{ + { Name: "foo", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "football", Policy: PolicyDeny, }, }, NodePrefixes: []*NodeRule{ - &NodeRule{ + { Name: "foot", Policy: PolicyRead, }, - &NodeRule{ + { Name: "fo", Policy: PolicyRead, }, }, Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyWrite, Intentions: PolicyWrite, }, - &ServiceRule{ + { Name: "football", Policy: PolicyDeny, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "foot", Policy: PolicyRead, Intentions: PolicyRead, }, - &ServiceRule{ + { Name: "fo", Policy: PolicyRead, Intentions: PolicyRead, }, }, Sessions: []*SessionRule{ - &SessionRule{ + { Node: "foo", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "football", Policy: PolicyDeny, }, }, SessionPrefixes: []*SessionRule{ - &SessionRule{ + { Node: "foot", Policy: PolicyRead, }, - &SessionRule{ + { Node: "fo", Policy: PolicyRead, }, }, Events: []*EventRule{ - &EventRule{ + { Event: "foo", Policy: PolicyWrite, }, - &EventRule{ + { Event: "football", Policy: PolicyDeny, }, }, EventPrefixes: []*EventRule{ - &EventRule{ + { Event: "foot", Policy: PolicyRead, }, - &EventRule{ + { Event: "fo", Policy: PolicyRead, }, }, PreparedQueries: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "football", Policy: PolicyDeny, }, }, PreparedQueryPrefixes: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "foot", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "fo", Policy: PolicyRead, }, @@ -344,17 +344,17 @@ func TestPolicyAuthorizer(t *testing.T) { {name: "PreparedQueryWriteDenied", prefix: "football", check: checkDenyPreparedQueryWrite}, }, }, - "Intention Wildcards - prefix denied": aclTest{ + "Intention Wildcards - prefix denied": { policy: &Policy{PolicyRules: PolicyRules{ Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyWrite, Intentions: PolicyWrite, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "", Policy: PolicyDeny, Intentions: PolicyDeny, @@ -366,17 +366,17 @@ func TestPolicyAuthorizer(t *testing.T) { {name: "AllDenied", prefix: "*", check: checkDenyIntentionWrite}, }, }, - "Intention Wildcards - prefix allowed": aclTest{ + "Intention Wildcards - prefix allowed": { policy: &Policy{PolicyRules: PolicyRules{ Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyWrite, Intentions: PolicyDeny, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "", Policy: PolicyWrite, Intentions: PolicyWrite, @@ -388,17 +388,17 @@ func TestPolicyAuthorizer(t *testing.T) { {name: "AllDenied", prefix: "*", check: checkDenyIntentionWrite}, }, }, - "Intention Wildcards - all allowed": aclTest{ + "Intention Wildcards - all allowed": { policy: &Policy{PolicyRules: PolicyRules{ Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyWrite, Intentions: PolicyWrite, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "", Policy: PolicyWrite, Intentions: PolicyWrite, @@ -410,10 +410,10 @@ func TestPolicyAuthorizer(t *testing.T) { {name: "AllAllowed", prefix: "*", check: checkAllowIntentionWrite}, }, }, - "Intention Wildcards - all default": aclTest{ + "Intention Wildcards - all default": { policy: &Policy{PolicyRules: PolicyRules{ Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyWrite, Intentions: PolicyWrite, @@ -425,10 +425,10 @@ func TestPolicyAuthorizer(t *testing.T) { {name: "AllDefault", prefix: "*", check: checkDefaultIntentionWrite}, }, }, - "Intention Wildcards - any default": aclTest{ + "Intention Wildcards - any default": { policy: &Policy{PolicyRules: PolicyRules{ Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyWrite, Intentions: PolicyDeny, @@ -484,21 +484,21 @@ func TestAnyAllowed(t *testing.T) { } cases := map[string]testCase{ - "no-rules-default": testCase{ + "no-rules-default": { readEnforcement: Default, listEnforcement: Default, writeEnforcement: Default, }, - "prefix-write-allowed": testCase{ + "prefix-write-allowed": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, }, }, // this shouldn't affect whether anyAllowed returns things are allowed - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, @@ -509,9 +509,9 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Allow, }, - "prefix-list-allowed": testCase{ + "prefix-list-allowed": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessList}, @@ -522,9 +522,9 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Deny, }, - "prefix-read-allowed": testCase{ + "prefix-read-allowed": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessRead}, @@ -535,9 +535,9 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-deny": testCase{ + "prefix-deny": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, @@ -548,15 +548,15 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-deny-other-write-prefix": testCase{ + "prefix-deny-other-write-prefix": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, @@ -567,15 +567,15 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Allow, }, - "prefix-deny-other-write-exact": testCase{ + "prefix-deny-other-write-exact": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ exact: &policyAuthorizerRule{access: AccessWrite}, @@ -586,15 +586,15 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Allow, }, - "prefix-deny-other-list-prefix": testCase{ + "prefix-deny-other-list-prefix": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessList}, @@ -605,15 +605,15 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Deny, }, - "prefix-deny-other-list-exact": testCase{ + "prefix-deny-other-list-exact": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ exact: &policyAuthorizerRule{access: AccessList}, @@ -624,15 +624,15 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Deny, }, - "prefix-deny-other-read-prefix": testCase{ + "prefix-deny-other-read-prefix": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessRead}, @@ -643,15 +643,15 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-deny-other-read-exact": testCase{ + "prefix-deny-other-read-exact": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ exact: &policyAuthorizerRule{access: AccessRead}, @@ -662,15 +662,15 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-deny-other-deny-prefix": testCase{ + "prefix-deny-other-deny-prefix": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, @@ -681,15 +681,15 @@ func TestAnyAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-deny-other-deny-exact": testCase{ + "prefix-deny-other-deny-exact": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ exact: &policyAuthorizerRule{access: AccessDeny}, @@ -735,14 +735,14 @@ func TestAllAllowed(t *testing.T) { } cases := map[string]testCase{ - "no-rules-default": testCase{ + "no-rules-default": { readEnforcement: Default, listEnforcement: Default, writeEnforcement: Default, }, - "prefix-write-allowed": testCase{ + "prefix-write-allowed": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, @@ -753,9 +753,9 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Allow, }, - "prefix-list-allowed": testCase{ + "prefix-list-allowed": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessList}, @@ -766,9 +766,9 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Deny, }, - "prefix-read-allowed": testCase{ + "prefix-read-allowed": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessRead}, @@ -779,9 +779,9 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-deny": testCase{ + "prefix-deny": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, @@ -792,15 +792,15 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-allow-other-write-prefix": testCase{ + "prefix-allow-other-write-prefix": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, @@ -811,15 +811,15 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Allow, }, - "prefix-allow-other-write-exact": testCase{ + "prefix-allow-other-write-exact": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ exact: &policyAuthorizerRule{access: AccessWrite}, @@ -830,15 +830,15 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Allow, }, - "prefix-allow-other-list-prefix": testCase{ + "prefix-allow-other-list-prefix": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessList}, @@ -849,15 +849,15 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Deny, }, - "prefix-allow-other-list-exact": testCase{ + "prefix-allow-other-list-exact": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ exact: &policyAuthorizerRule{access: AccessList}, @@ -868,15 +868,15 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Allow, writeEnforcement: Deny, }, - "prefix-allow-other-read-prefix": testCase{ + "prefix-allow-other-read-prefix": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessRead}, @@ -887,15 +887,15 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-allow-other-read-exact": testCase{ + "prefix-allow-other-read-exact": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ exact: &policyAuthorizerRule{access: AccessRead}, @@ -906,15 +906,15 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-allow-other-deny-prefix": testCase{ + "prefix-allow-other-deny-prefix": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessDeny}, @@ -925,15 +925,15 @@ func TestAllAllowed(t *testing.T) { listEnforcement: Deny, writeEnforcement: Deny, }, - "prefix-allow-other-deny-exact": testCase{ + "prefix-allow-other-deny-exact": { insertions: []radixInsertion{ - radixInsertion{ + { segment: "", value: &policyAuthorizerRadixLeaf{ prefix: &policyAuthorizerRule{access: AccessWrite}, }, }, - radixInsertion{ + { segment: "foo", value: &policyAuthorizerRadixLeaf{ exact: &policyAuthorizerRule{access: AccessDeny}, diff --git a/acl/policy_test.go b/acl/policy_test.go index 2f8bbca0ce..fd0f4745e4 100644 --- a/acl/policy_test.go +++ b/acl/policy_test.go @@ -89,93 +89,93 @@ func TestPolicySourceParse(t *testing.T) { `} `), &Policy{PolicyRules: PolicyRules{ AgentPrefixes: []*AgentRule{ - &AgentRule{ + { Node: "foo", Policy: PolicyRead, }, - &AgentRule{ + { Node: "bar", Policy: PolicyWrite, }, }, EventPrefixes: []*EventRule{ - &EventRule{ + { Event: "", Policy: PolicyRead, }, - &EventRule{ + { Event: "foo", Policy: PolicyWrite, }, - &EventRule{ + { Event: "bar", Policy: PolicyDeny, }, }, Keyring: PolicyDeny, KeyPrefixes: []*KeyRule{ - &KeyRule{ + { Prefix: "", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "foo/", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "foo/bar/", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "foo/bar/baz", Policy: PolicyDeny, }, }, NodePrefixes: []*NodeRule{ - &NodeRule{ + { Name: "", Policy: PolicyRead, }, - &NodeRule{ + { Name: "foo", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "bar", Policy: PolicyDeny, }, }, Operator: PolicyDeny, PreparedQueryPrefixes: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "bar", Policy: PolicyDeny, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "", Policy: PolicyWrite, }, - &ServiceRule{ + { Name: "foo", Policy: PolicyRead, }, }, SessionPrefixes: []*SessionRule{ - &SessionRule{ + { Node: "foo", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "bar", Policy: PolicyDeny, }, @@ -264,93 +264,93 @@ func TestPolicySourceParse(t *testing.T) { `} `), &Policy{PolicyRules: PolicyRules{ AgentPrefixes: []*AgentRule{ - &AgentRule{ + { Node: "foo", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "bar", Policy: PolicyDeny, }, }, EventPrefixes: []*EventRule{ - &EventRule{ + { Event: "", Policy: PolicyRead, }, - &EventRule{ + { Event: "foo", Policy: PolicyWrite, }, - &EventRule{ + { Event: "bar", Policy: PolicyDeny, }, }, Keyring: PolicyDeny, KeyPrefixes: []*KeyRule{ - &KeyRule{ + { Prefix: "", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "foo/", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "foo/bar/", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "foo/bar/baz", Policy: PolicyDeny, }, }, NodePrefixes: []*NodeRule{ - &NodeRule{ + { Name: "", Policy: PolicyRead, }, - &NodeRule{ + { Name: "foo", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "bar", Policy: PolicyDeny, }, }, Operator: PolicyDeny, PreparedQueryPrefixes: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "bar", Policy: PolicyDeny, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "", Policy: PolicyWrite, }, - &ServiceRule{ + { Name: "foo", Policy: PolicyRead, }, }, SessionPrefixes: []*SessionRule{ - &SessionRule{ + { Node: "foo", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "bar", Policy: PolicyDeny, }, @@ -565,53 +565,53 @@ func TestMergePolicies(t *testing.T) { { name: "Agents", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "foo", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "bar", Policy: PolicyRead, }, - &AgentRule{ + { Node: "baz", Policy: PolicyWrite, }, }, AgentPrefixes: []*AgentRule{ - &AgentRule{ + { Node: "000", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "111", Policy: PolicyRead, }, - &AgentRule{ + { Node: "222", Policy: PolicyWrite, }, }, }}, - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "foo", Policy: PolicyRead, }, - &AgentRule{ + { Node: "baz", Policy: PolicyDeny, }, }, AgentPrefixes: []*AgentRule{ - &AgentRule{ + { Node: "000", Policy: PolicyRead, }, - &AgentRule{ + { Node: "222", Policy: PolicyDeny, }, @@ -620,29 +620,29 @@ func TestMergePolicies(t *testing.T) { }}, expected: &Policy{PolicyRules: PolicyRules{ Agents: []*AgentRule{ - &AgentRule{ + { Node: "foo", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "bar", Policy: PolicyRead, }, - &AgentRule{ + { Node: "baz", Policy: PolicyDeny, }, }, AgentPrefixes: []*AgentRule{ - &AgentRule{ + { Node: "000", Policy: PolicyWrite, }, - &AgentRule{ + { Node: "111", Policy: PolicyRead, }, - &AgentRule{ + { Node: "222", Policy: PolicyDeny, }, @@ -652,53 +652,53 @@ func TestMergePolicies(t *testing.T) { { name: "Events", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Events: []*EventRule{ - &EventRule{ + { Event: "foo", Policy: PolicyWrite, }, - &EventRule{ + { Event: "bar", Policy: PolicyRead, }, - &EventRule{ + { Event: "baz", Policy: PolicyWrite, }, }, EventPrefixes: []*EventRule{ - &EventRule{ + { Event: "000", Policy: PolicyWrite, }, - &EventRule{ + { Event: "111", Policy: PolicyRead, }, - &EventRule{ + { Event: "222", Policy: PolicyWrite, }, }, }}, - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Events: []*EventRule{ - &EventRule{ + { Event: "foo", Policy: PolicyRead, }, - &EventRule{ + { Event: "baz", Policy: PolicyDeny, }, }, EventPrefixes: []*EventRule{ - &EventRule{ + { Event: "000", Policy: PolicyRead, }, - &EventRule{ + { Event: "222", Policy: PolicyDeny, }, @@ -707,29 +707,29 @@ func TestMergePolicies(t *testing.T) { }, expected: &Policy{PolicyRules: PolicyRules{ Events: []*EventRule{ - &EventRule{ + { Event: "foo", Policy: PolicyWrite, }, - &EventRule{ + { Event: "bar", Policy: PolicyRead, }, - &EventRule{ + { Event: "baz", Policy: PolicyDeny, }, }, EventPrefixes: []*EventRule{ - &EventRule{ + { Event: "000", Policy: PolicyWrite, }, - &EventRule{ + { Event: "111", Policy: PolicyRead, }, - &EventRule{ + { Event: "222", Policy: PolicyDeny, }, @@ -739,53 +739,53 @@ func TestMergePolicies(t *testing.T) { { name: "Node", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Nodes: []*NodeRule{ - &NodeRule{ + { Name: "foo", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "bar", Policy: PolicyRead, }, - &NodeRule{ + { Name: "baz", Policy: PolicyWrite, }, }, NodePrefixes: []*NodeRule{ - &NodeRule{ + { Name: "000", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "111", Policy: PolicyRead, }, - &NodeRule{ + { Name: "222", Policy: PolicyWrite, }, }, }}, - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Nodes: []*NodeRule{ - &NodeRule{ + { Name: "foo", Policy: PolicyRead, }, - &NodeRule{ + { Name: "baz", Policy: PolicyDeny, }, }, NodePrefixes: []*NodeRule{ - &NodeRule{ + { Name: "000", Policy: PolicyRead, }, - &NodeRule{ + { Name: "222", Policy: PolicyDeny, }, @@ -794,29 +794,29 @@ func TestMergePolicies(t *testing.T) { }}, expected: &Policy{PolicyRules: PolicyRules{ Nodes: []*NodeRule{ - &NodeRule{ + { Name: "foo", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "bar", Policy: PolicyRead, }, - &NodeRule{ + { Name: "baz", Policy: PolicyDeny, }, }, NodePrefixes: []*NodeRule{ - &NodeRule{ + { Name: "000", Policy: PolicyWrite, }, - &NodeRule{ + { Name: "111", Policy: PolicyRead, }, - &NodeRule{ + { Name: "222", Policy: PolicyDeny, }, @@ -826,69 +826,69 @@ func TestMergePolicies(t *testing.T) { { name: "Keys", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "bar", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "baz", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "zoo", Policy: PolicyList, }, }, KeyPrefixes: []*KeyRule{ - &KeyRule{ + { Prefix: "000", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "111", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "222", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "333", Policy: PolicyList, }, }, }}, - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "baz", Policy: PolicyDeny, }, - &KeyRule{ + { Prefix: "zoo", Policy: PolicyRead, }, }, KeyPrefixes: []*KeyRule{ - &KeyRule{ + { Prefix: "000", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "222", Policy: PolicyDeny, }, - &KeyRule{ + { Prefix: "333", Policy: PolicyRead, }, @@ -897,37 +897,37 @@ func TestMergePolicies(t *testing.T) { }, expected: &Policy{PolicyRules: PolicyRules{ Keys: []*KeyRule{ - &KeyRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "bar", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "baz", Policy: PolicyDeny, }, - &KeyRule{ + { Prefix: "zoo", Policy: PolicyList, }, }, KeyPrefixes: []*KeyRule{ - &KeyRule{ + { Prefix: "000", Policy: PolicyWrite, }, - &KeyRule{ + { Prefix: "111", Policy: PolicyRead, }, - &KeyRule{ + { Prefix: "222", Policy: PolicyDeny, }, - &KeyRule{ + { Prefix: "333", Policy: PolicyList, }, @@ -937,62 +937,62 @@ func TestMergePolicies(t *testing.T) { { name: "Services", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyWrite, Intentions: PolicyWrite, }, - &ServiceRule{ + { Name: "bar", Policy: PolicyRead, Intentions: PolicyRead, }, - &ServiceRule{ + { Name: "baz", Policy: PolicyWrite, Intentions: PolicyWrite, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "000", Policy: PolicyWrite, Intentions: PolicyWrite, }, - &ServiceRule{ + { Name: "111", Policy: PolicyRead, Intentions: PolicyRead, }, - &ServiceRule{ + { Name: "222", Policy: PolicyWrite, Intentions: PolicyWrite, }, }, }}, - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyRead, Intentions: PolicyRead, }, - &ServiceRule{ + { Name: "baz", Policy: PolicyDeny, Intentions: PolicyDeny, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "000", Policy: PolicyRead, Intentions: PolicyRead, }, - &ServiceRule{ + { Name: "222", Policy: PolicyDeny, Intentions: PolicyDeny, @@ -1002,34 +1002,34 @@ func TestMergePolicies(t *testing.T) { }, expected: &Policy{PolicyRules: PolicyRules{ Services: []*ServiceRule{ - &ServiceRule{ + { Name: "foo", Policy: PolicyWrite, Intentions: PolicyWrite, }, - &ServiceRule{ + { Name: "bar", Policy: PolicyRead, Intentions: PolicyRead, }, - &ServiceRule{ + { Name: "baz", Policy: PolicyDeny, Intentions: PolicyDeny, }, }, ServicePrefixes: []*ServiceRule{ - &ServiceRule{ + { Name: "000", Policy: PolicyWrite, Intentions: PolicyWrite, }, - &ServiceRule{ + { Name: "111", Policy: PolicyRead, Intentions: PolicyRead, }, - &ServiceRule{ + { Name: "222", Policy: PolicyDeny, Intentions: PolicyDeny, @@ -1040,53 +1040,53 @@ func TestMergePolicies(t *testing.T) { { name: "Sessions", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Sessions: []*SessionRule{ - &SessionRule{ + { Node: "foo", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "bar", Policy: PolicyRead, }, - &SessionRule{ + { Node: "baz", Policy: PolicyWrite, }, }, SessionPrefixes: []*SessionRule{ - &SessionRule{ + { Node: "000", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "111", Policy: PolicyRead, }, - &SessionRule{ + { Node: "222", Policy: PolicyWrite, }, }, }}, - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ Sessions: []*SessionRule{ - &SessionRule{ + { Node: "foo", Policy: PolicyRead, }, - &SessionRule{ + { Node: "baz", Policy: PolicyDeny, }, }, SessionPrefixes: []*SessionRule{ - &SessionRule{ + { Node: "000", Policy: PolicyRead, }, - &SessionRule{ + { Node: "222", Policy: PolicyDeny, }, @@ -1095,29 +1095,29 @@ func TestMergePolicies(t *testing.T) { }, expected: &Policy{PolicyRules: PolicyRules{ Sessions: []*SessionRule{ - &SessionRule{ + { Node: "foo", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "bar", Policy: PolicyRead, }, - &SessionRule{ + { Node: "baz", Policy: PolicyDeny, }, }, SessionPrefixes: []*SessionRule{ - &SessionRule{ + { Node: "000", Policy: PolicyWrite, }, - &SessionRule{ + { Node: "111", Policy: PolicyRead, }, - &SessionRule{ + { Node: "222", Policy: PolicyDeny, }, @@ -1127,53 +1127,53 @@ func TestMergePolicies(t *testing.T) { { name: "Prepared Queries", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ PreparedQueries: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "bar", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "baz", Policy: PolicyWrite, }, }, PreparedQueryPrefixes: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "000", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "111", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "222", Policy: PolicyWrite, }, }, }}, - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ PreparedQueries: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "foo", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "baz", Policy: PolicyDeny, }, }, PreparedQueryPrefixes: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "000", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "222", Policy: PolicyDeny, }, @@ -1182,29 +1182,29 @@ func TestMergePolicies(t *testing.T) { }, expected: &Policy{PolicyRules: PolicyRules{ PreparedQueries: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "foo", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "bar", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "baz", Policy: PolicyDeny, }, }, PreparedQueryPrefixes: []*PreparedQueryRule{ - &PreparedQueryRule{ + { Prefix: "000", Policy: PolicyWrite, }, - &PreparedQueryRule{ + { Prefix: "111", Policy: PolicyRead, }, - &PreparedQueryRule{ + { Prefix: "222", Policy: PolicyDeny, }, @@ -1214,12 +1214,12 @@ func TestMergePolicies(t *testing.T) { { name: "Write Precedence", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ ACL: PolicyRead, Keyring: PolicyRead, Operator: PolicyRead, }}, - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ ACL: PolicyWrite, Keyring: PolicyWrite, Operator: PolicyWrite, @@ -1234,12 +1234,12 @@ func TestMergePolicies(t *testing.T) { { name: "Deny Precedence", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ ACL: PolicyWrite, Keyring: PolicyWrite, Operator: PolicyWrite, }}, - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ ACL: PolicyDeny, Keyring: PolicyDeny, Operator: PolicyDeny, @@ -1254,12 +1254,12 @@ func TestMergePolicies(t *testing.T) { { name: "Read Precedence", input: []*Policy{ - &Policy{PolicyRules: PolicyRules{ + {PolicyRules: PolicyRules{ ACL: PolicyRead, Keyring: PolicyRead, Operator: PolicyRead, }}, - &Policy{}, + {}, }, expected: &Policy{PolicyRules: PolicyRules{ ACL: PolicyRead, diff --git a/agent/acl.go b/agent/acl.go index 71aee6c209..f7f022ee63 100644 --- a/agent/acl.go +++ b/agent/acl.go @@ -68,13 +68,13 @@ func (a *Agent) initializeACLs() error { policy := &acl.Policy{ PolicyRules: acl.PolicyRules{ Agents: []*acl.AgentRule{ - &acl.AgentRule{ + { Node: a.config.NodeName, Policy: acl.PolicyWrite, }, }, NodePrefixes: []*acl.NodeRule{ - &acl.NodeRule{ + { Name: "", Policy: acl.PolicyRead, }, diff --git a/agent/acl_endpoint_test.go b/agent/acl_endpoint_test.go index 1835444fee..ea2c9b1468 100644 --- a/agent/acl_endpoint_test.go +++ b/agent/acl_endpoint_test.go @@ -399,17 +399,17 @@ func TestACL_HTTP(t *testing.T) { Name: "test", Description: "test", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLRolePolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, }, NodeIdentities: []*structs.ACLNodeIdentity{ - &structs.ACLNodeIdentity{ + { NodeName: "web-node", Datacenter: "foo", }, @@ -443,7 +443,7 @@ func TestACL_HTTP(t *testing.T) { roleInput := &structs.ACLRole{ Name: "service-id-web", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "web", }, }, @@ -477,7 +477,7 @@ func TestACL_HTTP(t *testing.T) { Name: "test", Description: "test", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "db", }, }, @@ -505,12 +505,12 @@ func TestACL_HTTP(t *testing.T) { Name: "test", Description: "test", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "web-indexer", }, }, NodeIdentities: []*structs.ACLNodeIdentity{ - &structs.ACLNodeIdentity{ + { NodeName: "web-node", Datacenter: "foo", }, @@ -547,7 +547,7 @@ func TestACL_HTTP(t *testing.T) { Name: "with-id", Description: "test", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "foobar", }, }, @@ -628,17 +628,17 @@ func TestACL_HTTP(t *testing.T) { tokenInput := &structs.ACLToken{ Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, }, NodeIdentities: []*structs.ACLNodeIdentity{ - &structs.ACLNodeIdentity{ + { NodeName: "foo", Datacenter: "bar", }, @@ -671,11 +671,11 @@ func TestACL_HTTP(t *testing.T) { tokenInput := &structs.ACLToken{ Description: "local", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -757,13 +757,13 @@ func TestACL_HTTP(t *testing.T) { tokenInput := &structs.ACLToken{ Description: "Better description for this cloned token", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, }, NodeIdentities: []*structs.ACLNodeIdentity{ - &structs.ACLNodeIdentity{ + { NodeName: "foo", Datacenter: "bar", }, @@ -808,7 +808,7 @@ func TestACL_HTTP(t *testing.T) { AccessorID: "e8aeb69a-0ace-42b9-b95f-d1d9eafe1561", Description: "Better description for this cloned token", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -879,11 +879,11 @@ func TestACL_HTTP(t *testing.T) { AccessorID: "56e8e6a3-708b-4a2f-8ab3-b973cce39108", Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -917,11 +917,11 @@ func TestACL_HTTP(t *testing.T) { SecretID: "4e3efd15-d06c-442e-a7cc-1744f55c8dea", Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -956,11 +956,11 @@ func TestACL_HTTP(t *testing.T) { SecretID: "10126ffa-b28f-4137-b9a9-e89ab1e97c5b", Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -994,11 +994,11 @@ func TestACL_HTTP(t *testing.T) { AccessorID: "dee863fa-e548-4c61-a96f-9aa07999249f", Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -1016,11 +1016,11 @@ func TestACL_HTTP(t *testing.T) { SecretID: "dee863fa-e548-4c61-a96f-9aa07999249f", Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -1038,11 +1038,11 @@ func TestACL_HTTP(t *testing.T) { SecretID: "10126ffa-b28f-4137-b9a9-e89ab1e97c5b", Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -1060,11 +1060,11 @@ func TestACL_HTTP(t *testing.T) { AccessorID: "10126ffa-b28f-4137-b9a9-e89ab1e97c5b", Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -1082,11 +1082,11 @@ func TestACL_HTTP(t *testing.T) { AccessorID: "00000000-0000-0000-0000-00000000005b", Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -1104,11 +1104,11 @@ func TestACL_HTTP(t *testing.T) { SecretID: "00000000-0000-0000-0000-00000000005b", Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-test"], Name: policyMap[idMap["policy-test"]].Name, }, - structs.ACLTokenPolicyLink{ + { ID: idMap["policy-read-all-nodes"], Name: policyMap[idMap["policy-read-all-nodes"]].Name, }, @@ -1807,7 +1807,7 @@ func TestACL_Authorize(t *testing.T) { tokenReq := structs.ACLTokenSetRequest{ ACLToken: structs.ACLToken{ Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: policy.ID, }, }, @@ -1839,7 +1839,7 @@ func TestACL_Authorize(t *testing.T) { localTokenReq := structs.ACLTokenSetRequest{ ACLToken: structs.ACLToken{ Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: policy.ID, }, }, @@ -1854,111 +1854,111 @@ func TestACL_Authorize(t *testing.T) { t.Run("master-token", func(t *testing.T) { request := []structs.ACLAuthorizationRequest{ - structs.ACLAuthorizationRequest{ + { Resource: "acl", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "acl", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "agent", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "agent", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "event", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "event", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "intention", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "intention", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "key", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "key", Segment: "foo", Access: "list", }, - structs.ACLAuthorizationRequest{ + { Resource: "key", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "keyring", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "keyring", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "node", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "node", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "operator", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "operator", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "query", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "query", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "service", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "service", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "session", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "session", Segment: "foo", Access: "write", @@ -1988,111 +1988,111 @@ func TestACL_Authorize(t *testing.T) { }) customAuthorizationRequests := []structs.ACLAuthorizationRequest{ - structs.ACLAuthorizationRequest{ + { Resource: "acl", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "acl", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "agent", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "agent", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "event", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "event", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "intention", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "intention", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "key", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "key", Segment: "foo", Access: "list", }, - structs.ACLAuthorizationRequest{ + { Resource: "key", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "keyring", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "keyring", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "node", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "node", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "operator", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "operator", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "query", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "query", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "service", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "service", Segment: "foo", Access: "write", }, - structs.ACLAuthorizationRequest{ + { Resource: "session", Segment: "foo", Access: "read", }, - structs.ACLAuthorizationRequest{ + { Resource: "session", Segment: "foo", Access: "write", @@ -2176,7 +2176,7 @@ func TestACL_Authorize(t *testing.T) { t.Run("acl-not-found", func(t *testing.T) { request := []structs.ACLAuthorizationRequest{ - structs.ACLAuthorizationRequest{ + { Resource: "acl", Access: "read", }, @@ -2212,7 +2212,7 @@ func TestACL_Authorize(t *testing.T) { t.Run("local-token-wrong-dc", func(t *testing.T) { request := []structs.ACLAuthorizationRequest{ - structs.ACLAuthorizationRequest{ + { Resource: "acl", Access: "read", }, diff --git a/agent/acl_test.go b/agent/acl_test.go index bb95d4a751..c9ef16f8f6 100644 --- a/agent/acl_test.go +++ b/agent/acl_test.go @@ -479,9 +479,9 @@ func TestACL_filterMembers(t *testing.T) { require.Len(t, members, 0) members = []serf.Member{ - serf.Member{Name: "Node 1"}, - serf.Member{Name: "Nope"}, - serf.Member{Name: "Node 2"}, + {Name: "Node 1"}, + {Name: "Nope"}, + {Name: "Node 2"}, } require.NoError(t, a.filterMembers(nodeROSecret, &members)) require.Len(t, members, 2) diff --git a/agent/agent_endpoint_test.go b/agent/agent_endpoint_test.go index c91c1d49cf..b50153c6d0 100644 --- a/agent/agent_endpoint_test.go +++ b/agent/agent_endpoint_test.go @@ -386,7 +386,7 @@ func TestAgent_Service(t *testing.T) { Warning: 1, }, TaggedAddresses: map[string]api.ServiceAddress{ - "wan": api.ServiceAddress{ + "wan": { Address: "198.18.0.1", Port: 1818, }, @@ -2254,7 +2254,7 @@ func TestAgent_RegisterCheck_ACLDeny(t *testing.T) { tokenReq := &structs.ACLToken{ Description: "write-foo", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { Name: "write-foo", }, }, @@ -2272,7 +2272,7 @@ func TestAgent_RegisterCheck_ACLDeny(t *testing.T) { tokenReq = &structs.ACLToken{ Description: "write-node", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { Name: "write-node", }, }, @@ -2565,9 +2565,9 @@ func TestAgent_UpdateCheck(t *testing.T) { } cases := []checkUpdate{ - checkUpdate{api.HealthPassing, "hello-passing"}, - checkUpdate{api.HealthCritical, "hello-critical"}, - checkUpdate{api.HealthWarning, "hello-warning"}, + {api.HealthPassing, "hello-passing"}, + {api.HealthCritical, "hello-critical"}, + {api.HealthWarning, "hello-warning"}, } for _, c := range cases { @@ -2692,10 +2692,10 @@ func testAgent_RegisterService(t *testing.T, extraHCL string) { TTL: 15 * time.Second, }, Checks: []*structs.CheckType{ - &structs.CheckType{ + { TTL: 20 * time.Second, }, - &structs.CheckType{ + { TTL: 30 * time.Second, }, }, @@ -2775,11 +2775,11 @@ func testAgent_RegisterService_ReRegister(t *testing.T, extraHCL string) { Tags: []string{"master"}, Port: 8000, Checks: []*structs.CheckType{ - &structs.CheckType{ + { CheckID: types.CheckID("check_1"), TTL: 20 * time.Second, }, - &structs.CheckType{ + { CheckID: types.CheckID("check_2"), TTL: 30 * time.Second, }, @@ -2799,11 +2799,11 @@ func testAgent_RegisterService_ReRegister(t *testing.T, extraHCL string) { Tags: []string{"master"}, Port: 8000, Checks: []*structs.CheckType{ - &structs.CheckType{ + { CheckID: types.CheckID("check_1"), TTL: 20 * time.Second, }, - &structs.CheckType{ + { CheckID: types.CheckID("check_3"), TTL: 30 * time.Second, }, @@ -2850,12 +2850,12 @@ func testAgent_RegisterService_ReRegister_ReplaceExistingChecks(t *testing.T, ex Tags: []string{"master"}, Port: 8000, Checks: []*structs.CheckType{ - &structs.CheckType{ + { // explicitly not setting the check id to let it be auto-generated // we want to ensure that we are testing out the cases with autogenerated names/ids TTL: 20 * time.Second, }, - &structs.CheckType{ + { CheckID: types.CheckID("check_2"), TTL: 30 * time.Second, }, @@ -2875,10 +2875,10 @@ func testAgent_RegisterService_ReRegister_ReplaceExistingChecks(t *testing.T, ex Tags: []string{"master"}, Port: 8000, Checks: []*structs.CheckType{ - &structs.CheckType{ + { TTL: 20 * time.Second, }, - &structs.CheckType{ + { CheckID: types.CheckID("check_3"), TTL: 30 * time.Second, }, @@ -3144,10 +3144,10 @@ func testAgent_RegisterService_ACLDeny(t *testing.T, extraHCL string) { TTL: 15 * time.Second, }, Checks: []*structs.CheckType{ - &structs.CheckType{ + { TTL: 20 * time.Second, }, - &structs.CheckType{ + { TTL: 30 * time.Second, }, }, @@ -3312,7 +3312,7 @@ func testCreateToken(t *testing.T, a *TestAgent, rules string) string { args := map[string]interface{}{ "Description": "User Token", "Policies": []map[string]interface{}{ - map[string]interface{}{ + { "ID": policyID, }, }, @@ -4615,7 +4615,7 @@ func TestAgent_TokenTriggersFullSync(t *testing.T) { token := &structs.ACLToken{ Description: "test", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{Name: policyName}, + {Name: policyName}, }, } diff --git a/agent/agent_test.go b/agent/agent_test.go index dbdd37590f..227caee1bb 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -401,7 +401,7 @@ func testAgent_AddService(t *testing.T, extraHCL string) { } }, []*structs.CheckType{ - &structs.CheckType{ + { CheckID: "check1", Name: "name1", TTL: time.Minute, @@ -409,7 +409,7 @@ func testAgent_AddService(t *testing.T, extraHCL string) { }, }, map[string]*structs.HealthCheck{ - "check1": &structs.HealthCheck{ + "check1": { Node: "node1", CheckID: "check1", Name: "name1", @@ -438,26 +438,26 @@ func testAgent_AddService(t *testing.T, extraHCL string) { }, nil, // No change expected []*structs.CheckType{ - &structs.CheckType{ + { CheckID: "check1", Name: "name1", TTL: time.Minute, Notes: "note1", }, - &structs.CheckType{ + { CheckID: "check-noname", TTL: time.Minute, }, - &structs.CheckType{ + { Name: "check-noid", TTL: time.Minute, }, - &structs.CheckType{ + { TTL: time.Minute, }, }, map[string]*structs.HealthCheck{ - "check1": &structs.HealthCheck{ + "check1": { Node: "node1", CheckID: "check1", Name: "name1", @@ -469,7 +469,7 @@ func testAgent_AddService(t *testing.T, extraHCL string) { Type: "ttl", EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - "check-noname": &structs.HealthCheck{ + "check-noname": { Node: "node1", CheckID: "check-noname", Name: "Service 'svcname2' check", @@ -480,7 +480,7 @@ func testAgent_AddService(t *testing.T, extraHCL string) { Type: "ttl", EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - "service:svcid2:3": &structs.HealthCheck{ + "service:svcid2:3": { Node: "node1", CheckID: "service:svcid2:3", Name: "check-noid", @@ -491,7 +491,7 @@ func testAgent_AddService(t *testing.T, extraHCL string) { Type: "ttl", EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - "service:svcid2:4": &structs.HealthCheck{ + "service:svcid2:4": { Node: "node1", CheckID: "service:svcid2:4", Name: "Service 'svcname2' check", @@ -598,7 +598,7 @@ func testAgent_AddServices_AliasUpdateCheckNotReverted(t *testing.T, extraHCL st Name: name, Port: 8080 + i, Checks: []*structs.CheckType{ - &structs.CheckType{ + { Name: "alias-for-fake-service", AliasService: "fake", }, @@ -1013,7 +1013,7 @@ func testAgent_RemoveService(t *testing.T, extraHCL string) { Service: "memcache", Port: 8000, } - chkTypes := []*structs.CheckType{&structs.CheckType{TTL: time.Minute}} + chkTypes := []*structs.CheckType{{TTL: time.Minute}} if err := a.AddService(srv, chkTypes, false, "", ConfigSourceLocal); err != nil { t.Fatalf("err: %v", err) @@ -1047,8 +1047,8 @@ func testAgent_RemoveService(t *testing.T, extraHCL string) { Port: 8000, } chkTypes := []*structs.CheckType{ - &structs.CheckType{TTL: time.Minute}, - &structs.CheckType{TTL: 30 * time.Second}, + {TTL: time.Minute}, + {TTL: 30 * time.Second}, } if err := a.AddService(srv, chkTypes, false, "", ConfigSourceLocal); err != nil { t.Fatalf("err: %v", err) @@ -1061,8 +1061,8 @@ func testAgent_RemoveService(t *testing.T, extraHCL string) { Port: 3306, } chkTypes = []*structs.CheckType{ - &structs.CheckType{TTL: time.Minute}, - &structs.CheckType{TTL: 30 * time.Second}, + {TTL: time.Minute}, + {TTL: 30 * time.Second}, } if err := a.AddService(srv, chkTypes, false, "", ConfigSourceLocal); err != nil { t.Fatalf("err: %v", err) @@ -1579,7 +1579,7 @@ func TestAgent_RestoreServiceWithAliasCheck(t *testing.T) { Port: 8000, }, []*structs.CheckType{ - &structs.CheckType{ + { HTTP: testHTTPServer.URL, Method: "GET", Interval: 5 * time.Second, @@ -1598,7 +1598,7 @@ func TestAgent_RestoreServiceWithAliasCheck(t *testing.T) { Port: 9000, }, []*structs.CheckType{ - &structs.CheckType{ + { Name: "Connect Sidecar Aliasing ping", AliasService: "ping", }, @@ -2844,7 +2844,7 @@ func TestAgent_Service_Reap(t *testing.T) { Port: 8000, } chkTypes := []*structs.CheckType{ - &structs.CheckType{ + { Status: api.HealthPassing, TTL: 25 * time.Millisecond, DeregisterCriticalServiceAfter: 200 * time.Millisecond, @@ -2898,7 +2898,7 @@ func TestAgent_Service_NoReap(t *testing.T) { Port: 8000, } chkTypes := []*structs.CheckType{ - &structs.CheckType{ + { Status: api.HealthPassing, TTL: 25 * time.Millisecond, }, @@ -2962,7 +2962,7 @@ func testAgent_AddService_restoresSnapshot(t *testing.T, extraHCL string) { require.NoError(t, a.AddCheck(check1, nil, false, "", ConfigSourceLocal)) // Re-registering the service preserves the state of the check - chkTypes := []*structs.CheckType{&structs.CheckType{TTL: 30 * time.Second}} + chkTypes := []*structs.CheckType{{TTL: 30 * time.Second}} require.NoError(t, a.AddService(svc, chkTypes, false, "", ConfigSourceLocal)) check := requireCheckExists(t, a, "service:redis") require.Equal(t, api.HealthPassing, check.Status) diff --git a/agent/cache-types/catalog_list_services_test.go b/agent/cache-types/catalog_list_services_test.go index 0f0e78c760..ee806ff88e 100644 --- a/agent/cache-types/catalog_list_services_test.go +++ b/agent/cache-types/catalog_list_services_test.go @@ -26,8 +26,8 @@ func TestCatalogListServices(t *testing.T) { reply := args.Get(2).(*structs.IndexedServices) reply.Services = map[string][]string{ - "foo": []string{"prod", "linux"}, - "bar": []string{"qa", "windows"}, + "foo": {"prod", "linux"}, + "bar": {"qa", "windows"}, } reply.QueryMeta.Index = 48 resp = reply diff --git a/agent/cache-types/catalog_services_test.go b/agent/cache-types/catalog_services_test.go index 7eeff023d5..7400a443f3 100644 --- a/agent/cache-types/catalog_services_test.go +++ b/agent/cache-types/catalog_services_test.go @@ -29,7 +29,7 @@ func TestCatalogServices(t *testing.T) { reply := args.Get(2).(*structs.IndexedServiceNodes) reply.ServiceNodes = []*structs.ServiceNode{ - &structs.ServiceNode{ServiceTags: req.ServiceTags}, + {ServiceTags: req.ServiceTags}, } reply.QueryMeta.Index = 48 resp = reply diff --git a/agent/cache-types/resolved_service_config_test.go b/agent/cache-types/resolved_service_config_test.go index f52d65e42f..34c2ddea05 100644 --- a/agent/cache-types/resolved_service_config_test.go +++ b/agent/cache-types/resolved_service_config_test.go @@ -32,7 +32,7 @@ func TestResolvedServiceConfig(t *testing.T) { "protocol": "http", } reply.UpstreamConfigs = map[string]map[string]interface{}{ - "s2": map[string]interface{}{ + "s2": { "protocol": "http", }, } diff --git a/agent/catalog_endpoint_test.go b/agent/catalog_endpoint_test.go index 13552122b6..e1a836a029 100644 --- a/agent/catalog_endpoint_test.go +++ b/agent/catalog_endpoint_test.go @@ -847,7 +847,7 @@ func TestCatalogServiceNodes_WanTranslation(t *testing.T) { Address: "127.0.0.1", Port: 8080, TaggedAddresses: map[string]structs.ServiceAddress{ - "wan": structs.ServiceAddress{ + "wan": { Address: "1.2.3.4", Port: 80, }, @@ -1274,7 +1274,7 @@ func TestCatalogNodeServices_WanTranslation(t *testing.T) { Address: "127.0.0.1", Port: 8080, TaggedAddresses: map[string]structs.ServiceAddress{ - "wan": structs.ServiceAddress{ + "wan": { Address: "1.2.3.4", Port: 80, }, diff --git a/agent/checks/alias_test.go b/agent/checks/alias_test.go index 24147b2c19..9ae6e913a6 100644 --- a/agent/checks/alias_test.go +++ b/agent/checks/alias_test.go @@ -91,21 +91,21 @@ func TestCheckAlias_remoteNodeFailure(t *testing.T) { rpc.AddReply("Health.NodeChecks", structs.IndexedHealthChecks{ HealthChecks: []*structs.HealthCheck{ // Should ignore non-matching node - &structs.HealthCheck{ + { Node: "A", ServiceID: "web", Status: api.HealthCritical, }, // Node failure - &structs.HealthCheck{ + { Node: "remote", ServiceID: "", Status: api.HealthCritical, }, // Match - &structs.HealthCheck{ + { Node: "remote", ServiceID: "web", Status: api.HealthPassing, @@ -140,21 +140,21 @@ func TestCheckAlias_remotePassing(t *testing.T) { rpc.AddReply("Health.NodeChecks", structs.IndexedHealthChecks{ HealthChecks: []*structs.HealthCheck{ // Should ignore non-matching node - &structs.HealthCheck{ + { Node: "A", ServiceID: "web", Status: api.HealthCritical, }, // Should ignore non-matching service - &structs.HealthCheck{ + { Node: "remote", ServiceID: "db", Status: api.HealthCritical, }, // Match - &structs.HealthCheck{ + { Node: "remote", ServiceID: "web", Status: api.HealthPassing, @@ -189,14 +189,14 @@ func TestCheckAlias_remotePassingWithoutChecksButWithService(t *testing.T) { rpc.AddReply("Health.NodeChecks", structs.IndexedHealthChecks{ HealthChecks: []*structs.HealthCheck{ // Should ignore non-matching node - &structs.HealthCheck{ + { Node: "A", ServiceID: "web", Status: api.HealthCritical, }, // Should ignore non-matching service - &structs.HealthCheck{ + { Node: "remote", ServiceID: "db", Status: api.HealthCritical, @@ -246,14 +246,14 @@ func TestCheckAlias_remotePassingWithoutChecksAndWithoutService(t *testing.T) { rpc.AddReply("Health.NodeChecks", structs.IndexedHealthChecks{ HealthChecks: []*structs.HealthCheck{ // Should ignore non-matching node - &structs.HealthCheck{ + { Node: "A", ServiceID: "web", Status: api.HealthCritical, }, // Should ignore non-matching service - &structs.HealthCheck{ + { Node: "remote", ServiceID: "db", Status: api.HealthCritical, @@ -299,27 +299,27 @@ func TestCheckAlias_remoteCritical(t *testing.T) { rpc.AddReply("Health.NodeChecks", structs.IndexedHealthChecks{ HealthChecks: []*structs.HealthCheck{ // Should ignore non-matching node - &structs.HealthCheck{ + { Node: "A", ServiceID: "web", Status: api.HealthCritical, }, // Should ignore non-matching service - &structs.HealthCheck{ + { Node: "remote", ServiceID: "db", Status: api.HealthCritical, }, // Match - &structs.HealthCheck{ + { Node: "remote", ServiceID: "web", Status: api.HealthPassing, }, - &structs.HealthCheck{ + { Node: "remote", ServiceID: "web", Status: api.HealthCritical, @@ -354,27 +354,27 @@ func TestCheckAlias_remoteWarning(t *testing.T) { rpc.AddReply("Health.NodeChecks", structs.IndexedHealthChecks{ HealthChecks: []*structs.HealthCheck{ // Should ignore non-matching node - &structs.HealthCheck{ + { Node: "A", ServiceID: "web", Status: api.HealthCritical, }, // Should ignore non-matching service - &structs.HealthCheck{ + { Node: "remote", ServiceID: "db", Status: api.HealthCritical, }, // Match - &structs.HealthCheck{ + { Node: "remote", ServiceID: "web", Status: api.HealthPassing, }, - &structs.HealthCheck{ + { Node: "remote", ServiceID: "web", Status: api.HealthWarning, @@ -408,21 +408,21 @@ func TestCheckAlias_remoteNodeOnlyPassing(t *testing.T) { rpc.AddReply("Health.NodeChecks", structs.IndexedHealthChecks{ HealthChecks: []*structs.HealthCheck{ // Should ignore non-matching node - &structs.HealthCheck{ + { Node: "A", ServiceID: "web", Status: api.HealthCritical, }, // Should ignore any services - &structs.HealthCheck{ + { Node: "remote", ServiceID: "db", Status: api.HealthCritical, }, // Match - &structs.HealthCheck{ + { Node: "remote", Status: api.HealthPassing, }, @@ -455,21 +455,21 @@ func TestCheckAlias_remoteNodeOnlyCritical(t *testing.T) { rpc.AddReply("Health.NodeChecks", structs.IndexedHealthChecks{ HealthChecks: []*structs.HealthCheck{ // Should ignore non-matching node - &structs.HealthCheck{ + { Node: "A", ServiceID: "web", Status: api.HealthCritical, }, // Should ignore any services - &structs.HealthCheck{ + { Node: "remote", ServiceID: "db", Status: api.HealthCritical, }, // Match - &structs.HealthCheck{ + { Node: "remote", Status: api.HealthCritical, }, diff --git a/agent/config/runtime_oss_test.go b/agent/config/runtime_oss_test.go index 72cee4d261..3871940c51 100644 --- a/agent/config/runtime_oss_test.go +++ b/agent/config/runtime_oss_test.go @@ -17,7 +17,7 @@ var enterpriseNonVotingServerWarnings []string = []string{enterpriseConfigKeyErr var enterpriseConfigKeyWarnings []string func init() { - for k, _ := range enterpriseConfigMap { + for k := range enterpriseConfigMap { enterpriseConfigKeyWarnings = append(enterpriseConfigKeyWarnings, enterpriseConfigKeyError{key: k}.Error()) } } diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index 20d9e70be7..cb9426b0bc 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -2287,8 +2287,8 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { }, patch: func(rt *RuntimeConfig) { rt.Checks = []*structs.CheckDefinition{ - &structs.CheckDefinition{Name: "a", ScriptArgs: []string{"/bin/true"}, OutputMaxSize: checks.DefaultBufSize}, - &structs.CheckDefinition{Name: "b", ScriptArgs: []string{"/bin/false"}, OutputMaxSize: checks.DefaultBufSize}, + {Name: "a", ScriptArgs: []string{"/bin/true"}, OutputMaxSize: checks.DefaultBufSize}, + {Name: "b", ScriptArgs: []string{"/bin/false"}, OutputMaxSize: checks.DefaultBufSize}, } rt.DataDir = dataDir }, @@ -2306,7 +2306,7 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { }, patch: func(rt *RuntimeConfig) { rt.Checks = []*structs.CheckDefinition{ - &structs.CheckDefinition{Name: "a", GRPC: "localhost:12345/foo", GRPCUseTLS: true, OutputMaxSize: checks.DefaultBufSize}, + {Name: "a", GRPC: "localhost:12345/foo", GRPCUseTLS: true, OutputMaxSize: checks.DefaultBufSize}, } rt.DataDir = dataDir }, @@ -2324,7 +2324,7 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { }, patch: func(rt *RuntimeConfig) { rt.Checks = []*structs.CheckDefinition{ - &structs.CheckDefinition{Name: "a", AliasService: "foo", OutputMaxSize: checks.DefaultBufSize}, + {Name: "a", AliasService: "foo", OutputMaxSize: checks.DefaultBufSize}, } rt.DataDir = dataDir }, @@ -2344,7 +2344,7 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { }, patch: func(rt *RuntimeConfig) { rt.Services = []*structs.ServiceDefinition{ - &structs.ServiceDefinition{ + { Name: "a", Port: 80, Weights: &structs.Weights{ @@ -2352,7 +2352,7 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { Warning: 1, }, }, - &structs.ServiceDefinition{ + { Name: "b", Port: 90, Meta: map[string]string{"my": "value"}, @@ -2453,18 +2453,18 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { }, patch: func(rt *RuntimeConfig) { rt.Services = []*structs.ServiceDefinition{ - &structs.ServiceDefinition{ + { Name: "a", Port: 80, TaggedAddresses: map[string]structs.ServiceAddress{ - "wan": structs.ServiceAddress{ + "wan": { Address: "198.18.3.4", Port: 443, }, }, EnableTagOverride: true, Checks: []*structs.CheckType{ - &structs.CheckType{ + { CheckID: types.CheckID("x"), Name: "y", DockerContainerID: "z", @@ -5250,7 +5250,7 @@ func TestFullConfig(t *testing.T) { `} tail := map[string][]Source{ - "json": []Source{ + "json": { { Name: "tail.non-user.json", Format: "json", @@ -5293,7 +5293,7 @@ func TestFullConfig(t *testing.T) { }`, }, }, - "hcl": []Source{ + "hcl": { { Name: "tail.non-user.hcl", Format: "hcl", @@ -5407,7 +5407,7 @@ func TestFullConfig(t *testing.T) { CertFile: "7s4QAzDk", CheckOutputMaxSize: checks.DefaultBufSize, Checks: []*structs.CheckDefinition{ - &structs.CheckDefinition{ + { ID: "uAjE6m9Z", Name: "QsZRGpYr", Notes: "VJ7Sk4BY", @@ -5417,8 +5417,8 @@ func TestFullConfig(t *testing.T) { ScriptArgs: []string{"4BAJttck", "4D2NPtTQ"}, HTTP: "dohLcyQ2", Header: map[string][]string{ - "ZBfTin3L": []string{"1sDbEqYG", "lJGASsWK"}, - "Ui0nU99X": []string{"LMccm3Qe", "k5H5RggQ"}, + "ZBfTin3L": {"1sDbEqYG", "lJGASsWK"}, + "Ui0nU99X": {"LMccm3Qe", "k5H5RggQ"}, }, Method: "aldrIQ4l", Body: "wSjTy7dg", @@ -5432,7 +5432,7 @@ func TestFullConfig(t *testing.T) { TTL: 21743 * time.Second, DeregisterCriticalServiceAfter: 14232 * time.Second, }, - &structs.CheckDefinition{ + { ID: "Cqq95BhP", Name: "3qXpkS0i", Notes: "sb5qLTex", @@ -5442,8 +5442,8 @@ func TestFullConfig(t *testing.T) { ScriptArgs: []string{"9s526ogY", "gSlOHj1w"}, HTTP: "yzhgsQ7Y", Header: map[string][]string{ - "zcqwA8dO": []string{"qb1zx0DL", "sXCxPFsD"}, - "qxvdnSE9": []string{"6wBPUYdF", "YYh8wtSZ"}, + "zcqwA8dO": {"qb1zx0DL", "sXCxPFsD"}, + "qxvdnSE9": {"6wBPUYdF", "YYh8wtSZ"}, }, Method: "gLrztrNw", Body: "0jkKgGUC", @@ -5457,7 +5457,7 @@ func TestFullConfig(t *testing.T) { TTL: 31006 * time.Second, DeregisterCriticalServiceAfter: 2366 * time.Second, }, - &structs.CheckDefinition{ + { ID: "fZaCAXww", Name: "OOM2eo0f", Notes: "zXzXI9Gt", @@ -5638,7 +5638,7 @@ func TestFullConfig(t *testing.T) { }, EnableTagOverride: true, Checks: []*structs.CheckType{ - &structs.CheckType{ + { CheckID: "qmfeO5if", Name: "atDGP7n5", Status: "pDQKEhWL", @@ -5804,11 +5804,11 @@ func TestFullConfig(t *testing.T) { ID: "dLOXpSCI", Name: "o1ynPkp0", TaggedAddresses: map[string]structs.ServiceAddress{ - "lan": structs.ServiceAddress{ + "lan": { Address: "2d79888a", Port: 2143, }, - "wan": structs.ServiceAddress{ + "wan": { Address: "d4db85e2", Port: 6109, }, @@ -5959,13 +5959,13 @@ func TestFullConfig(t *testing.T) { VerifyOutgoing: true, VerifyServerHostname: true, Watches: []map[string]interface{}{ - map[string]interface{}{ + { "type": "key", "datacenter": "GyE6jpeW", "key": "j9lF1Tve", "handler": "90N7S4LN", }, - map[string]interface{}{ + { "type": "keyprefix", "datacenter": "fYrl3F5d", "key": "sl3Dffu7", @@ -6262,7 +6262,7 @@ func TestSanitize(t *testing.T) { "pmgw_foo=bar pmgw_key=baz pmgw_secret=boom pmgw_bang=bar", }, Services: []*structs.ServiceDefinition{ - &structs.ServiceDefinition{ + { Name: "foo", Token: "bar", Check: structs.CheckType{ @@ -6276,7 +6276,7 @@ func TestSanitize(t *testing.T) { }, }, Checks: []*structs.CheckDefinition{ - &structs.CheckDefinition{ + { Name: "zoo", Token: "zope", OutputMaxSize: checks.DefaultBufSize, diff --git a/agent/connect/common_names_test.go b/agent/connect/common_names_test.go index 15b612a5b4..50b0cb161c 100644 --- a/agent/connect/common_names_test.go +++ b/agent/connect/common_names_test.go @@ -18,35 +18,35 @@ func TestServiceAndNamespaceTruncation(t *testing.T) { } cases := map[string]tcase{ - "short-no-truncation": tcase{ + "short-no-truncation": { service: "foo", namespace: "bar", }, - "long-service-no-truncation": tcase{ + "long-service-no-truncation": { // -3 because thats the length of the namespace service: strings.Repeat("a", maxServiceAndNamespaceLen-3), namespace: "bar", }, - "long-namespace-no-truncation": tcase{ + "long-namespace-no-truncation": { service: "foo", // -3 because thats the length of the service name namespace: strings.Repeat("b", maxServiceAndNamespaceLen-3), }, - "truncate-service-only": tcase{ + "truncate-service-only": { // this should force the service name to be truncated service: strings.Repeat("a", maxServiceAndNamespaceLen-minNamespaceNameLen+5), expectedService: strings.Repeat("a", maxServiceAndNamespaceLen-minNamespaceNameLen), // this is the maximum length that will never be truncated for a namespace namespace: strings.Repeat("b", minNamespaceNameLen), }, - "truncate-namespace-only": tcase{ + "truncate-namespace-only": { // this is the maximum length that will never be truncated for a service name service: strings.Repeat("a", minServiceNameLen), // this should force the namespace name to be truncated namespace: strings.Repeat("b", maxServiceAndNamespaceLen-minServiceNameLen+5), expectedNamespace: strings.Repeat("b", maxServiceAndNamespaceLen-minServiceNameLen), }, - "truncate-both-even": tcase{ + "truncate-both-even": { // this test would need to be update if the maxServiceAndNamespaceLen variable is updated // I could put some more complex logic into here to prevent that but it would be mostly // duplicating the logic in the function itself and thus not really be testing anything @@ -59,7 +59,7 @@ func TestServiceAndNamespaceTruncation(t *testing.T) { namespace: strings.Repeat("b", 51), expectedNamespace: strings.Repeat("b", 22), }, - "truncate-both-odd": tcase{ + "truncate-both-odd": { // this test would need to be update if the maxServiceAndNamespaceLen variable is updated // I could put some more complex logic into here to prevent that but it would be mostly // duplicating the logic in the function itself and thus not really be testing anything @@ -73,13 +73,13 @@ func TestServiceAndNamespaceTruncation(t *testing.T) { namespace: strings.Repeat("b", 50), expectedNamespace: strings.Repeat("b", 22), }, - "truncate-both-min-svc": tcase{ + "truncate-both-min-svc": { service: strings.Repeat("a", minServiceNameLen+1), expectedService: strings.Repeat("a", minServiceNameLen), namespace: strings.Repeat("b", maxServiceAndNamespaceLen), expectedNamespace: strings.Repeat("b", maxServiceAndNamespaceLen-minServiceNameLen), }, - "truncate-both-min-ns": tcase{ + "truncate-both-min-ns": { service: strings.Repeat("a", maxServiceAndNamespaceLen), expectedService: strings.Repeat("a", maxServiceAndNamespaceLen-minNamespaceNameLen), namespace: strings.Repeat("b", minNamespaceNameLen+1), diff --git a/agent/consul/acl.go b/agent/consul/acl.go index ba260743cf..81730a67a4 100644 --- a/agent/consul/acl.go +++ b/agent/consul/acl.go @@ -1414,7 +1414,7 @@ func (f *aclFilter) filterCheckServiceNodes(nodes *structs.CheckServiceNodes) { func (f *aclFilter) filterDatacenterCheckServiceNodes(datacenterNodes *map[string]structs.CheckServiceNodes) { dn := *datacenterNodes out := make(map[string]structs.CheckServiceNodes) - for dc, _ := range dn { + for dc := range dn { nodes := dn[dc] f.filterCheckServiceNodes(&nodes) if len(nodes) > 0 { diff --git a/agent/consul/acl_replication_test.go b/agent/consul/acl_replication_test.go index 3cafca58aa..d1b39c26fe 100644 --- a/agent/consul/acl_replication_test.go +++ b/agent/consul/acl_replication_test.go @@ -336,7 +336,7 @@ func TestACLReplication_Tokens(t *testing.T) { ACLToken: structs.ACLToken{ Description: fmt.Sprintf("token-%d", i), Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -391,7 +391,7 @@ func TestACLReplication_Tokens(t *testing.T) { ACLToken: structs.ACLToken{ Description: fmt.Sprintf("token-%d", i), Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -411,7 +411,7 @@ func TestACLReplication_Tokens(t *testing.T) { ACLToken: structs.ACLToken{ Description: fmt.Sprintf("token-%d", i), Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -432,7 +432,7 @@ func TestACLReplication_Tokens(t *testing.T) { SecretID: tokens[i].SecretID, Description: fmt.Sprintf("token-%d-modified", i), Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -625,7 +625,7 @@ func TestACLReplication_TokensRedacted(t *testing.T) { ACLToken: structs.ACLToken{ Description: "dc2-replication", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: policy.ID, }, }, @@ -700,7 +700,7 @@ func TestACLReplication_TokensRedacted(t *testing.T) { ACLToken: structs.ACLToken{ Description: "management", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, diff --git a/agent/consul/acl_test.go b/agent/consul/acl_test.go index 248faa2c9a..f2098e3dcf 100644 --- a/agent/consul/acl_test.go +++ b/agent/consul/acl_test.go @@ -72,10 +72,10 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "435a75af-1763-4980-89f4-f0951dda53b4", SecretID: "b1b6be70-ed2e-4c80-8495-bdb3db110b1e", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "not-found", }, - structs.ACLTokenPolicyLink{ + { ID: "acl-ro", }, }, @@ -85,10 +85,10 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "435a75af-1763-4980-89f4-f0951dda53b4", SecretID: "b1b6be70-ed2e-4c80-8495-bdb3db110b1e", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: "not-found", }, - structs.ACLTokenRoleLink{ + { ID: "acl-ro", }, }, @@ -98,7 +98,7 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "435a75af-1763-4980-89f4-f0951dda53b4", SecretID: "b1b6be70-ed2e-4c80-8495-bdb3db110b1e", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: "missing-policy", }, }, @@ -121,10 +121,10 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "5f57c1f6-6a89-4186-9445-531b316e01df", SecretID: "a1a54629-5050-4d17-8a4e-560d2423f835", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "node-wr", }, - structs.ACLTokenPolicyLink{ + { ID: "dc2-key-wr", }, }, @@ -136,7 +136,7 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "5f57c1f6-6a89-4186-9445-531b316e01df", SecretID: "a1a54629-5050-4d17-8a4e-560d2423f835", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: "found", }, }, @@ -146,15 +146,15 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "5f57c1f6-6a89-4186-9445-531b316e01df", SecretID: "a1a54629-5050-4d17-8a4e-560d2423f835", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "node-wr", }, - structs.ACLTokenPolicyLink{ + { ID: "dc2-key-wr", }, }, Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: "service-ro", }, }, @@ -164,7 +164,7 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "f6c5a5fb-4da4-422b-9abf-2c942813fc71", SecretID: "55cb7d69-2bea-42c3-a68f-2a1443d2abbc", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "service1", }, }, @@ -174,7 +174,7 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "7c87dfad-be37-446e-8305-299585677cb5", SecretID: "dfca9676-ac80-453a-837b-4c0cf923473c", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "service2", }, }, @@ -184,12 +184,12 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "bebccc92-3987-489d-84c2-ffd00d93ef93", SecretID: "de70f2e2-69d9-4e88-9815-f91c03c6bcb1", NodeIdentities: []*structs.ACLNodeIdentity{ - &structs.ACLNodeIdentity{ + { NodeName: "test-node1", Datacenter: "dc1", }, // as the resolver is in dc1 this identity should be ignored - &structs.ACLNodeIdentity{ + { NodeName: "test-node-dc2", Datacenter: "dc2", }, @@ -200,12 +200,12 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "359b9927-25fd-46b9-bd14-3470f848ec65", SecretID: "83c4d500-847d-49f7-8c08-0483f6b4156e", NodeIdentities: []*structs.ACLNodeIdentity{ - &structs.ACLNodeIdentity{ + { NodeName: "test-node2", Datacenter: "dc1", }, // as the resolver is in dc1 this identity should be ignored - &structs.ACLNodeIdentity{ + { NodeName: "test-node-dc2", Datacenter: "dc2", }, @@ -226,7 +226,7 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "435a75af-1763-4980-89f4-f0951dda53b4", SecretID: "b1b6be70-ed2e-4c80-8495-bdb3db110b1e", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "acl-ro", }, }, @@ -236,7 +236,7 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "435a75af-1763-4980-89f4-f0951dda53b4", SecretID: "b1b6be70-ed2e-4c80-8495-bdb3db110b1e", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "acl-wr", }, }, @@ -246,10 +246,10 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "5f57c1f6-6a89-4186-9445-531b316e01df", SecretID: "a1a54629-5050-4d17-8a4e-560d2423f835", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "node-wr", }, - structs.ACLTokenPolicyLink{ + { ID: "acl-wr", }, }, @@ -259,7 +259,7 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "5f57c1f6-6a89-4186-9445-531b316e01df", SecretID: "a1a54629-5050-4d17-8a4e-560d2423f835", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "node-wr", }, }, @@ -269,10 +269,10 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "5f57c1f6-6a89-4186-9445-531b316e01df", SecretID: "a1a54629-5050-4d17-8a4e-560d2423f835", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "node-wr", }, - structs.ACLTokenPolicyLink{ + { ID: "acl-wr", }, }, @@ -282,7 +282,7 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { AccessorID: "00000000-0000-0000-0000-000000000002", SecretID: anonymousToken, Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "node-wr", }, }, @@ -363,7 +363,7 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "service-ro", Description: "service-ro", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "service-ro", }, }, @@ -375,7 +375,7 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "service-wr", Description: "service-wr", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "service-wr", }, }, @@ -387,10 +387,10 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "missing-policy", Description: "missing-policy", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "not-found", }, - structs.ACLRolePolicyLink{ + { ID: "acl-ro", }, }, @@ -402,10 +402,10 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "found", Description: "found", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "node-wr", }, - structs.ACLRolePolicyLink{ + { ID: "dc2-key-wr", }, }, @@ -416,7 +416,7 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "acl-ro", Description: "acl-ro", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "acl-ro", }, }, @@ -427,7 +427,7 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "acl-rw", Description: "acl-rw", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "acl-wr", }, }, @@ -438,10 +438,10 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "racey-unmodified", Description: "racey-unmodified", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "node-wr", }, - structs.ACLRolePolicyLink{ + { ID: "acl-wr", }, }, @@ -452,7 +452,7 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "racey-modified", Description: "racey-modified", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "node-wr", }, }, @@ -463,10 +463,10 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "concurrent-resolve-1", Description: "concurrent-resolve-1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "node-wr", }, - structs.ACLRolePolicyLink{ + { ID: "acl-wr", }, }, @@ -477,10 +477,10 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "concurrent-resolve-2", Description: "concurrent-resolve-2", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "node-wr", }, - structs.ACLRolePolicyLink{ + { ID: "acl-wr", }, }, @@ -491,11 +491,11 @@ func testRoleForID(roleID string) (bool, *structs.ACLRole, error) { Name: "node-identity", Description: "node-identity", NodeIdentities: []*structs.ACLNodeIdentity{ - &structs.ACLNodeIdentity{ + { NodeName: "test-node", Datacenter: "dc1", }, - &structs.ACLNodeIdentity{ + { NodeName: "test-node-dc2", Datacenter: "dc2", }, @@ -1566,7 +1566,7 @@ func TestACLResolver_Client(t *testing.T) { ID: "not-needed", PolicyRules: acl.PolicyRules{ Nodes: []*acl.NodeRule{ - &acl.NodeRule{ + { Name: "foo", Policy: acl.PolicyWrite, }, @@ -1909,7 +1909,7 @@ func TestACLResolver_Legacy(t *testing.T) { ID: "not-needed", PolicyRules: acl.PolicyRules{ Nodes: []*acl.NodeRule{ - &acl.NodeRule{ + { Name: "foo", Policy: acl.PolicyWrite, }, @@ -1960,7 +1960,7 @@ func TestACLResolver_Legacy(t *testing.T) { ID: "not-needed", PolicyRules: acl.PolicyRules{ Nodes: []*acl.NodeRule{ - &acl.NodeRule{ + { Name: "foo", Policy: acl.PolicyWrite, }, @@ -2013,7 +2013,7 @@ func TestACLResolver_Legacy(t *testing.T) { ID: "not-needed", PolicyRules: acl.PolicyRules{ Nodes: []*acl.NodeRule{ - &acl.NodeRule{ + { Name: "foo", Policy: acl.PolicyWrite, }, @@ -2067,7 +2067,7 @@ func TestACLResolver_Legacy(t *testing.T) { ID: "not-needed", PolicyRules: acl.PolicyRules{ Nodes: []*acl.NodeRule{ - &acl.NodeRule{ + { Name: "foo", Policy: acl.PolicyWrite, }, @@ -2121,7 +2121,7 @@ func TestACLResolver_Legacy(t *testing.T) { ID: "not-needed", PolicyRules: acl.PolicyRules{ Nodes: []*acl.NodeRule{ - &acl.NodeRule{ + { Name: "foo", Policy: acl.PolicyWrite, }, @@ -2581,7 +2581,7 @@ func TestACL_filterNodeServices(t *testing.T) { Node: "node1", }, Services: map[string]*structs.NodeService{ - "foo": &structs.NodeService{ + "foo": { ID: "foo", Service: "foo", }, @@ -2830,13 +2830,13 @@ func TestACL_filterNodeDump(t *testing.T) { &structs.NodeInfo{ Node: "node1", Services: []*structs.NodeService{ - &structs.NodeService{ + { ID: "foo", Service: "foo", }, }, Checks: []*structs.HealthCheck{ - &structs.HealthCheck{ + { Node: "node1", CheckID: "check1", ServiceName: "foo", diff --git a/agent/consul/authmethod/authmethods.go b/agent/consul/authmethod/authmethods.go index 41f791fe43..0397ed19ce 100644 --- a/agent/consul/authmethod/authmethods.go +++ b/agent/consul/authmethod/authmethods.go @@ -68,7 +68,7 @@ type Identity struct { // ProjectedVarNames returns just the keyspace of the ProjectedVars map. func (i *Identity) ProjectedVarNames() []string { v := make([]string, 0, len(i.ProjectedVars)) - for k, _ := range i.ProjectedVars { + for k := range i.ProjectedVars { v = append(v, k) } return v diff --git a/agent/consul/authmethod/kubeauth/testing.go b/agent/consul/authmethod/kubeauth/testing.go index 1633b75c93..786845c140 100644 --- a/agent/consul/authmethod/kubeauth/testing.go +++ b/agent/consul/authmethod/kubeauth/testing.go @@ -517,7 +517,7 @@ func createReadServiceAccountFound(namespace, name, uid, overrideAnnotation, jwt CreationTimestamp: metav1.Time{Time: time.Now()}, }, Secrets: []corev1.ObjectReference{ - corev1.ObjectReference{ + { Name: name + "-token-m9cvn", }, }, diff --git a/agent/consul/authmethod/testing.go b/agent/consul/authmethod/testing.go index e7161c78ad..d367f64767 100644 --- a/agent/consul/authmethod/testing.go +++ b/agent/consul/authmethod/testing.go @@ -18,7 +18,7 @@ func RequireIdentityMatch(t testing.T, id *Identity, projectedVars map[string]st require.Equal(t, projectedVars, id.ProjectedVars) expectNames := make([]string, 0, len(projectedVars)) - for k, _ := range projectedVars { + for k := range projectedVars { expectNames = append(expectNames, k) } sort.Strings(expectNames) diff --git a/agent/consul/catalog_endpoint_test.go b/agent/consul/catalog_endpoint_test.go index a4b435ff14..f38e84dfc9 100644 --- a/agent/consul/catalog_endpoint_test.go +++ b/agent/consul/catalog_endpoint_test.go @@ -1644,11 +1644,11 @@ func TestCatalog_ListServiceNodes_ByAddress(t *testing.T) { fooAddress := "10.1.2.3" fooPort := 1111 fooTaggedAddresses := map[string]structs.ServiceAddress{ - "lan": structs.ServiceAddress{ + "lan": { Address: "10.1.2.3", Port: fooPort, }, - "wan": structs.ServiceAddress{ + "wan": { Address: "198.18.1.2", Port: fooPort, }, @@ -1656,11 +1656,11 @@ func TestCatalog_ListServiceNodes_ByAddress(t *testing.T) { barAddress := "10.1.2.3" barPort := 2222 barTaggedAddresses := map[string]structs.ServiceAddress{ - "lan": structs.ServiceAddress{ + "lan": { Address: "10.1.2.3", Port: barPort, }, - "wan": structs.ServiceAddress{ + "wan": { Address: "198.18.2.3", Port: barPort, }, @@ -1668,11 +1668,11 @@ func TestCatalog_ListServiceNodes_ByAddress(t *testing.T) { bazAddress := "192.168.1.35" bazPort := 2222 bazTaggedAddresses := map[string]structs.ServiceAddress{ - "lan": structs.ServiceAddress{ + "lan": { Address: "192.168.1.35", Port: barPort, }, - "wan": structs.ServiceAddress{ + "wan": { Address: "198.18.2.4", Port: barPort, }, diff --git a/agent/consul/client.go b/agent/consul/client.go index ce4738ae46..2d4eee61f2 100644 --- a/agent/consul/client.go +++ b/agent/consul/client.go @@ -393,7 +393,7 @@ func (c *Client) Stats() map[string]map[string]string { return strconv.FormatUint(v, 10) } stats := map[string]map[string]string{ - "consul": map[string]string{ + "consul": { "server": "false", "known_servers": toString(uint64(numServers)), }, diff --git a/agent/consul/config_endpoint_test.go b/agent/consul/config_endpoint_test.go index 50e6acc78d..8a8591a034 100644 --- a/agent/consul/config_endpoint_test.go +++ b/agent/consul/config_endpoint_test.go @@ -779,7 +779,7 @@ func TestConfigEntry_ResolveServiceConfig(t *testing.T) { "protocol": "http", }, UpstreamConfigs: map[string]map[string]interface{}{ - "bar": map[string]interface{}{ + "bar": { "protocol": "grpc", }, }, @@ -1013,16 +1013,16 @@ func TestConfigEntry_ResolveServiceConfig_UpstreamProxyDefaultsProtocol(t *testi "protocol": "http", }, UpstreamConfigs: map[string]map[string]interface{}{ - "bar": map[string]interface{}{ + "bar": { "protocol": "http", }, - "other": map[string]interface{}{ + "other": { "protocol": "http", }, - "dne": map[string]interface{}{ + "dne": { "protocol": "http", }, - "alreadyprotocol": map[string]interface{}{ + "alreadyprotocol": { "protocol": "grpc", }, }, @@ -1066,7 +1066,7 @@ func TestConfigEntry_ResolveServiceConfig_ProxyDefaultsProtocol_UsedForAllUpstre "protocol": "http", }, UpstreamConfigs: map[string]map[string]interface{}{ - "bar": map[string]interface{}{ + "bar": { "protocol": "http", }, }, diff --git a/agent/consul/discovery_chain_endpoint_test.go b/agent/consul/discovery_chain_endpoint_test.go index d228b1faf4..89e4e64bd8 100644 --- a/agent/consul/discovery_chain_endpoint_test.go +++ b/agent/consul/discovery_chain_endpoint_test.go @@ -91,7 +91,7 @@ func TestDiscoveryChainEndpoint_Get(t *testing.T) { Protocol: "tcp", StartNode: "resolver:web.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:web.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:web.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "web.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -185,7 +185,7 @@ func TestDiscoveryChainEndpoint_Get(t *testing.T) { Protocol: "tcp", StartNode: "resolver:web.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:web.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:web.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "web.default.dc1", Resolver: &structs.DiscoveryResolver{ diff --git a/agent/consul/discoverychain/compile.go b/agent/consul/discoverychain/compile.go index 733ead473b..f5bbd1ba4d 100644 --- a/agent/consul/discoverychain/compile.go +++ b/agent/consul/discoverychain/compile.go @@ -272,7 +272,7 @@ func (c *compiler) compile() (*structs.CompiledDiscoveryChain, error) { return nil, err } - for targetID, _ := range c.loadedTargets { + for targetID := range c.loadedTargets { if _, ok := c.retainedTargets[targetID]; !ok { delete(c.loadedTargets, targetID) } @@ -443,7 +443,7 @@ func (c *compiler) removeUnusedNodes() error { if len(todo) == 0 { return "" } - for k, _ := range todo { + for k := range todo { delete(todo, k) return k } @@ -485,7 +485,7 @@ func (c *compiler) removeUnusedNodes() error { return nil } - for name, _ := range c.nodes { + for name := range c.nodes { if _, ok := visited[name]; !ok { delete(c.nodes, name) } @@ -541,7 +541,7 @@ func (c *compiler) assembleChain() error { return err } - for i, _ := range router.Routes { + for i := range router.Routes { // We don't use range variables here because we'll take the address of // this route and store that in a DiscoveryGraphNode and the range // variables share memory addresses between iterations which is exactly diff --git a/agent/consul/discoverychain/compile_test.go b/agent/consul/discoverychain/compile_test.go index d86c93cbd1..ac77600dcc 100644 --- a/agent/consul/discoverychain/compile_test.go +++ b/agent/consul/discoverychain/compile_test.go @@ -157,7 +157,7 @@ func testcase_JustRouterWithDefaults() compileTestCase { Protocol: "http", StartNode: "router:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "router:main.default": &structs.DiscoveryGraphNode{ + "router:main.default": { Type: structs.DiscoveryGraphNodeTypeRouter, Name: "main.default", Routes: []*structs.DiscoveryRoute{ @@ -167,7 +167,7 @@ func testcase_JustRouterWithDefaults() compileTestCase { }, }, }, - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -209,7 +209,7 @@ func testcase_JustRouterWithNoDestination() compileTestCase { Protocol: "http", StartNode: "router:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "router:main.default": &structs.DiscoveryGraphNode{ + "router:main.default": { Type: structs.DiscoveryGraphNodeTypeRouter, Name: "main.default", Routes: []*structs.DiscoveryRoute{ @@ -229,7 +229,7 @@ func testcase_JustRouterWithNoDestination() compileTestCase { }, }, }, - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -269,7 +269,7 @@ func testcase_RouterWithDefaults_NoSplit_WithResolver() compileTestCase { Protocol: "http", StartNode: "router:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "router:main.default": &structs.DiscoveryGraphNode{ + "router:main.default": { Type: structs.DiscoveryGraphNodeTypeRouter, Name: "main.default", Routes: []*structs.DiscoveryRoute{ @@ -279,7 +279,7 @@ func testcase_RouterWithDefaults_NoSplit_WithResolver() compileTestCase { }, }, }, - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -320,7 +320,7 @@ func testcase_RouterWithDefaults_WithNoopSplit_DefaultResolver() compileTestCase Protocol: "http", StartNode: "router:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "router:main.default": &structs.DiscoveryGraphNode{ + "router:main.default": { Type: structs.DiscoveryGraphNodeTypeRouter, Name: "main.default", Routes: []*structs.DiscoveryRoute{ @@ -330,7 +330,7 @@ func testcase_RouterWithDefaults_WithNoopSplit_DefaultResolver() compileTestCase }, }, }, - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -340,7 +340,7 @@ func testcase_RouterWithDefaults_WithNoopSplit_DefaultResolver() compileTestCase }, }, }, - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -382,7 +382,7 @@ func testcase_NoopSplit_DefaultResolver_ProtocolFromProxyDefaults() compileTestC Protocol: "http", StartNode: "router:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "router:main.default": &structs.DiscoveryGraphNode{ + "router:main.default": { Type: structs.DiscoveryGraphNodeTypeRouter, Name: "main.default", Routes: []*structs.DiscoveryRoute{ @@ -392,7 +392,7 @@ func testcase_NoopSplit_DefaultResolver_ProtocolFromProxyDefaults() compileTestC }, }, }, - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -402,7 +402,7 @@ func testcase_NoopSplit_DefaultResolver_ProtocolFromProxyDefaults() compileTestC }, }, }, - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -451,7 +451,7 @@ func testcase_RouterWithDefaults_WithNoopSplit_WithResolver() compileTestCase { Protocol: "http", StartNode: "router:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "router:main.default": &structs.DiscoveryGraphNode{ + "router:main.default": { Type: structs.DiscoveryGraphNodeTypeRouter, Name: "main.default", Routes: []*structs.DiscoveryRoute{ @@ -461,7 +461,7 @@ func testcase_RouterWithDefaults_WithNoopSplit_WithResolver() compileTestCase { }, }, }, - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -471,7 +471,7 @@ func testcase_RouterWithDefaults_WithNoopSplit_WithResolver() compileTestCase { }, }, }, - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -532,7 +532,7 @@ func testcase_RouteBypassesSplit() compileTestCase { Protocol: "http", StartNode: "router:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "router:main.default": &structs.DiscoveryGraphNode{ + "router:main.default": { Type: structs.DiscoveryGraphNodeTypeRouter, Name: "main.default", Routes: []*structs.DiscoveryRoute{ @@ -546,7 +546,7 @@ func testcase_RouteBypassesSplit() compileTestCase { }, }, }, - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -555,7 +555,7 @@ func testcase_RouteBypassesSplit() compileTestCase { Target: "main.default.dc1", }, }, - "resolver:bypass.other.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:bypass.other.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "bypass.other.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -595,7 +595,7 @@ func testcase_NoopSplit_DefaultResolver() compileTestCase { Protocol: "http", StartNode: "splitter:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -605,7 +605,7 @@ func testcase_NoopSplit_DefaultResolver() compileTestCase { }, }, }, - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -648,7 +648,7 @@ func testcase_NoopSplit_WithResolver() compileTestCase { Protocol: "http", StartNode: "splitter:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -658,7 +658,7 @@ func testcase_NoopSplit_WithResolver() compileTestCase { }, }, }, - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -708,7 +708,7 @@ func testcase_SubsetSplit() compileTestCase { Protocol: "http", StartNode: "splitter:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -722,7 +722,7 @@ func testcase_SubsetSplit() compileTestCase { }, }, }, - "resolver:v2.main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:v2.main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "v2.main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -730,7 +730,7 @@ func testcase_SubsetSplit() compileTestCase { Target: "v2.main.default.dc1", }, }, - "resolver:v1.main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:v1.main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "v1.main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -777,7 +777,7 @@ func testcase_ServiceSplit() compileTestCase { Protocol: "http", StartNode: "splitter:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -791,7 +791,7 @@ func testcase_ServiceSplit() compileTestCase { }, }, }, - "resolver:foo.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:foo.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "foo.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -800,7 +800,7 @@ func testcase_ServiceSplit() compileTestCase { Target: "foo.default.dc1", }, }, - "resolver:bar.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:bar.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "bar.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -866,7 +866,7 @@ func testcase_SplitBypassesSplit() compileTestCase { Protocol: "http", StartNode: "splitter:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -876,7 +876,7 @@ func testcase_SplitBypassesSplit() compileTestCase { }, }, }, - "resolver:bypassed.next.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:bypassed.next.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "bypassed.next.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -913,7 +913,7 @@ func testcase_ServiceRedirect() compileTestCase { Protocol: "tcp", StartNode: "resolver:other.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:other.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:other.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "other.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -960,7 +960,7 @@ func testcase_ServiceAndSubsetRedirect() compileTestCase { Protocol: "tcp", StartNode: "resolver:v2.other.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:v2.other.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:v2.other.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "v2.other.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -996,7 +996,7 @@ func testcase_DatacenterRedirect() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc9", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc9": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc9": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc9", Resolver: &structs.DiscoveryResolver{ @@ -1035,7 +1035,7 @@ func testcase_DatacenterRedirect_WithMeshGateways() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc9", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc9": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc9": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc9", Resolver: &structs.DiscoveryResolver{ @@ -1071,7 +1071,7 @@ func testcase_ServiceFailover() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1114,7 +1114,7 @@ func testcase_ServiceFailoverThroughRedirect() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1157,7 +1157,7 @@ func testcase_Resolver_CircularFailover() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1198,7 +1198,7 @@ func testcase_ServiceAndSubsetFailover() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1238,7 +1238,7 @@ func testcase_DatacenterFailover() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1282,7 +1282,7 @@ func testcase_DatacenterFailover_WithMeshGateways() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1343,7 +1343,7 @@ func testcase_NoopSplit_WithDefaultSubset() compileTestCase { Protocol: "http", StartNode: "splitter:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -1353,7 +1353,7 @@ func testcase_NoopSplit_WithDefaultSubset() compileTestCase { }, }, }, - "resolver:v2.main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:v2.main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "v2.main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1380,7 +1380,7 @@ func testcase_DefaultResolver() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1415,7 +1415,7 @@ func testcase_DefaultResolver_WithProxyDefaults() compileTestCase { Protocol: "grpc", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1448,7 +1448,7 @@ func testcase_RedirectToDefaultResolverIsNotDefaultChain() compileTestCase { Protocol: "tcp", StartNode: "resolver:other.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:other.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:other.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "other.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1484,7 +1484,7 @@ func testcase_Resolve_WithDefaultSubset() compileTestCase { Protocol: "tcp", StartNode: "resolver:v2.main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:v2.main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:v2.main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "v2.main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1516,7 +1516,7 @@ func testcase_DefaultResolver_ExternalSNI() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1651,7 +1651,7 @@ func testcase_MultiDatacenterCanary() compileTestCase { Protocol: "http", StartNode: "splitter:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "splitter:main.default": &structs.DiscoveryGraphNode{ + "splitter:main.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "main.default", Splits: []*structs.DiscoverySplit{ @@ -1665,7 +1665,7 @@ func testcase_MultiDatacenterCanary() compileTestCase { }, }, }, - "resolver:main.default.dc2": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc2": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc2", Resolver: &structs.DiscoveryResolver{ @@ -1673,7 +1673,7 @@ func testcase_MultiDatacenterCanary() compileTestCase { Target: "main.default.dc2", }, }, - "resolver:main.default.dc3": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc3": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc3", Resolver: &structs.DiscoveryResolver{ @@ -1782,7 +1782,7 @@ func testcase_AllBellsAndWhistles() compileTestCase { Protocol: "http", StartNode: "router:main.default", Nodes: map[string]*structs.DiscoveryGraphNode{ - "router:main.default": &structs.DiscoveryGraphNode{ + "router:main.default": { Type: structs.DiscoveryGraphNodeTypeRouter, Name: "main.default", Routes: []*structs.DiscoveryRoute{ @@ -1800,7 +1800,7 @@ func testcase_AllBellsAndWhistles() compileTestCase { }, }, }, - "splitter:svc-split.default": &structs.DiscoveryGraphNode{ + "splitter:svc-split.default": { Type: structs.DiscoveryGraphNodeTypeSplitter, Name: "svc-split.default", Splits: []*structs.DiscoverySplit{ @@ -1822,7 +1822,7 @@ func testcase_AllBellsAndWhistles() compileTestCase { }, }, }, - "resolver:prod.redirected.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:prod.redirected.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "prod.redirected.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1830,7 +1830,7 @@ func testcase_AllBellsAndWhistles() compileTestCase { Target: "prod.redirected.default.dc1", }, }, - "resolver:v1.main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:v1.main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "v1.main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1838,7 +1838,7 @@ func testcase_AllBellsAndWhistles() compileTestCase { Target: "v1.main.default.dc1", }, }, - "resolver:v2.main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:v2.main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "v2.main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1846,7 +1846,7 @@ func testcase_AllBellsAndWhistles() compileTestCase { Target: "v2.main.default.dc1", }, }, - "resolver:v3.main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:v3.main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "v3.main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -1854,7 +1854,7 @@ func testcase_AllBellsAndWhistles() compileTestCase { Target: "v3.main.default.dc1", }, }, - "resolver:default-subset.main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:default-subset.main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "default-subset.main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -2006,7 +2006,7 @@ func testcase_FailoverCrossesProtocols() compileTestCase { Kind: structs.ServiceResolver, Name: "main", Failover: map[string]structs.ServiceResolverFailover{ - "*": structs.ServiceResolverFailover{ + "*": { Service: "other", }, }, @@ -2075,7 +2075,7 @@ func testcase_ResolverProtocolOverride() compileTestCase { Protocol: "http2", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -2108,7 +2108,7 @@ func testcase_ResolverProtocolOverrideIgnored() compileTestCase { Protocol: "http2", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -2145,7 +2145,7 @@ func testcase_RouterIgnored_ResolverProtocolOverride() compileTestCase { Protocol: "tcp", StartNode: "resolver:main.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:main.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:main.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "main.default.dc1", Resolver: &structs.DiscoveryResolver{ diff --git a/agent/consul/federation_state_endpoint.go b/agent/consul/federation_state_endpoint.go index 614d1f0a81..cd914e9ba8 100644 --- a/agent/consul/federation_state_endpoint.go +++ b/agent/consul/federation_state_endpoint.go @@ -181,7 +181,7 @@ func (c *FederationState) ListMeshGateways(args *structs.DCSpecificRequest, repl dump := make(map[string]structs.CheckServiceNodes) - for i, _ := range fedStates { + for i := range fedStates { fedState := fedStates[i] csn := fedState.MeshGateways if len(csn) > 0 { diff --git a/agent/consul/federation_state_endpoint_test.go b/agent/consul/federation_state_endpoint_test.go index 37b0bb1fc1..6e960fc289 100644 --- a/agent/consul/federation_state_endpoint_test.go +++ b/agent/consul/federation_state_endpoint_test.go @@ -355,7 +355,7 @@ func TestFederationState_List(t *testing.T) { var out structs.IndexedFederationStates require.NoError(t, msgpackrpc.CallWithCodec(codec, "FederationState.List", &args, &out)) - for i, _ := range out.States { + for i := range out.States { zeroFedStateIndexes(t, out.States[i]) } @@ -480,35 +480,35 @@ func TestFederationState_List_ACLDeny(t *testing.T) { } cases := map[string]tcase{ - "no token": tcase{ + "no token": { token: "", listDenied: true, gwListEmpty: true, }, - "no perms": tcase{ + "no perms": { token: nadaToken.SecretID, listDenied: true, gwListEmpty: true, }, - "service:read": tcase{ + "service:read": { token: svcReadToken.SecretID, listDenied: true, gwListEmpty: true, }, - "node:read": tcase{ + "node:read": { token: nodeReadToken.SecretID, listDenied: true, gwListEmpty: true, }, - "service:read and node:read": tcase{ + "service:read and node:read": { token: svcAndNodeReadToken.SecretID, listDenied: true, }, - "operator:read": tcase{ + "operator:read": { token: opReadToken.SecretID, gwListEmpty: true, }, - "master token": tcase{ + "master token": { token: "root", }, } @@ -534,7 +534,7 @@ func TestFederationState_List_ACLDeny(t *testing.T) { } else { require.NoError(t, err) - for i, _ := range out.States { + for i := range out.States { zeroFedStateIndexes(t, out.States[i]) } diff --git a/agent/consul/filter_test.go b/agent/consul/filter_test.go index 15369c1d8f..396ebbbb0b 100644 --- a/agent/consul/filter_test.go +++ b/agent/consul/filter_test.go @@ -18,15 +18,15 @@ func TestFilter_DirEnt(t *testing.T) { out []string } cases := []tcase{ - tcase{ + { in: []string{"foo/test", "foo/priv/nope", "foo/other", "zoo"}, out: []string{"foo/test", "foo/other"}, }, - tcase{ + { in: []string{"abe", "lincoln"}, out: nil, }, - tcase{ + { in: []string{"abe", "foo/1", "foo/2", "foo/3", "nope"}, out: []string{"foo/1", "foo/2", "foo/3"}, }, @@ -60,15 +60,15 @@ func TestFilter_TxnResults(t *testing.T) { out []string } cases := []tcase{ - tcase{ + { in: []string{"foo/test", "foo/priv/nope", "foo/other", "zoo"}, out: []string{"foo/test", "foo/other"}, }, - tcase{ + { in: []string{"abe", "lincoln"}, out: nil, }, - tcase{ + { in: []string{"abe", "foo/1", "foo/2", "foo/3", "nope"}, out: []string{"foo/1", "foo/2", "foo/3"}, }, diff --git a/agent/consul/fsm/snapshot_oss_test.go b/agent/consul/fsm/snapshot_oss_test.go index 70fdae164b..e104819f7f 100644 --- a/agent/consul/fsm/snapshot_oss_test.go +++ b/agent/consul/fsm/snapshot_oss_test.go @@ -91,7 +91,7 @@ func TestFSM_SnapshotRestore_OSS(t *testing.T) { Name: "some-role", Description: "test snapshot role", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "example", }, }, diff --git a/agent/consul/helper_test.go b/agent/consul/helper_test.go index 7373234369..5ea53cff35 100644 --- a/agent/consul/helper_test.go +++ b/agent/consul/helper_test.go @@ -211,7 +211,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { // prep the cluster with some data we can use in our filters registrations := map[string]*structs.RegisterRequest{ - "Node foo": &structs.RegisterRequest{ + "Node foo": { Datacenter: "dc1", Node: "foo", ID: types.NodeID("e0155642-135d-4739-9853-a1ee6c9f945b"), @@ -241,7 +241,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Service redis v1 on foo": &structs.RegisterRequest{ + "Service redis v1 on foo": { Datacenter: "dc1", Node: "foo", SkipNodeUpdate: true, @@ -266,7 +266,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Service redis v2 on foo": &structs.RegisterRequest{ + "Service redis v2 on foo": { Datacenter: "dc1", Node: "foo", SkipNodeUpdate: true, @@ -291,7 +291,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Node bar": &structs.RegisterRequest{ + "Node bar": { Datacenter: "dc1", Node: "bar", ID: types.NodeID("c6e7a976-8f4f-44b5-bdd3-631be7e8ecac"), @@ -314,7 +314,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Service redis v1 on bar": &structs.RegisterRequest{ + "Service redis v1 on bar": { Datacenter: "dc1", Node: "bar", SkipNodeUpdate: true, @@ -339,7 +339,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Service web v1 on bar": &structs.RegisterRequest{ + "Service web v1 on bar": { Datacenter: "dc1", Node: "bar", SkipNodeUpdate: true, @@ -365,7 +365,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Node baz": &structs.RegisterRequest{ + "Node baz": { Datacenter: "dc1", Node: "baz", ID: types.NodeID("12f96b27-a7b0-47bd-add7-044a2bfc7bfb"), @@ -394,7 +394,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Service web v1 on baz": &structs.RegisterRequest{ + "Service web v1 on baz": { Datacenter: "dc1", Node: "baz", SkipNodeUpdate: true, @@ -420,7 +420,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Service web v2 on baz": &structs.RegisterRequest{ + "Service web v2 on baz": { Datacenter: "dc1", Node: "baz", SkipNodeUpdate: true, @@ -446,7 +446,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Service critical on baz": &structs.RegisterRequest{ + "Service critical on baz": { Datacenter: "dc1", Node: "baz", SkipNodeUpdate: true, @@ -471,7 +471,7 @@ func registerTestCatalogEntries(t *testing.T, codec rpc.ClientCodec) { }, }, }, - "Service warning on baz": &structs.RegisterRequest{ + "Service warning on baz": { Datacenter: "dc1", Node: "baz", SkipNodeUpdate: true, @@ -505,7 +505,7 @@ func registerTestCatalogProxyEntries(t *testing.T, codec rpc.ClientCodec) { t.Helper() registrations := map[string]*structs.RegisterRequest{ - "Service tg-gw": &structs.RegisterRequest{ + "Service tg-gw": { Datacenter: "dc1", Node: "terminating-gateway", ID: types.NodeID("3a9d7530-20d4-443a-98d3-c10fe78f09f4"), @@ -518,7 +518,7 @@ func registerTestCatalogProxyEntries(t *testing.T, codec rpc.ClientCodec) { Address: "198.18.1.3", }, }, - "Service mg-gw": &structs.RegisterRequest{ + "Service mg-gw": { Datacenter: "dc1", Node: "gateway", ID: types.NodeID("72e18a4c-85ec-4520-978f-2fc0378b06aa"), @@ -531,7 +531,7 @@ func registerTestCatalogProxyEntries(t *testing.T, codec rpc.ClientCodec) { Address: "198.18.1.4", }, }, - "Service web-proxy": &structs.RegisterRequest{ + "Service web-proxy": { Datacenter: "dc1", Node: "proxy", ID: types.NodeID("2d31602c-3291-4f94-842d-446bc2f945ce"), diff --git a/agent/consul/intention_endpoint.go b/agent/consul/intention_endpoint.go index 5560a778e9..d5070bda06 100644 --- a/agent/consul/intention_endpoint.go +++ b/agent/consul/intention_endpoint.go @@ -437,7 +437,7 @@ func (s *Intention) Check( _, matches, err := state.IntentionMatch(nil, &structs.IntentionQueryMatch{ Type: structs.IntentionMatchDestination, Entries: []structs.IntentionMatchEntry{ - structs.IntentionMatchEntry{ + { Namespace: query.DestinationNS, Name: query.DestinationName, }, diff --git a/agent/consul/intention_endpoint_test.go b/agent/consul/intention_endpoint_test.go index 7123f9fd7e..6359aa4824 100644 --- a/agent/consul/intention_endpoint_test.go +++ b/agent/consul/intention_endpoint_test.go @@ -571,7 +571,7 @@ func TestIntention_WildcardACLEnforcement(t *testing.T) { Match: &structs.IntentionQueryMatch{ Type: structs.IntentionMatchDestination, Entries: []structs.IntentionMatchEntry{ - structs.IntentionMatchEntry{ + { Namespace: "default", Name: "*", }, diff --git a/agent/consul/leader_connect_test.go b/agent/consul/leader_connect_test.go index 5378a67ef6..0f8edc470d 100644 --- a/agent/consul/leader_connect_test.go +++ b/agent/consul/leader_connect_test.go @@ -1076,7 +1076,7 @@ func TestLeader_batchIntentionUpdates(t *testing.T) { { deletes: structs.Intentions{ixn1}, expected: []structs.TxnOps{ - structs.TxnOps{ + { &structs.TxnOp{ Intention: &structs.TxnIntentionOp{ Op: structs.IntentionOpDelete, @@ -1090,7 +1090,7 @@ func TestLeader_batchIntentionUpdates(t *testing.T) { { updates: structs.Intentions{ixn1}, expected: []structs.TxnOps{ - structs.TxnOps{ + { &structs.TxnOp{ Intention: &structs.TxnIntentionOp{ Op: structs.IntentionOpUpdate, @@ -1105,7 +1105,7 @@ func TestLeader_batchIntentionUpdates(t *testing.T) { deletes: structs.Intentions{ixn1}, updates: structs.Intentions{ixn2}, expected: []structs.TxnOps{ - structs.TxnOps{ + { &structs.TxnOp{ Intention: &structs.TxnIntentionOp{ Op: structs.IntentionOpDelete, @@ -1125,7 +1125,7 @@ func TestLeader_batchIntentionUpdates(t *testing.T) { { updates: structs.Intentions{ixnLarge}, expected: []structs.TxnOps{ - structs.TxnOps{ + { &structs.TxnOp{ Intention: &structs.TxnIntentionOp{ Op: structs.IntentionOpUpdate, @@ -1140,7 +1140,7 @@ func TestLeader_batchIntentionUpdates(t *testing.T) { deletes: structs.Intentions{ixn1, ixnLarge}, updates: structs.Intentions{ixn2}, expected: []structs.TxnOps{ - structs.TxnOps{ + { &structs.TxnOp{ Intention: &structs.TxnIntentionOp{ Op: structs.IntentionOpDelete, @@ -1154,7 +1154,7 @@ func TestLeader_batchIntentionUpdates(t *testing.T) { }, }, }, - structs.TxnOps{ + { &structs.TxnOp{ Intention: &structs.TxnIntentionOp{ Op: structs.IntentionOpUpdate, @@ -1169,7 +1169,7 @@ func TestLeader_batchIntentionUpdates(t *testing.T) { deletes: structs.Intentions{ixn1}, updates: structs.Intentions{ixnLarge, ixn2}, expected: []structs.TxnOps{ - structs.TxnOps{ + { &structs.TxnOp{ Intention: &structs.TxnIntentionOp{ Op: structs.IntentionOpDelete, @@ -1183,7 +1183,7 @@ func TestLeader_batchIntentionUpdates(t *testing.T) { }, }, }, - structs.TxnOps{ + { &structs.TxnOp{ Intention: &structs.TxnIntentionOp{ Op: structs.IntentionOpUpdate, diff --git a/agent/consul/leader_federation_state_ae_test.go b/agent/consul/leader_federation_state_ae_test.go index 17d5bf0865..0606081fd7 100644 --- a/agent/consul/leader_federation_state_ae_test.go +++ b/agent/consul/leader_federation_state_ae_test.go @@ -222,7 +222,7 @@ func TestLeader_FederationStateAntiEntropyPruning(t *testing.T) { require.Len(r, remote, 2) require.Len(r, local, 2) - for i, _ := range remote { + for i := range remote { // zero out the raft data for future comparisons remote[i].RaftIndex = structs.RaftIndex{} local[i].RaftIndex = structs.RaftIndex{} @@ -310,7 +310,7 @@ func TestLeader_FederationStateAntiEntropyPruning_ACLDeny(t *testing.T) { require.Len(r, remote, 2) require.Len(r, local, 2) - for i, _ := range remote { + for i := range remote { // zero out the raft data for future comparisons remote[i].RaftIndex = structs.RaftIndex{} local[i].RaftIndex = structs.RaftIndex{} diff --git a/agent/consul/operator_raft_endpoint_test.go b/agent/consul/operator_raft_endpoint_test.go index f119d5f4e3..f585dc8941 100644 --- a/agent/consul/operator_raft_endpoint_test.go +++ b/agent/consul/operator_raft_endpoint_test.go @@ -44,7 +44,7 @@ func TestOperator_RaftGetConfiguration(t *testing.T) { me := future.Configuration().Servers[0] expected := structs.RaftConfigurationResponse{ Servers: []*structs.RaftServer{ - &structs.RaftServer{ + { ID: me.ID, Node: s1.config.NodeName, Address: me.Address, @@ -121,7 +121,7 @@ func TestOperator_RaftGetConfiguration_ACLDeny(t *testing.T) { me := future.Configuration().Servers[0] expected := structs.RaftConfigurationResponse{ Servers: []*structs.RaftServer{ - &structs.RaftServer{ + { ID: me.ID, Node: s1.config.NodeName, Address: me.Address, diff --git a/agent/consul/prepared_query/template.go b/agent/consul/prepared_query/template.go index 466fc143f8..5fa2cd9994 100644 --- a/agent/consul/prepared_query/template.go +++ b/agent/consul/prepared_query/template.go @@ -140,19 +140,19 @@ func (ct *CompiledTemplate) Render(name string, source structs.QuerySource) (*st config := &hil.EvalConfig{ GlobalScope: &ast.BasicScope{ VarMap: map[string]ast.Variable{ - "name.full": ast.Variable{ + "name.full": { Type: ast.TypeString, Value: name, }, - "name.prefix": ast.Variable{ + "name.prefix": { Type: ast.TypeString, Value: query.Name, }, - "name.suffix": ast.Variable{ + "name.suffix": { Type: ast.TypeString, Value: strings.TrimPrefix(name, query.Name), }, - "agent.segment": ast.Variable{ + "agent.segment": { Type: ast.TypeString, Value: source.Segment, }, diff --git a/agent/consul/rpc_test.go b/agent/consul/rpc_test.go index f3afda1c03..864d78a309 100644 --- a/agent/consul/rpc_test.go +++ b/agent/consul/rpc_test.go @@ -837,7 +837,7 @@ func TestRPC_LocalTokenStrippedOnForward(t *testing.T) { ACLToken: structs.ACLToken{ AccessorID: structs.ACLTokenAnonymousID, Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: kvPolicy.ID, }, }, diff --git a/agent/consul/rtt_test.go b/agent/consul/rtt_test.go index 985171eb73..5eacc3deaf 100644 --- a/agent/consul/rtt_test.go +++ b/agent/consul/rtt_test.go @@ -92,27 +92,27 @@ func seedCoordinates(t *testing.T, codec rpc.ClientCodec, server *Server) { // Seed the fixed setup of the nodes. updates := []structs.CoordinateUpdateRequest{ - structs.CoordinateUpdateRequest{ + { Datacenter: "dc1", Node: "node1", Coord: lib.GenerateCoordinate(10 * time.Millisecond), }, - structs.CoordinateUpdateRequest{ + { Datacenter: "dc1", Node: "node2", Coord: lib.GenerateCoordinate(2 * time.Millisecond), }, - structs.CoordinateUpdateRequest{ + { Datacenter: "dc1", Node: "node3", Coord: lib.GenerateCoordinate(1 * time.Millisecond), }, - structs.CoordinateUpdateRequest{ + { Datacenter: "dc1", Node: "node4", Coord: lib.GenerateCoordinate(8 * time.Millisecond), }, - structs.CoordinateUpdateRequest{ + { Datacenter: "dc1", Node: "node5", Coord: lib.GenerateCoordinate(3 * time.Millisecond), diff --git a/agent/consul/server.go b/agent/consul/server.go index 67c2922072..dc65cfaf0d 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -781,7 +781,7 @@ func (s *Server) setupRaft() error { if !hasState { configuration := raft.Configuration{ Servers: []raft.Server{ - raft.Server{ + { ID: s.config.RaftConfig.LocalID, Address: trans.LocalAddr(), }, @@ -1299,7 +1299,7 @@ func (s *Server) Stats() map[string]map[string]string { } numKnownDCs := len(s.router.GetDatacenters()) stats := map[string]map[string]string{ - "consul": map[string]string{ + "consul": { "server": "true", "leader": fmt.Sprintf("%v", s.IsLeader()), "leader_addr": string(s.raft.Leader()), diff --git a/agent/consul/state/acl_oss.go b/agent/consul/state/acl_oss.go index 2970ea77ff..07e381b50b 100644 --- a/agent/consul/state/acl_oss.go +++ b/agent/consul/state/acl_oss.go @@ -17,7 +17,7 @@ func tokensTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "acl-tokens", Indexes: map[string]*memdb.IndexSchema{ - "accessor": &memdb.IndexSchema{ + "accessor": { Name: "accessor", // DEPRECATED (ACL-Legacy-Compat) - we should not AllowMissing here once legacy compat is removed AllowMissing: true, @@ -26,7 +26,7 @@ func tokensTableSchema() *memdb.TableSchema { Field: "AccessorID", }, }, - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -35,20 +35,20 @@ func tokensTableSchema() *memdb.TableSchema { Lowercase: false, }, }, - "policies": &memdb.IndexSchema{ + "policies": { Name: "policies", // Need to allow missing for the anonymous token AllowMissing: true, Unique: false, Indexer: &TokenPoliciesIndex{}, }, - "roles": &memdb.IndexSchema{ + "roles": { Name: "roles", AllowMissing: true, Unique: false, Indexer: &TokenRolesIndex{}, }, - "authmethod": &memdb.IndexSchema{ + "authmethod": { Name: "authmethod", AllowMissing: true, Unique: false, @@ -57,7 +57,7 @@ func tokensTableSchema() *memdb.TableSchema { Lowercase: false, }, }, - "local": &memdb.IndexSchema{ + "local": { Name: "local", AllowMissing: false, Unique: false, @@ -85,7 +85,7 @@ func tokensTableSchema() *memdb.TableSchema { //DEPRECATED (ACL-Legacy-Compat) - This index is only needed while we support upgrading v1 to v2 acls // This table indexes all the ACL tokens that do not have an AccessorID - "needs-upgrade": &memdb.IndexSchema{ + "needs-upgrade": { Name: "needs-upgrade", AllowMissing: false, Unique: false, @@ -106,7 +106,7 @@ func policiesTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "acl-policies", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -114,7 +114,7 @@ func policiesTableSchema() *memdb.TableSchema { Field: "ID", }, }, - "name": &memdb.IndexSchema{ + "name": { Name: "name", AllowMissing: false, Unique: true, @@ -132,7 +132,7 @@ func rolesTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "acl-roles", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -140,7 +140,7 @@ func rolesTableSchema() *memdb.TableSchema { Field: "ID", }, }, - "name": &memdb.IndexSchema{ + "name": { Name: "name", AllowMissing: false, Unique: true, @@ -149,7 +149,7 @@ func rolesTableSchema() *memdb.TableSchema { Lowercase: true, }, }, - "policies": &memdb.IndexSchema{ + "policies": { Name: "policies", // Need to allow missing for the anonymous token AllowMissing: true, @@ -164,7 +164,7 @@ func bindingRulesTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "acl-binding-rules", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -172,7 +172,7 @@ func bindingRulesTableSchema() *memdb.TableSchema { Field: "ID", }, }, - "authmethod": &memdb.IndexSchema{ + "authmethod": { Name: "authmethod", AllowMissing: false, Unique: false, @@ -189,7 +189,7 @@ func authMethodsTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "acl-auth-methods", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, diff --git a/agent/consul/state/acl_test.go b/agent/consul/state/acl_test.go index e5b665fb87..939bb54445 100644 --- a/agent/consul/state/acl_test.go +++ b/agent/consul/state/acl_test.go @@ -121,7 +121,7 @@ func setupExtraPoliciesAndRoles(t *testing.T, s *Store) { Name: "node-read-role", Description: "Allows reading all node information", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_A, }, }, @@ -131,7 +131,7 @@ func setupExtraPoliciesAndRoles(t *testing.T, s *Store) { Name: "agent-read-role", Description: "Allows reading all agent information", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_B, }, }, @@ -247,7 +247,7 @@ func TestStateStore_ACLToken_SetGet_Legacy(t *testing.T) { AccessorID: "c8d0378c-566a-4535-8fc9-c883a8cc9849", SecretID: "6d48ce91-2558-4098-bdab-8737e4e57d5f", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: testPolicyID_A, }, }, @@ -367,7 +367,7 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { AccessorID: "daf37c07-d04d-4fd5-9678-a8206a57d61a", SecretID: "39171632-6f34-4411-827f-9416403687f4", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{}, + {}, }, } @@ -382,7 +382,7 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { AccessorID: "daf37c07-d04d-4fd5-9678-a8206a57d61a", SecretID: "39171632-6f34-4411-827f-9416403687f4", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { Datacenters: []string{"dc1"}, }, }, @@ -399,7 +399,7 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { AccessorID: "daf37c07-d04d-4fd5-9678-a8206a57d61a", SecretID: "39171632-6f34-4411-827f-9416403687f4", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { Name: "no-id", }, }, @@ -416,7 +416,7 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { AccessorID: "daf37c07-d04d-4fd5-9678-a8206a57d61a", SecretID: "39171632-6f34-4411-827f-9416403687f4", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { Name: "no-id", }, }, @@ -433,7 +433,7 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { AccessorID: "daf37c07-d04d-4fd5-9678-a8206a57d61a", SecretID: "39171632-6f34-4411-827f-9416403687f4", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "4f20e379-b496-4b99-9599-19a197126490", }, }, @@ -450,7 +450,7 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { AccessorID: "daf37c07-d04d-4fd5-9678-a8206a57d61a", SecretID: "39171632-6f34-4411-827f-9416403687f4", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: "9b2349b6-55d3-4901-b287-347ae725af2f", }, }, @@ -480,17 +480,17 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { AccessorID: "daf37c07-d04d-4fd5-9678-a8206a57d61a", SecretID: "39171632-6f34-4411-827f-9416403687f4", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: testPolicyID_A, }, }, Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: testRoleID_A, }, }, ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "web", }, }, @@ -520,12 +520,12 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { AccessorID: "daf37c07-d04d-4fd5-9678-a8206a57d61a", SecretID: "39171632-6f34-4411-827f-9416403687f4", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: testPolicyID_A, }, }, ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "web", }, }, @@ -537,17 +537,17 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { AccessorID: "daf37c07-d04d-4fd5-9678-a8206a57d61a", SecretID: "39171632-6f34-4411-827f-9416403687f4", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: testRoleID_A, }, }, ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { ServiceName: "db", }, }, @@ -581,7 +581,7 @@ func TestStateStore_ACLToken_SetGet(t *testing.T) { SecretID: "39171632-6f34-4411-827f-9416403687f4", AuthMethod: "test", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: testRoleID_A, }, }, @@ -744,7 +744,7 @@ func TestStateStore_ACLTokens_UpsertBatchRead(t *testing.T) { SecretID: "00ff4564-dd96-4d1b-8ad6-578a08279f79", Description: "first token", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: testPolicyID_A, }, }, @@ -754,7 +754,7 @@ func TestStateStore_ACLTokens_UpsertBatchRead(t *testing.T) { SecretID: "ff826eaf-4b88-4881-aaef-52b1089e5d5d", Description: "second token", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -801,7 +801,7 @@ func TestStateStore_ACLTokens_UpsertBatchRead(t *testing.T) { AccessorID: "a4f68bd6-3af5-4f56-b764-3c6f20247879", SecretID: "00ff4564-dd96-4d1b-8ad6-578a08279f79", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: fakePolicyID, }, }, @@ -840,7 +840,7 @@ func TestStateStore_ACLTokens_UpsertBatchRead(t *testing.T) { AccessorID: "a4f68bd6-3af5-4f56-b764-3c6f20247879", SecretID: "00ff4564-dd96-4d1b-8ad6-578a08279f79", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: fakeRoleID, }, }, @@ -910,7 +910,7 @@ func TestStateStore_ACLTokens_ListUpgradeable(t *testing.T) { AccessorID: "f1093997-b6c7-496d-bfb8-6b1b1895641b", SecretID: "34ec8eb3-095d-417a-a937-b439af7a8e8b", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -919,7 +919,7 @@ func TestStateStore_ACLTokens_ListUpgradeable(t *testing.T) { AccessorID: "54866514-3cf2-4fec-8a8a-710583831834", SecretID: "8de2dd39-134d-4cb1-950b-b7ab96ea20ba", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -928,7 +928,7 @@ func TestStateStore_ACLTokens_ListUpgradeable(t *testing.T) { AccessorID: "47eea4da-bda1-48a6-901c-3e36d2d9262f", SecretID: "548bdb8e-c0d6-477b-bcc4-67fb836e9e61", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -937,7 +937,7 @@ func TestStateStore_ACLTokens_ListUpgradeable(t *testing.T) { AccessorID: "af1dffe5-8ac2-4282-9336-aeed9f7d951a", SecretID: "3ee33676-d9b8-4144-bf0b-92618cff438b", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -946,7 +946,7 @@ func TestStateStore_ACLTokens_ListUpgradeable(t *testing.T) { AccessorID: "511df589-3316-4784-b503-6e25ead4d4e1", SecretID: "fa9d658a-6e26-42ab-a5f0-1ea05c893dee", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -971,7 +971,7 @@ func TestStateStore_ACLToken_List(t *testing.T) { AccessorID: "f1093997-b6c7-496d-bfb8-6b1b1895641b", SecretID: "34ec8eb3-095d-417a-a937-b439af7a8e8b", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -982,7 +982,7 @@ func TestStateStore_ACLToken_List(t *testing.T) { AccessorID: "54866514-3cf2-4fec-8a8a-710583831834", SecretID: "8de2dd39-134d-4cb1-950b-b7ab96ea20ba", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -992,7 +992,7 @@ func TestStateStore_ACLToken_List(t *testing.T) { AccessorID: "47eea4da-bda1-48a6-901c-3e36d2d9262f", SecretID: "548bdb8e-c0d6-477b-bcc4-67fb836e9e61", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: testPolicyID_A, }, }, @@ -1002,7 +1002,7 @@ func TestStateStore_ACLToken_List(t *testing.T) { AccessorID: "4915fc9d-3726-4171-b588-6c271f45eecd", SecretID: "f6998577-fd9b-4e6c-b202-cc3820513d32", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: testPolicyID_A, }, }, @@ -1013,7 +1013,7 @@ func TestStateStore_ACLToken_List(t *testing.T) { AccessorID: "a7715fde-8954-4c92-afbc-d84c6ecdc582", SecretID: "77a2da3a-b479-4025-a83e-bd6b859f0cfe", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: testRoleID_A, }, }, @@ -1023,7 +1023,7 @@ func TestStateStore_ACLToken_List(t *testing.T) { AccessorID: "cadb4f13-f62a-49ab-ab3f-5a7e01b925d9", SecretID: "c432d12b-3c86-4628-b74f-94ddfc7fb3ba", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: testRoleID_A, }, }, @@ -1239,7 +1239,7 @@ func TestStateStore_ACLToken_FixupPolicyLinks(t *testing.T) { AccessorID: "47eea4da-bda1-48a6-901c-3e36d2d9262f", SecretID: "548bdb8e-c0d6-477b-bcc4-67fb836e9e61", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: testPolicyID_A, }, }, @@ -1365,7 +1365,7 @@ func TestStateStore_ACLToken_FixupRoleLinks(t *testing.T) { AccessorID: "47eea4da-bda1-48a6-901c-3e36d2d9262f", SecretID: "548bdb8e-c0d6-477b-bcc4-67fb836e9e61", Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: testRoleID_A, }, }, @@ -1386,7 +1386,7 @@ func TestStateStore_ACLToken_FixupRoleLinks(t *testing.T) { Name: "node-read-role-renamed", Description: "Allows reading all node information", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_A, }, }, @@ -1490,7 +1490,7 @@ func TestStateStore_ACLToken_Delete(t *testing.T) { AccessorID: "f1093997-b6c7-496d-bfb8-6b1b1895641b", SecretID: "34ec8eb3-095d-417a-a937-b439af7a8e8b", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -1518,7 +1518,7 @@ func TestStateStore_ACLToken_Delete(t *testing.T) { AccessorID: "f1093997-b6c7-496d-bfb8-6b1b1895641b", SecretID: "34ec8eb3-095d-417a-a937-b439af7a8e8b", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -1547,7 +1547,7 @@ func TestStateStore_ACLToken_Delete(t *testing.T) { AccessorID: "f1093997-b6c7-496d-bfb8-6b1b1895641b", SecretID: "34ec8eb3-095d-417a-a937-b439af7a8e8b", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -1557,7 +1557,7 @@ func TestStateStore_ACLToken_Delete(t *testing.T) { AccessorID: "a0bfe8d4-b2f3-4b48-b387-f28afb820eab", SecretID: "be444e46-fb95-4ccc-80d5-c873f34e6fa6", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -2040,7 +2040,7 @@ func TestStateStore_ACLRole_SetGet(t *testing.T) { Name: "test-role", Description: "test", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -2057,7 +2057,7 @@ func TestStateStore_ACLRole_SetGet(t *testing.T) { ID: testRoleID_A, Description: "test", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -2074,7 +2074,7 @@ func TestStateStore_ACLRole_SetGet(t *testing.T) { ID: testRoleID_A, Description: "test", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{}, + {}, }, } @@ -2089,7 +2089,7 @@ func TestStateStore_ACLRole_SetGet(t *testing.T) { ID: testRoleID_A, Description: "test", ServiceIdentities: []*structs.ACLServiceIdentity{ - &structs.ACLServiceIdentity{ + { Datacenters: []string{"dc1"}, }, }, @@ -2106,7 +2106,7 @@ func TestStateStore_ACLRole_SetGet(t *testing.T) { ID: testRoleID_A, Description: "test", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { Name: "no-id", }, }, @@ -2123,7 +2123,7 @@ func TestStateStore_ACLRole_SetGet(t *testing.T) { ID: testRoleID_A, Description: "test", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "4f20e379-b496-4b99-9599-19a197126490", }, }, @@ -2141,7 +2141,7 @@ func TestStateStore_ACLRole_SetGet(t *testing.T) { Name: "my-new-role", Description: "test", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_A, }, }, @@ -2180,7 +2180,7 @@ func TestStateStore_ACLRole_SetGet(t *testing.T) { Name: "node-read-role", Description: "Allows reading all node information", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_A, }, }, @@ -2195,7 +2195,7 @@ func TestStateStore_ACLRole_SetGet(t *testing.T) { Name: "node-read-role-modified", Description: "Modified", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -2247,7 +2247,7 @@ func TestStateStore_ACLRoles_UpsertBatchRead(t *testing.T) { Name: "role1", Description: "test-role1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_A, }, }, @@ -2257,7 +2257,7 @@ func TestStateStore_ACLRoles_UpsertBatchRead(t *testing.T) { Name: "role2", Description: "test-role2", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_B, }, }, @@ -2289,7 +2289,7 @@ func TestStateStore_ACLRoles_UpsertBatchRead(t *testing.T) { Name: "role1", Description: "test-role1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_A, }, }, @@ -2299,7 +2299,7 @@ func TestStateStore_ACLRoles_UpsertBatchRead(t *testing.T) { Name: "role2", Description: "test-role2", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_B, }, }, @@ -2315,7 +2315,7 @@ func TestStateStore_ACLRoles_UpsertBatchRead(t *testing.T) { Name: "role1-modified", Description: "test-role1-modified", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_C, }, }, @@ -2324,10 +2324,10 @@ func TestStateStore_ACLRoles_UpsertBatchRead(t *testing.T) { ID: testRoleID_B, Name: "role2-modified", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_D, }, - structs.ACLRolePolicyLink{ + { ID: testPolicyID_E, }, }, @@ -2369,7 +2369,7 @@ func TestStateStore_ACLRoles_UpsertBatchRead(t *testing.T) { Name: "role1", Description: "test-role1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: fakePolicyID, }, }, @@ -2408,7 +2408,7 @@ func TestStateStore_ACLRole_List(t *testing.T) { Name: "role1", Description: "test-role1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_A, }, }, @@ -2418,7 +2418,7 @@ func TestStateStore_ACLRole_List(t *testing.T) { Name: "role2", Description: "test-role2", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_B, }, }, @@ -2508,7 +2508,7 @@ func TestStateStore_ACLRole_FixupPolicyLinks(t *testing.T) { ID: "672537b1-35cb-48fc-a2cd-a1863c301b70", Name: "test-role", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: testPolicyID_A, }, }, @@ -2631,7 +2631,7 @@ func TestStateStore_ACLRole_Delete(t *testing.T) { Name: "role1", Description: "test-role1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -2660,7 +2660,7 @@ func TestStateStore_ACLRole_Delete(t *testing.T) { Name: "role1", Description: "test-role1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -2690,7 +2690,7 @@ func TestStateStore_ACLRole_Delete(t *testing.T) { Name: "role1", Description: "test-role1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -2700,7 +2700,7 @@ func TestStateStore_ACLRole_Delete(t *testing.T) { Name: "role2", Description: "test-role2", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: structs.ACLPolicyGlobalManagementID, }, }, @@ -3492,7 +3492,7 @@ func TestStateStore_ACLTokens_Snapshot_Restore(t *testing.T) { Name: "role1", Description: "role1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "ca1fc52c-3676-4050-82ed-ca223e38b2c9", }, }, @@ -3502,7 +3502,7 @@ func TestStateStore_ACLTokens_Snapshot_Restore(t *testing.T) { Name: "role2", Description: "role2", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "7b70fa0f-58cd-412d-93c3-a0f17bb19a3e", }, }, @@ -3521,21 +3521,21 @@ func TestStateStore_ACLTokens_Snapshot_Restore(t *testing.T) { SecretID: "838f72b5-5c15-4a9e-aa6d-31734c3a0286", Description: "token1", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "ca1fc52c-3676-4050-82ed-ca223e38b2c9", Name: "policy1", }, - structs.ACLTokenPolicyLink{ + { ID: "7b70fa0f-58cd-412d-93c3-a0f17bb19a3e", Name: "policy2", }, }, Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: "1a3a9af9-9cdc-473a-8016-010067b7e424", Name: "role1", }, - structs.ACLTokenRoleLink{ + { ID: "4dccc2c7-10f3-4eba-b367-9c09be9a9d67", Name: "role2", }, @@ -3546,21 +3546,21 @@ func TestStateStore_ACLTokens_Snapshot_Restore(t *testing.T) { SecretID: "ba5d9239-a4ab-49b9-ae09-1f19eed92204", Description: "token2", Policies: []structs.ACLTokenPolicyLink{ - structs.ACLTokenPolicyLink{ + { ID: "ca1fc52c-3676-4050-82ed-ca223e38b2c9", Name: "policy1", }, - structs.ACLTokenPolicyLink{ + { ID: "7b70fa0f-58cd-412d-93c3-a0f17bb19a3e", Name: "policy2", }, }, Roles: []structs.ACLTokenRoleLink{ - structs.ACLTokenRoleLink{ + { ID: "1a3a9af9-9cdc-473a-8016-010067b7e424", Name: "role1", }, - structs.ACLTokenRoleLink{ + { ID: "4dccc2c7-10f3-4eba-b367-9c09be9a9d67", Name: "role2", }, @@ -3707,7 +3707,7 @@ func TestTokenPoliciesIndex(t *testing.T) { } schema := &memdb.DBSchema{ Tables: map[string]*memdb.TableSchema{ - "test": &memdb.TableSchema{ + "test": { Name: "test", Indexes: map[string]*memdb.IndexSchema{ "id": idIndex, @@ -3887,11 +3887,11 @@ func TestStateStore_ACLRoles_Snapshot_Restore(t *testing.T) { Name: "838f72b5-5c15-4a9e-aa6d-31734c3a0286", Description: "policy1", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "ca1fc52c-3676-4050-82ed-ca223e38b2c9", Name: "policy1", }, - structs.ACLRolePolicyLink{ + { ID: "7b70fa0f-58cd-412d-93c3-a0f17bb19a3e", Name: "policy2", }, @@ -3904,11 +3904,11 @@ func TestStateStore_ACLRoles_Snapshot_Restore(t *testing.T) { Name: "ba5d9239-a4ab-49b9-ae09-1f19eed92204", Description: "policy2", Policies: []structs.ACLRolePolicyLink{ - structs.ACLRolePolicyLink{ + { ID: "ca1fc52c-3676-4050-82ed-ca223e38b2c9", Name: "policy1", }, - structs.ACLRolePolicyLink{ + { ID: "7b70fa0f-58cd-412d-93c3-a0f17bb19a3e", Name: "policy2", }, @@ -4100,7 +4100,7 @@ func TestStateStore_resolveACLLinks(t *testing.T) { defer tx.Abort() links := []agentpb.ACLLink{ - agentpb.ACLLink{ + { Name: "foo", }, } @@ -4123,10 +4123,10 @@ func TestStateStore_resolveACLLinks(t *testing.T) { defer tx.Abort() links := []agentpb.ACLLink{ - agentpb.ACLLink{ + { ID: "b985e082-25d3-45a9-9dd8-fd1a41b83b0d", }, - agentpb.ACLLink{ + { ID: "e81887b4-836b-4053-a1fa-7e8305902be9", }, } @@ -4156,7 +4156,7 @@ func TestStateStore_resolveACLLinks(t *testing.T) { defer tx.Abort() links := []agentpb.ACLLink{ - agentpb.ACLLink{ + { ID: "b985e082-25d3-45a9-9dd8-fd1a41b83b0d", }, } @@ -4176,19 +4176,19 @@ func TestStateStore_fixupACLLinks(t *testing.T) { t.Parallel() links := []agentpb.ACLLink{ - agentpb.ACLLink{ + { ID: "40b57f86-97ea-40e4-a99a-c399cc81f4dd", Name: "foo", }, - agentpb.ACLLink{ + { ID: "8f024f92-1f8e-42ea-a3c3-55fb0c8670bc", Name: "bar", }, - agentpb.ACLLink{ + { ID: "c91afed1-e474-4cd2-98aa-cd57dd9377e9", Name: "baz", }, - agentpb.ACLLink{ + { ID: "c1585be7-ab0e-4973-b572-ba9afda86e07", Name: "four", }, diff --git a/agent/consul/state/autopilot.go b/agent/consul/state/autopilot.go index 7c03dd7ad9..4390a3a588 100644 --- a/agent/consul/state/autopilot.go +++ b/agent/consul/state/autopilot.go @@ -13,7 +13,7 @@ func autopilotConfigTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "autopilot-config", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: true, Unique: true, diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 575213d177..9eec1e44b8 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -29,7 +29,7 @@ func nodesTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "nodes", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -38,7 +38,7 @@ func nodesTableSchema() *memdb.TableSchema { Lowercase: true, }, }, - "uuid": &memdb.IndexSchema{ + "uuid": { Name: "uuid", AllowMissing: true, Unique: true, @@ -46,7 +46,7 @@ func nodesTableSchema() *memdb.TableSchema { Field: "ID", }, }, - "meta": &memdb.IndexSchema{ + "meta": { Name: "meta", AllowMissing: true, Unique: false, @@ -879,7 +879,7 @@ func (s *Store) serviceListTxn(tx *memdb.Txn, ws memdb.WatchSet, entMeta *struct } results := make(structs.ServiceList, 0, len(unique)) - for sn, _ := range unique { + for sn := range unique { results = append(results, structs.ServiceName{Name: sn.Name, EnterpriseMeta: sn.EnterpriseMeta}) } diff --git a/agent/consul/state/catalog_oss.go b/agent/consul/state/catalog_oss.go index b6f20db65d..5cc7d271f3 100644 --- a/agent/consul/state/catalog_oss.go +++ b/agent/consul/state/catalog_oss.go @@ -14,7 +14,7 @@ func servicesTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "services", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -31,7 +31,7 @@ func servicesTableSchema() *memdb.TableSchema { }, }, }, - "node": &memdb.IndexSchema{ + "node": { Name: "node", AllowMissing: false, Unique: false, @@ -40,7 +40,7 @@ func servicesTableSchema() *memdb.TableSchema { Lowercase: true, }, }, - "service": &memdb.IndexSchema{ + "service": { Name: "service", AllowMissing: true, Unique: false, @@ -49,13 +49,13 @@ func servicesTableSchema() *memdb.TableSchema { Lowercase: true, }, }, - "connect": &memdb.IndexSchema{ + "connect": { Name: "connect", AllowMissing: true, Unique: false, Indexer: &IndexConnectService{}, }, - "kind": &memdb.IndexSchema{ + "kind": { Name: "kind", AllowMissing: false, Unique: false, @@ -72,7 +72,7 @@ func checksTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "checks", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -89,7 +89,7 @@ func checksTableSchema() *memdb.TableSchema { }, }, }, - "status": &memdb.IndexSchema{ + "status": { Name: "status", AllowMissing: false, Unique: false, @@ -98,7 +98,7 @@ func checksTableSchema() *memdb.TableSchema { Lowercase: false, }, }, - "service": &memdb.IndexSchema{ + "service": { Name: "service", AllowMissing: true, Unique: false, @@ -107,7 +107,7 @@ func checksTableSchema() *memdb.TableSchema { Lowercase: true, }, }, - "node": &memdb.IndexSchema{ + "node": { Name: "node", AllowMissing: true, Unique: false, @@ -116,7 +116,7 @@ func checksTableSchema() *memdb.TableSchema { Lowercase: true, }, }, - "node_service_check": &memdb.IndexSchema{ + "node_service_check": { Name: "node_service_check", AllowMissing: true, Unique: false, @@ -132,7 +132,7 @@ func checksTableSchema() *memdb.TableSchema { }, }, }, - "node_service": &memdb.IndexSchema{ + "node_service": { Name: "node_service", AllowMissing: true, Unique: false, diff --git a/agent/consul/state/catalog_test.go b/agent/consul/state/catalog_test.go index bc0c052947..11e60767ff 100644 --- a/agent/consul/state/catalog_test.go +++ b/agent/consul/state/catalog_test.go @@ -221,7 +221,7 @@ func TestStateStore_EnsureRegistration(t *testing.T) { // Verify that the service got registered. verifyService := func() { svcmap := map[string]*structs.NodeService{ - "redis1": &structs.NodeService{ + "redis1": { ID: "redis1", Service: "redis", Address: "1.1.1.1", @@ -2225,7 +2225,7 @@ func TestStateStore_Service_Snapshot(t *testing.T) { // Register a node with two services. testRegisterNode(t, s, 0, "node1") ns := []*structs.NodeService{ - &structs.NodeService{ + { ID: "service1", Service: "redis", Tags: []string{"prod"}, @@ -2234,7 +2234,7 @@ func TestStateStore_Service_Snapshot(t *testing.T) { Weights: &structs.Weights{Passing: 1, Warning: 0}, EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - &structs.NodeService{ + { ID: "service2", Service: "nomad", Tags: []string{"dev"}, @@ -4216,7 +4216,7 @@ func TestStateStore_NodeInfo_NodeDump(t *testing.T) { }, }, Services: []*structs.NodeService{ - &structs.NodeService{ + { ID: "service1", Service: "service1", Address: "1.1.1.1", @@ -4229,7 +4229,7 @@ func TestStateStore_NodeInfo_NodeDump(t *testing.T) { }, EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - &structs.NodeService{ + { ID: "service2", Service: "service2", Address: "1.1.1.1", @@ -4273,7 +4273,7 @@ func TestStateStore_NodeInfo_NodeDump(t *testing.T) { }, }, Services: []*structs.NodeService{ - &structs.NodeService{ + { ID: "service1", Service: "service1", Address: "1.1.1.1", @@ -4286,7 +4286,7 @@ func TestStateStore_NodeInfo_NodeDump(t *testing.T) { }, EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - &structs.NodeService{ + { ID: "service2", Service: "service2", Address: "1.1.1.1", @@ -4953,9 +4953,9 @@ func TestStateStore_CheckIngressServiceNodes(t *testing.T) { ids[n.Service.ID] = struct{}{} } expectedIds := map[string]struct{}{ - "ingress1": struct{}{}, - "ingress2": struct{}{}, - "wildcardIngress": struct{}{}, + "ingress1": {}, + "ingress2": {}, + "wildcardIngress": {}, } require.Equal(expectedIds, ids) }) @@ -4971,8 +4971,8 @@ func TestStateStore_CheckIngressServiceNodes(t *testing.T) { ids[n.Service.ID] = struct{}{} } expectedIds := map[string]struct{}{ - "ingress1": struct{}{}, - "wildcardIngress": struct{}{}, + "ingress1": {}, + "wildcardIngress": {}, } require.Equal(expectedIds, ids) }) diff --git a/agent/consul/state/config_entry.go b/agent/consul/state/config_entry.go index 1fbaea78be..25dd51380a 100644 --- a/agent/consul/state/config_entry.go +++ b/agent/consul/state/config_entry.go @@ -439,7 +439,7 @@ func (s *Store) validateProposedConfigEntryInServiceGraph( {Kind: kind, Name: name}: next, } - for chain, _ := range checkChains { + for chain := range checkChains { if err := s.testCompileDiscoveryChain(tx, nil, chain.ID, overrides, &chain.EnterpriseMeta); err != nil { return err } @@ -690,7 +690,7 @@ func anyKey(m map[structs.ServiceID]struct{}) (structs.ServiceID, bool) { if len(m) == 0 { return structs.ServiceID{}, false } - for k, _ := range m { + for k := range m { return k, true } return structs.ServiceID{}, false diff --git a/agent/consul/state/config_entry_oss.go b/agent/consul/state/config_entry_oss.go index cb9cd6a70e..dfb8495470 100644 --- a/agent/consul/state/config_entry_oss.go +++ b/agent/consul/state/config_entry_oss.go @@ -13,7 +13,7 @@ func configTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: configTableName, Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -30,7 +30,7 @@ func configTableSchema() *memdb.TableSchema { }, }, }, - "kind": &memdb.IndexSchema{ + "kind": { Name: "kind", AllowMissing: false, Unique: false, @@ -39,7 +39,7 @@ func configTableSchema() *memdb.TableSchema { Lowercase: true, }, }, - "link": &memdb.IndexSchema{ + "link": { Name: "link", AllowMissing: true, Unique: false, diff --git a/agent/consul/state/config_entry_test.go b/agent/consul/state/config_entry_test.go index 6747991bb4..38f7cc28de 100644 --- a/agent/consul/state/config_entry_test.go +++ b/agent/consul/state/config_entry_test.go @@ -184,7 +184,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectGraphErr bool } cases := map[string]tcase{ - "splitter fails without default protocol": tcase{ + "splitter fails without default protocol": { entries: []structs.ConfigEntry{}, op: func(t *testing.T, s *Store) error { entry := &structs.ServiceSplitterConfigEntry{ @@ -199,7 +199,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: "does not permit advanced routing or splitting behavior", expectGraphErr: true, }, - "splitter fails with tcp protocol": tcase{ + "splitter fails with tcp protocol": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -220,7 +220,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: "does not permit advanced routing or splitting behavior", expectGraphErr: true, }, - "splitter works with http protocol": tcase{ + "splitter works with http protocol": { entries: []structs.ConfigEntry{ &structs.ProxyConfigEntry{ Kind: structs.ProxyDefaults, @@ -239,10 +239,10 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == v2", }, }, @@ -261,7 +261,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { return s.EnsureConfigEntry(0, entry, nil) }, }, - "splitter works with http protocol (from proxy-defaults)": tcase{ + "splitter works with http protocol (from proxy-defaults)": { entries: []structs.ConfigEntry{ &structs.ProxyConfigEntry{ Kind: structs.ProxyDefaults, @@ -274,10 +274,10 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == v2", }, }, @@ -295,7 +295,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { return s.EnsureConfigEntry(0, entry, nil) }, }, - "router fails with tcp protocol": tcase{ + "router fails with tcp protocol": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -306,7 +306,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "other": structs.ServiceResolverSubset{ + "other": { Filter: "Service.Meta.version == other", }, }, @@ -334,13 +334,13 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: "does not permit advanced routing or splitting behavior", expectGraphErr: true, }, - "router fails without default protocol": tcase{ + "router fails without default protocol": { entries: []structs.ConfigEntry{ &structs.ServiceResolverConfigEntry{ Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "other": structs.ServiceResolverSubset{ + "other": { Filter: "Service.Meta.version == other", }, }, @@ -369,7 +369,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectGraphErr: true, }, ///////////////////////////////////////////////// - "cannot remove default protocol after splitter created": tcase{ + "cannot remove default protocol after splitter created": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -380,10 +380,10 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == v2", }, }, @@ -403,7 +403,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: "does not permit advanced routing or splitting behavior", expectGraphErr: true, }, - "cannot remove global default protocol after splitter created": tcase{ + "cannot remove global default protocol after splitter created": { entries: []structs.ConfigEntry{ &structs.ProxyConfigEntry{ Kind: structs.ProxyDefaults, @@ -416,10 +416,10 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == v2", }, }, @@ -439,7 +439,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: "does not permit advanced routing or splitting behavior", expectGraphErr: true, }, - "can remove global default protocol after splitter created if service default overrides it": tcase{ + "can remove global default protocol after splitter created if service default overrides it": { entries: []structs.ConfigEntry{ &structs.ProxyConfigEntry{ Kind: structs.ProxyDefaults, @@ -457,10 +457,10 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == v2", }, }, @@ -478,7 +478,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { return s.DeleteConfigEntry(0, structs.ProxyDefaults, structs.ProxyConfigGlobal, nil) }, }, - "cannot change to tcp protocol after splitter created": tcase{ + "cannot change to tcp protocol after splitter created": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -489,10 +489,10 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == v2", }, }, @@ -517,7 +517,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: "does not permit advanced routing or splitting behavior", expectGraphErr: true, }, - "cannot remove default protocol after router created": tcase{ + "cannot remove default protocol after router created": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -528,7 +528,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "other": structs.ServiceResolverSubset{ + "other": { Filter: "Service.Meta.version == other", }, }, @@ -556,7 +556,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: "does not permit advanced routing or splitting behavior", expectGraphErr: true, }, - "cannot change to tcp protocol after router created": tcase{ + "cannot change to tcp protocol after router created": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -567,7 +567,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "other": structs.ServiceResolverSubset{ + "other": { Filter: "Service.Meta.version == other", }, }, @@ -601,7 +601,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectGraphErr: true, }, ///////////////////////////////////////////////// - "cannot split to a service using tcp": tcase{ + "cannot split to a service using tcp": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -628,7 +628,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: "uses inconsistent protocols", expectGraphErr: true, }, - "cannot route to a service using tcp": tcase{ + "cannot route to a service using tcp": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -664,7 +664,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectGraphErr: true, }, ///////////////////////////////////////////////// - "cannot failover to a service using a different protocol": tcase{ + "cannot failover to a service using a different protocol": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -687,7 +687,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Failover: map[string]structs.ServiceResolverFailover{ - "*": structs.ServiceResolverFailover{ + "*": { Service: "other", }, }, @@ -697,7 +697,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: "uses inconsistent protocols", expectGraphErr: true, }, - "cannot redirect to a service using a different protocol": tcase{ + "cannot redirect to a service using a different protocol": { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, @@ -729,14 +729,14 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectGraphErr: true, }, ///////////////////////////////////////////////// - "redirect to a subset that does exist is fine": tcase{ + "redirect to a subset that does exist is fine": { entries: []structs.ConfigEntry{ &structs.ServiceResolverConfigEntry{ Kind: structs.ServiceResolver, Name: "other", ConnectTimeout: 33 * time.Second, Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, }, @@ -754,7 +754,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { return s.EnsureConfigEntry(0, entry, nil) }, }, - "cannot redirect to a subset that does not exist": tcase{ + "cannot redirect to a subset that does not exist": { entries: []structs.ConfigEntry{ &structs.ServiceResolverConfigEntry{ Kind: structs.ServiceResolver, @@ -777,7 +777,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectGraphErr: true, }, ///////////////////////////////////////////////// - "cannot introduce circular resolver redirect": tcase{ + "cannot introduce circular resolver redirect": { entries: []structs.ConfigEntry{ &structs.ServiceResolverConfigEntry{ Kind: structs.ServiceResolver, @@ -800,7 +800,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) { expectErr: `detected circular resolver redirect`, expectGraphErr: true, }, - "cannot introduce circular split": tcase{ + "cannot introduce circular split": { entries: []structs.ConfigEntry{ &structs.ProxyConfigEntry{ Kind: structs.ProxyDefaults, @@ -1220,10 +1220,10 @@ func TestStore_ReadDiscoveryChainConfigEntries_SubsetSplit(t *testing.T) { Kind: structs.ServiceResolver, Name: "main", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == v2", }, }, diff --git a/agent/consul/state/connect_ca.go b/agent/consul/state/connect_ca.go index cd7b387276..a57f307f83 100644 --- a/agent/consul/state/connect_ca.go +++ b/agent/consul/state/connect_ca.go @@ -22,7 +22,7 @@ func caBuiltinProviderTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: caBuiltinProviderTableName, Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -42,7 +42,7 @@ func caConfigTableSchema() *memdb.TableSchema { Indexes: map[string]*memdb.IndexSchema{ // This table only stores one row, so this just ignores the ID field // and always overwrites the same config object. - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: true, Unique: true, @@ -60,7 +60,7 @@ func caRootTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: caRootTableName, Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, diff --git a/agent/consul/state/coordinate.go b/agent/consul/state/coordinate.go index 95b27fb1c4..7ae0d0cca5 100644 --- a/agent/consul/state/coordinate.go +++ b/agent/consul/state/coordinate.go @@ -14,7 +14,7 @@ func coordinatesTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "coordinates", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -34,7 +34,7 @@ func coordinatesTableSchema() *memdb.TableSchema { }, }, }, - "node": &memdb.IndexSchema{ + "node": { Name: "node", AllowMissing: false, Unique: false, diff --git a/agent/consul/state/federation_state.go b/agent/consul/state/federation_state.go index 1a96f78215..5eb40cf39a 100644 --- a/agent/consul/state/federation_state.go +++ b/agent/consul/state/federation_state.go @@ -13,7 +13,7 @@ func federationStateTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: federationStateTableName, Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, diff --git a/agent/consul/state/graveyard_test.go b/agent/consul/state/graveyard_test.go index 332beaa35d..cd6e8033ec 100644 --- a/agent/consul/state/graveyard_test.go +++ b/agent/consul/state/graveyard_test.go @@ -211,10 +211,10 @@ func TestGraveyard_Snapshot_Restore(t *testing.T) { // Verify the dump, which should be ordered by key. expected := []*Tombstone{ - &Tombstone{Key: "foo/bar/baz", Index: 5}, - &Tombstone{Key: "foo/bar/zoo", Index: 8}, - &Tombstone{Key: "foo/in/the/house", Index: 2}, - &Tombstone{Key: "some/other/path", Index: 9}, + {Key: "foo/bar/baz", Index: 5}, + {Key: "foo/bar/zoo", Index: 8}, + {Key: "foo/in/the/house", Index: 2}, + {Key: "some/other/path", Index: 9}, } if len(expected) != len(dump) { t.Fatalf("expected %d, got %d tombstones", len(expected), len(dump)) diff --git a/agent/consul/state/intention.go b/agent/consul/state/intention.go index 61bb9bd0a1..9b0be42eab 100644 --- a/agent/consul/state/intention.go +++ b/agent/consul/state/intention.go @@ -18,7 +18,7 @@ func intentionsTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: intentionsTableName, Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -26,7 +26,7 @@ func intentionsTableSchema() *memdb.TableSchema { Field: "ID", }, }, - "destination": &memdb.IndexSchema{ + "destination": { Name: "destination", AllowMissing: true, // This index is not unique since we need uniqueness across the whole @@ -45,7 +45,7 @@ func intentionsTableSchema() *memdb.TableSchema { }, }, }, - "source": &memdb.IndexSchema{ + "source": { Name: "source", AllowMissing: true, // This index is not unique since we need uniqueness across the whole @@ -64,7 +64,7 @@ func intentionsTableSchema() *memdb.TableSchema { }, }, }, - "source_destination": &memdb.IndexSchema{ + "source_destination": { Name: "source_destination", AllowMissing: true, Unique: true, diff --git a/agent/consul/state/kvs.go b/agent/consul/state/kvs.go index ab412c133b..85a532fb77 100644 --- a/agent/consul/state/kvs.go +++ b/agent/consul/state/kvs.go @@ -14,13 +14,13 @@ func kvsTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "kvs", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, Indexer: kvsIndexer(), }, - "session": &memdb.IndexSchema{ + "session": { Name: "session", AllowMissing: true, Unique: false, @@ -38,7 +38,7 @@ func tombstonesTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "tombstones", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, diff --git a/agent/consul/state/prepared_query.go b/agent/consul/state/prepared_query.go index 89a8f83493..afdfe71402 100644 --- a/agent/consul/state/prepared_query.go +++ b/agent/consul/state/prepared_query.go @@ -15,7 +15,7 @@ func preparedQueriesTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "prepared-queries", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -23,7 +23,7 @@ func preparedQueriesTableSchema() *memdb.TableSchema { Field: "ID", }, }, - "name": &memdb.IndexSchema{ + "name": { Name: "name", AllowMissing: true, Unique: true, @@ -32,13 +32,13 @@ func preparedQueriesTableSchema() *memdb.TableSchema { Lowercase: true, }, }, - "template": &memdb.IndexSchema{ + "template": { Name: "template", AllowMissing: true, Unique: true, Indexer: &PreparedQueryIndex{}, }, - "session": &memdb.IndexSchema{ + "session": { Name: "session", AllowMissing: true, Unique: false, diff --git a/agent/consul/state/schema.go b/agent/consul/state/schema.go index e24b23618c..8ab6565a84 100644 --- a/agent/consul/state/schema.go +++ b/agent/consul/state/schema.go @@ -44,7 +44,7 @@ func indexTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "index", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, diff --git a/agent/consul/state/session.go b/agent/consul/state/session.go index 8f32bd3944..aeddeb6732 100644 --- a/agent/consul/state/session.go +++ b/agent/consul/state/session.go @@ -16,13 +16,13 @@ func sessionsTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "sessions", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, Indexer: sessionIndexer(), }, - "node": &memdb.IndexSchema{ + "node": { Name: "node", AllowMissing: false, Unique: false, @@ -38,7 +38,7 @@ func sessionChecksTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "session_checks", Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ + "id": { Name: "id", AllowMissing: false, Unique: true, @@ -55,13 +55,13 @@ func sessionChecksTableSchema() *memdb.TableSchema { }, }, }, - "node_check": &memdb.IndexSchema{ + "node_check": { Name: "node_check", AllowMissing: false, Unique: false, Indexer: nodeChecksIndexer(), }, - "session": &memdb.IndexSchema{ + "session": { Name: "session", AllowMissing: false, Unique: false, diff --git a/agent/consul/state/session_test.go b/agent/consul/state/session_test.go index d4f9e85db7..af27e746a1 100644 --- a/agent/consul/state/session_test.go +++ b/agent/consul/state/session_test.go @@ -285,11 +285,11 @@ func TestStateStore_NodeSessions(t *testing.T) { }, } sessions2 := []*structs.Session{ - &structs.Session{ + { ID: testUUID(), Node: "node2", }, - &structs.Session{ + { ID: testUUID(), Node: "node2", }, diff --git a/agent/consul/state/txn_test.go b/agent/consul/state/txn_test.go index 11206624ce..66f19b61ae 100644 --- a/agent/consul/state/txn_test.go +++ b/agent/consul/state/txn_test.go @@ -324,7 +324,7 @@ func TestStateStore_Txn_Service(t *testing.T) { }, }, Services: map[string]*structs.NodeService{ - "svc1": &structs.NodeService{ + "svc1": { ID: "svc1", Service: "svc1", Address: "1.1.1.1", @@ -337,7 +337,7 @@ func TestStateStore_Txn_Service(t *testing.T) { EnterpriseMeta: *structs.DefaultEnterpriseMeta(), Meta: map[string]string{}, }, - "svc5": &structs.NodeService{ + "svc5": { ID: "svc5", RaftIndex: structs.RaftIndex{ CreateIndex: 6, @@ -346,7 +346,7 @@ func TestStateStore_Txn_Service(t *testing.T) { Weights: &structs.Weights{Passing: 1, Warning: 1}, EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - "svc2": &structs.NodeService{ + "svc2": { ID: "svc2", Tags: []string{"modified"}, RaftIndex: structs.RaftIndex{ diff --git a/agent/consul/util_test.go b/agent/consul/util_test.go index 3307ada8ba..9f7947b521 100644 --- a/agent/consul/util_test.go +++ b/agent/consul/util_test.go @@ -628,7 +628,7 @@ func TestServersGetACLMode(t *testing.T) { } cases := map[string]tcase{ - "filter-members": tcase{ + "filter-members": { servers: testServersProvider{ makeServer("primary", structs.ACLModeLegacy, serf.StatusAlive, net.IP([]byte{127, 0, 0, 1})), makeServer("primary", structs.ACLModeLegacy, serf.StatusFailed, net.IP([]byte{127, 0, 0, 2})), @@ -647,7 +647,7 @@ func TestServersGetACLMode(t *testing.T) { minMode: structs.ACLModeLegacy, leaderMode: structs.ACLModeLegacy, }, - "disabled": tcase{ + "disabled": { servers: testServersProvider{ makeServer("primary", structs.ACLModeLegacy, serf.StatusAlive, net.IP([]byte{127, 0, 0, 1})), makeServer("primary", structs.ACLModeUnknown, serf.StatusAlive, net.IP([]byte{127, 0, 0, 2})), @@ -659,7 +659,7 @@ func TestServersGetACLMode(t *testing.T) { minMode: structs.ACLModeDisabled, leaderMode: structs.ACLModeLegacy, }, - "unknown": tcase{ + "unknown": { servers: testServersProvider{ makeServer("primary", structs.ACLModeLegacy, serf.StatusAlive, net.IP([]byte{127, 0, 0, 1})), makeServer("primary", structs.ACLModeUnknown, serf.StatusAlive, net.IP([]byte{127, 0, 0, 2})), @@ -670,7 +670,7 @@ func TestServersGetACLMode(t *testing.T) { minMode: structs.ACLModeUnknown, leaderMode: structs.ACLModeLegacy, }, - "legacy": tcase{ + "legacy": { servers: testServersProvider{ makeServer("primary", structs.ACLModeEnabled, serf.StatusAlive, net.IP([]byte{127, 0, 0, 1})), makeServer("primary", structs.ACLModeLegacy, serf.StatusAlive, net.IP([]byte{127, 0, 0, 2})), @@ -681,7 +681,7 @@ func TestServersGetACLMode(t *testing.T) { minMode: structs.ACLModeLegacy, leaderMode: structs.ACLModeEnabled, }, - "enabled": tcase{ + "enabled": { servers: testServersProvider{ makeServer("primary", structs.ACLModeEnabled, serf.StatusAlive, net.IP([]byte{127, 0, 0, 1})), makeServer("primary", structs.ACLModeEnabled, serf.StatusAlive, net.IP([]byte{127, 0, 0, 2})), @@ -693,7 +693,7 @@ func TestServersGetACLMode(t *testing.T) { minMode: structs.ACLModeEnabled, leaderMode: structs.ACLModeEnabled, }, - "failed-members": tcase{ + "failed-members": { servers: testServersProvider{ makeServer("primary", structs.ACLModeLegacy, serf.StatusAlive, net.IP([]byte{127, 0, 0, 1})), makeServer("primary", structs.ACLModeUnknown, serf.StatusFailed, net.IP([]byte{127, 0, 0, 2})), diff --git a/agent/discovery_chain_endpoint_test.go b/agent/discovery_chain_endpoint_test.go index 6edaf101bd..fd46499422 100644 --- a/agent/discovery_chain_endpoint_test.go +++ b/agent/discovery_chain_endpoint_test.go @@ -76,7 +76,7 @@ func TestDiscoveryChainRead(t *testing.T) { Protocol: "tcp", StartNode: "resolver:web.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:web.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:web.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "web.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -119,7 +119,7 @@ func TestDiscoveryChainRead(t *testing.T) { Protocol: "tcp", StartNode: "resolver:web.default.dc2", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:web.default.dc2": &structs.DiscoveryGraphNode{ + "resolver:web.default.dc2": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "web.default.dc2", Resolver: &structs.DiscoveryResolver{ @@ -171,7 +171,7 @@ func TestDiscoveryChainRead(t *testing.T) { Protocol: "tcp", StartNode: "resolver:web.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:web.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:web.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "web.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -233,7 +233,7 @@ func TestDiscoveryChainRead(t *testing.T) { Protocol: "tcp", StartNode: "resolver:web.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:web.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:web.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "web.default.dc1", Resolver: &structs.DiscoveryResolver{ @@ -269,7 +269,7 @@ func TestDiscoveryChainRead(t *testing.T) { CustomizationHash: "98809527", StartNode: "resolver:web.default.dc1", Nodes: map[string]*structs.DiscoveryGraphNode{ - "resolver:web.default.dc1": &structs.DiscoveryGraphNode{ + "resolver:web.default.dc1": { Type: structs.DiscoveryGraphNodeTypeResolver, Name: "web.default.dc1", Resolver: &structs.DiscoveryResolver{ diff --git a/agent/dns_test.go b/agent/dns_test.go index fb0f1a8cc3..cfc373b3c4 100644 --- a/agent/dns_test.go +++ b/agent/dns_test.go @@ -2496,13 +2496,13 @@ func TestDNS_ServiceLookup_WanTranslation(t *testing.T) { } cases := map[string]testCase{ - "node-addr-from-dc1": testCase{ + "node-addr-from-dc1": { dnsAddr: a1.config.DNSAddrs[0].String(), expectedPort: 8080, expectedAddress: "127.0.0.1", expectedARRName: "foo.node.dc2.consul.", }, - "node-wan-from-dc1": testCase{ + "node-wan-from-dc1": { dnsAddr: a1.config.DNSAddrs[0].String(), nodeTaggedAddresses: map[string]string{ "wan": "127.0.0.2", @@ -2511,7 +2511,7 @@ func TestDNS_ServiceLookup_WanTranslation(t *testing.T) { expectedAddress: "127.0.0.2", expectedARRName: "7f000002.addr.dc2.consul.", }, - "service-addr-from-dc1": testCase{ + "service-addr-from-dc1": { dnsAddr: a1.config.DNSAddrs[0].String(), nodeTaggedAddresses: map[string]string{ "wan": "127.0.0.2", @@ -2521,14 +2521,14 @@ func TestDNS_ServiceLookup_WanTranslation(t *testing.T) { expectedAddress: "10.0.1.1", expectedARRName: "0a000101.addr.dc2.consul.", }, - "service-wan-from-dc1": testCase{ + "service-wan-from-dc1": { dnsAddr: a1.config.DNSAddrs[0].String(), nodeTaggedAddresses: map[string]string{ "wan": "127.0.0.2", }, serviceAddress: "10.0.1.1", serviceTaggedAddresses: map[string]structs.ServiceAddress{ - "wan": structs.ServiceAddress{ + "wan": { Address: "198.18.0.1", Port: 80, }, @@ -2537,13 +2537,13 @@ func TestDNS_ServiceLookup_WanTranslation(t *testing.T) { expectedAddress: "198.18.0.1", expectedARRName: "c6120001.addr.dc2.consul.", }, - "node-addr-from-dc2": testCase{ + "node-addr-from-dc2": { dnsAddr: a2.config.DNSAddrs[0].String(), expectedPort: 8080, expectedAddress: "127.0.0.1", expectedARRName: "foo.node.dc2.consul.", }, - "node-wan-from-dc2": testCase{ + "node-wan-from-dc2": { dnsAddr: a2.config.DNSAddrs[0].String(), nodeTaggedAddresses: map[string]string{ "wan": "127.0.0.2", @@ -2552,7 +2552,7 @@ func TestDNS_ServiceLookup_WanTranslation(t *testing.T) { expectedAddress: "127.0.0.1", expectedARRName: "foo.node.dc2.consul.", }, - "service-addr-from-dc2": testCase{ + "service-addr-from-dc2": { dnsAddr: a2.config.DNSAddrs[0].String(), nodeTaggedAddresses: map[string]string{ "wan": "127.0.0.2", @@ -2562,14 +2562,14 @@ func TestDNS_ServiceLookup_WanTranslation(t *testing.T) { expectedAddress: "10.0.1.1", expectedARRName: "0a000101.addr.dc2.consul.", }, - "service-wan-from-dc2": testCase{ + "service-wan-from-dc2": { dnsAddr: a2.config.DNSAddrs[0].String(), nodeTaggedAddresses: map[string]string{ "wan": "127.0.0.2", }, serviceAddress: "10.0.1.1", serviceTaggedAddresses: map[string]structs.ServiceAddress{ - "wan": structs.ServiceAddress{ + "wan": { Address: "198.18.0.1", Port: 80, }, @@ -2685,7 +2685,7 @@ func TestDNS_Lookup_TaggedIPAddresses(t *testing.T) { } cases := map[string]testCase{ - "simple-ipv4": testCase{ + "simple-ipv4": { serviceAddress: "127.0.0.2", nodeAddress: "127.0.0.1", @@ -2694,7 +2694,7 @@ func TestDNS_Lookup_TaggedIPAddresses(t *testing.T) { expectedNodeIPv4Address: "127.0.0.1", expectedNodeIPv6Address: "", }, - "simple-ipv6": testCase{ + "simple-ipv6": { serviceAddress: "::2", nodeAddress: "::1", @@ -2703,7 +2703,7 @@ func TestDNS_Lookup_TaggedIPAddresses(t *testing.T) { expectedNodeIPv6Address: "::1", expectedNodeIPv4Address: "", }, - "ipv4-with-tagged-ipv6": testCase{ + "ipv4-with-tagged-ipv6": { serviceAddress: "127.0.0.2", nodeAddress: "127.0.0.1", @@ -2719,7 +2719,7 @@ func TestDNS_Lookup_TaggedIPAddresses(t *testing.T) { expectedNodeIPv4Address: "127.0.0.1", expectedNodeIPv6Address: "::1", }, - "ipv6-with-tagged-ipv4": testCase{ + "ipv6-with-tagged-ipv4": { serviceAddress: "::2", nodeAddress: "::1", diff --git a/agent/event_endpoint_test.go b/agent/event_endpoint_test.go index f15ec8de1e..fb138513a9 100644 --- a/agent/event_endpoint_test.go +++ b/agent/event_endpoint_test.go @@ -302,11 +302,11 @@ func TestEventList_EventBufOrder(t *testing.T) { expected := &UserEvent{Name: "foo"} for _, e := range []*UserEvent{ - &UserEvent{Name: "foo"}, - &UserEvent{Name: "bar"}, - &UserEvent{Name: "foo"}, + {Name: "foo"}, + {Name: "bar"}, + {Name: "foo"}, expected, - &UserEvent{Name: "bar"}, + {Name: "bar"}, } { if err := a.UserEvent("dc1", "root", e); err != nil { t.Fatalf("err: %v", err) diff --git a/agent/health_endpoint_test.go b/agent/health_endpoint_test.go index 61de07439d..2438cc2c95 100644 --- a/agent/health_endpoint_test.go +++ b/agent/health_endpoint_test.go @@ -1065,7 +1065,7 @@ func TestHealthServiceNodes_WanTranslation(t *testing.T) { Address: "127.0.0.1", Port: 8080, TaggedAddresses: map[string]structs.ServiceAddress{ - "wan": structs.ServiceAddress{ + "wan": { Address: "1.2.3.4", Port: 80, }, diff --git a/agent/http_decode_test.go b/agent/http_decode_test.go index 32f56c9db3..3a1c2b7cf2 100644 --- a/agent/http_decode_test.go +++ b/agent/http_decode_test.go @@ -226,9 +226,9 @@ var checkTypeHeaderTestCases = []struct { desc: "filled in map", in: `{"a": ["aa", "aaa"], "b": ["bb", "bbb", "bbbb"], "c": [], "d": ["dd"]}`, want: map[string][]string{ - "a": []string{"aa", "aaa"}, - "b": []string{"bb", "bbb", "bbbb"}, - "d": []string{"dd"}, + "a": {"aa", "aaa"}, + "b": {"bb", "bbb", "bbbb"}, + "d": {"dd"}, }, }, { diff --git a/agent/http_oss_test.go b/agent/http_oss_test.go index 494767f179..62dafc61a4 100644 --- a/agent/http_oss_test.go +++ b/agent/http_oss_test.go @@ -16,10 +16,10 @@ import ( // extra endpoints that should be tested, and their allowed methods var extraTestEndpoints = map[string][]string{ - "/v1/query": []string{"GET", "POST"}, - "/v1/query/": []string{"GET", "PUT", "DELETE"}, - "/v1/query/xxx/execute": []string{"GET"}, - "/v1/query/xxx/explain": []string{"GET"}, + "/v1/query": {"GET", "POST"}, + "/v1/query/": {"GET", "PUT", "DELETE"}, + "/v1/query/xxx/execute": {"GET"}, + "/v1/query/xxx/explain": {"GET"}, } // These endpoints are ignored in unit testing for response codes diff --git a/agent/prepared_query_endpoint_test.go b/agent/prepared_query_endpoint_test.go index 0e375faf93..e67b08cafa 100644 --- a/agent/prepared_query_endpoint_test.go +++ b/agent/prepared_query_endpoint_test.go @@ -519,7 +519,7 @@ func TestPreparedQuery_Execute(t *testing.T) { Address: "10.0.1.1", Port: 8080, TaggedAddresses: map[string]structs.ServiceAddress{ - "wan": structs.ServiceAddress{ + "wan": { Address: "198.18.0.1", Port: 80, }, diff --git a/agent/proxycfg/snapshot.go b/agent/proxycfg/snapshot.go index 2ae7f1b231..b5f6e6f696 100644 --- a/agent/proxycfg/snapshot.go +++ b/agent/proxycfg/snapshot.go @@ -175,10 +175,10 @@ func (c *configSnapshotMeshGateway) Datacenters() []string { } dcs := make([]string, 0, sz) - for dc, _ := range c.GatewayGroups { + for dc := range c.GatewayGroups { dcs = append(dcs, dc) } - for dc, _ := range c.FedStateGateways { + for dc := range c.FedStateGateways { if _, ok := c.GatewayGroups[dc]; !ok { dcs = append(dcs, dc) } diff --git a/agent/proxycfg/state.go b/agent/proxycfg/state.go index db62075ffc..5a43cb9148 100644 --- a/agent/proxycfg/state.go +++ b/agent/proxycfg/state.go @@ -97,7 +97,7 @@ func copyProxyConfig(ns *structs.NodeService) (structs.ConnectProxyConfig, error } // we can safely modify these since we just copied them - for idx, _ := range proxyCfg.Upstreams { + for idx := range proxyCfg.Upstreams { us := &proxyCfg.Upstreams[idx] if us.DestinationType != structs.UpstreamDestTypePreparedQuery && us.DestinationNamespace == "" { // default the upstreams target namespace to the namespace of the proxy @@ -862,7 +862,7 @@ func (s *state) resetWatchesFromChain( snap.WatchedUpstreams[id][target.ID] = cancel } - for dc, _ := range needGateways { + for dc := range needGateways { if _, ok := snap.WatchedGateways[id][dc]; ok { continue } @@ -1029,14 +1029,14 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config } // Delete gateway service mapping for services that were not in the update - for sn, _ := range snap.TerminatingGateway.GatewayServices { + for sn := range snap.TerminatingGateway.GatewayServices { if _, ok := svcMap[sn]; !ok { delete(snap.TerminatingGateway.GatewayServices, sn) } } // Clean up services with hostname mapping for services that were not in the update - for sn, _ := range snap.TerminatingGateway.HostnameServices { + for sn := range snap.TerminatingGateway.HostnameServices { if _, ok := svcMap[sn]; !ok { delete(snap.TerminatingGateway.HostnameServices, sn) } @@ -1157,7 +1157,7 @@ func (s *state) handleUpdateMeshGateway(u cache.UpdateEvent, snap *ConfigSnapsho snap.MeshGateway.HostnameDatacenters[dc] = s.hostnameEndpoints(logging.MeshGateway, snap.Datacenter, nodes) } - for dc, _ := range snap.MeshGateway.HostnameDatacenters { + for dc := range snap.MeshGateway.HostnameDatacenters { if _, ok := dcIndexedNodes.DatacenterNodes[dc]; !ok { delete(snap.MeshGateway.HostnameDatacenters, dc) } diff --git a/agent/proxycfg/state_test.go b/agent/proxycfg/state_test.go index 6006da26db..6f2f686901 100644 --- a/agent/proxycfg/state_test.go +++ b/agent/proxycfg/state_test.go @@ -476,12 +476,12 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, events: []cache.UpdateEvent{ rootWatchEvent(), - cache.UpdateEvent{ + { CorrelationID: leafWatchID, Result: issuedCert, Err: nil, }, - cache.UpdateEvent{ + { CorrelationID: "discovery-chain:api", Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api", "default", "dc1", "trustdomain.consul", "dc1", @@ -491,7 +491,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, Err: nil, }, - cache.UpdateEvent{ + { CorrelationID: "discovery-chain:api-failover-remote?dc=dc2", Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api-failover-remote", "default", "dc2", "trustdomain.consul", "dc1", @@ -501,7 +501,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, Err: nil, }, - cache.UpdateEvent{ + { CorrelationID: "discovery-chain:api-failover-local?dc=dc2", Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api-failover-local", "default", "dc2", "trustdomain.consul", "dc1", @@ -511,7 +511,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, Err: nil, }, - cache.UpdateEvent{ + { CorrelationID: "discovery-chain:api-failover-direct?dc=dc2", Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api-failover-direct", "default", "dc2", "trustdomain.consul", "dc1", @@ -521,7 +521,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, Err: nil, }, - cache.UpdateEvent{ + { CorrelationID: "discovery-chain:api-dc2", Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api-dc2", "default", "dc1", "trustdomain.consul", "dc1", @@ -603,7 +603,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { apiStr := api.String() cases := map[string]testCase{ - "initial-gateway": testCase{ + "initial-gateway": { ns: structs.NodeService{ Kind: structs.ServiceKindMeshGateway, ID: "mesh-gateway", @@ -613,7 +613,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, sourceDC: "dc1", stages: []verificationStage{ - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ rootsWatchID: genVerifyRootsWatch("dc1"), serviceListWatchID: genVerifyListServicesWatch("dc1"), @@ -624,7 +624,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.True(t, snap.ConnectProxy.IsEmpty()) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ rootWatchEvent(), }, @@ -640,9 +640,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Empty(t, snap.MeshGateway.GatewayGroups) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: serviceListWatchID, Result: &structs.IndexedServiceList{ Services: make(structs.ServiceList, 0), @@ -664,7 +664,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, }, }, - "mesh-gateway-do-not-cancel-service-watches": testCase{ + "mesh-gateway-do-not-cancel-service-watches": { ns: structs.NodeService{ Kind: structs.ServiceKindMeshGateway, ID: "mesh-gateway", @@ -674,7 +674,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, sourceDC: "dc1", stages: []verificationStage{ - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ rootsWatchID: genVerifyRootsWatch("dc1"), serviceListWatchID: genVerifyListServicesWatch("dc1"), @@ -682,7 +682,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, events: []cache.UpdateEvent{ rootWatchEvent(), - cache.UpdateEvent{ + { CorrelationID: serviceListWatchID, Result: &structs.IndexedServiceList{ Services: structs.ServiceList{ @@ -698,9 +698,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.True(t, snap.MeshGateway.WatchedServicesSet) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: serviceListWatchID, Result: &structs.IndexedServiceList{ Services: structs.ServiceList{ @@ -717,9 +717,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.True(t, snap.MeshGateway.WatchedServicesSet) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: "mesh-gateway:dc4", Result: &structs.IndexedCheckServiceNodes{ Nodes: TestGatewayNodesDC4Hostname(t), @@ -761,9 +761,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Equal(t, snap.MeshGateway.HostnameDatacenters["dc4"], expect) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: federationStateListGatewaysWatchID, Result: &structs.DatacenterIndexedCheckServiceNodes{ DatacenterNodes: map[string]structs.CheckServiceNodes{ @@ -809,7 +809,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, }, }, - "ingress-gateway": testCase{ + "ingress-gateway": { ns: structs.NodeService{ Kind: structs.ServiceKindIngressGateway, ID: "ingress-gateway", @@ -818,7 +818,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, sourceDC: "dc1", stages: []verificationStage{ - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ rootsWatchID: genVerifyRootsWatch("dc1"), gatewayConfigWatchID: genVerifyConfigEntryWatch(structs.IngressGateway, "ingress-gateway", "dc1"), @@ -829,7 +829,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.True(t, snap.IngressGateway.IsEmpty()) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ rootWatchEvent(), }, @@ -838,7 +838,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Equal(t, indexedRoots, snap.Roots) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ ingressConfigWatchEvent(false), }, @@ -848,9 +848,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.False(t, snap.IngressGateway.TLSEnabled) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: gatewayServicesWatchID, Result: &structs.IndexedGatewayServices{ Services: structs.GatewayServices{ @@ -885,12 +885,12 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Contains(t, snap.IngressGateway.WatchedDiscoveryChains, "api") }, }, - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ leafWatchID: genVerifyLeafWatch("ingress-gateway", "dc1"), }, events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: leafWatchID, Result: issuedCert, Err: nil, @@ -901,7 +901,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Equal(t, issuedCert, snap.IngressGateway.Leaf) }, }, - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ "discovery-chain:api": genVerifyDiscoveryChainWatch(&structs.DiscoveryChainRequest{ Name: "api", @@ -911,7 +911,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }), }, events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: "discovery-chain:api", Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api", "default", "dc1", "trustdomain.consul", "dc1", nil), @@ -924,12 +924,12 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Len(t, snap.IngressGateway.WatchedUpstreams["api"], 1) }, }, - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ "upstream-target:api.default.dc1:api": genVerifyServiceWatch("api", "", "dc1", true), }, events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: "upstream-target:api.default.dc1:api", Result: &structs.IndexedCheckServiceNodes{ Nodes: structs.CheckServiceNodes{ @@ -971,7 +971,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, }, }, - "ingress-gateway-with-tls-update-upstreams": testCase{ + "ingress-gateway-with-tls-update-upstreams": { ns: structs.NodeService{ Kind: structs.ServiceKindIngressGateway, ID: "ingress-gateway", @@ -980,7 +980,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, sourceDC: "dc1", stages: []verificationStage{ - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ rootsWatchID: genVerifyRootsWatch("dc1"), gatewayConfigWatchID: genVerifyConfigEntryWatch(structs.IngressGateway, "ingress-gateway", "dc1"), @@ -989,7 +989,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { events: []cache.UpdateEvent{ rootWatchEvent(), ingressConfigWatchEvent(true), - cache.UpdateEvent{ + { CorrelationID: gatewayServicesWatchID, Result: &structs.IndexedGatewayServices{ Services: structs.GatewayServices{ @@ -1003,7 +1003,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, Err: nil, }, - cache.UpdateEvent{ + { CorrelationID: leafWatchID, Result: issuedCert, Err: nil, @@ -1020,7 +1020,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Contains(t, snap.IngressGateway.WatchedDiscoveryChains, "api") }, }, - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ leafWatchID: genVerifyLeafWatchWithDNSSANs("ingress-gateway", "dc1", []string{ "test.example.com", @@ -1031,7 +1031,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }), }, events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: gatewayServicesWatchID, Result: &structs.IndexedGatewayServices{}, Err: nil, @@ -1046,7 +1046,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, }, }, - "terminating-gateway-initial": testCase{ + "terminating-gateway-initial": { ns: structs.NodeService{ Kind: structs.ServiceKindTerminatingGateway, ID: "terminating-gateway", @@ -1055,7 +1055,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, sourceDC: "dc1", stages: []verificationStage{ - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ rootsWatchID: genVerifyRootsWatch("dc1"), gatewayServicesWatchID: genVerifyServiceSpecificRequest(gatewayServicesWatchID, @@ -1068,7 +1068,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.True(t, snap.IngressGateway.IsEmpty()) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ rootWatchEvent(), }, @@ -1083,7 +1083,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, }, }, - "terminating-gateway-handle-update": testCase{ + "terminating-gateway-handle-update": { ns: structs.NodeService{ Kind: structs.ServiceKindTerminatingGateway, ID: "terminating-gateway", @@ -1092,7 +1092,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, sourceDC: "dc1", stages: []verificationStage{ - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ rootsWatchID: genVerifyRootsWatch("dc1"), gatewayServicesWatchID: genVerifyServiceSpecificRequest(gatewayServicesWatchID, @@ -1100,7 +1100,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, events: []cache.UpdateEvent{ rootWatchEvent(), - cache.UpdateEvent{ + { CorrelationID: gatewayServicesWatchID, Result: &structs.IndexedGatewayServices{ Services: structs.GatewayServices{ @@ -1118,9 +1118,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Len(t, snap.TerminatingGateway.WatchedServices, 1) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: gatewayServicesWatchID, Result: &structs.IndexedGatewayServices{ Services: structs.GatewayServices{ @@ -1173,12 +1173,12 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Contains(t, snap.TerminatingGateway.GatewayServices, api) }, }, - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ "external-service:" + dbStr: genVerifyServiceWatch("db", "", "dc1", false), }, events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: "external-service:" + dbStr, Result: &structs.IndexedCheckServiceNodes{ Nodes: structs.CheckServiceNodes{ @@ -1215,12 +1215,12 @@ func TestState_WatchesAndUpdates(t *testing.T) { ) }, }, - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ "external-service:" + apiStr: genVerifyServiceWatch("api", "", "dc1", false), }, events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: "external-service:" + apiStr, Result: &structs.IndexedCheckServiceNodes{ Nodes: structs.CheckServiceNodes{ @@ -1306,12 +1306,12 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.ElementsMatch(t, snap.TerminatingGateway.HostnameServices[sn], expect[:2]) }, }, - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ "service-leaf:" + dbStr: genVerifyLeafWatch("db", "dc1"), }, events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: "service-leaf:" + dbStr, Result: issuedCert, Err: nil, @@ -1321,12 +1321,12 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Equal(t, snap.TerminatingGateway.ServiceLeaves[structs.NewServiceName("db", nil)], issuedCert) }, }, - verificationStage{ + { requiredWatches: map[string]verifyWatchRequest{ "service-resolver:" + dbStr: genVerifyResolverWatch("db", "dc1", structs.ServiceResolver), }, events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: "service-resolver:" + dbStr, Result: &structs.IndexedConfigEntries{ Kind: structs.ServiceResolver, @@ -1356,9 +1356,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Equal(t, want, snap.TerminatingGateway.ServiceResolvers[structs.NewServiceName("db", nil)]) }, }, - verificationStage{ + { events: []cache.UpdateEvent{ - cache.UpdateEvent{ + { CorrelationID: gatewayServicesWatchID, Result: &structs.IndexedGatewayServices{ Services: structs.GatewayServices{ diff --git a/agent/proxycfg/testing.go b/agent/proxycfg/testing.go index dc453e988d..a2c79c1a30 100644 --- a/agent/proxycfg/testing.go +++ b/agent/proxycfg/testing.go @@ -102,7 +102,7 @@ func TestIntentions(t testing.T) *structs.IndexedIntentionMatches { return &structs.IndexedIntentionMatches{ Matches: []structs.Intentions{ []*structs.Intention{ - &structs.Intention{ + { ID: "foo", SourceNS: "default", SourceName: "billing", @@ -654,7 +654,7 @@ func TestConfigSnapshot(t testing.T) *ConfigSnapshot { "db": dbChain, }, WatchedUpstreamEndpoints: map[string]map[string]structs.CheckServiceNodes{ - "db": map[string]structs.CheckServiceNodes{ + "db": { "db.default.dc1": TestUpstreamNodes(t), }, }, @@ -954,10 +954,10 @@ func setupTestVariationConfigEntriesAndSnapshot( Kind: structs.ServiceResolver, Name: "db", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == v2", }, }, @@ -1243,7 +1243,7 @@ func setupTestVariationConfigEntriesAndSnapshot( "db": dbChain, }, WatchedUpstreamEndpoints: map[string]map[string]structs.CheckServiceNodes{ - "db": map[string]structs.CheckServiceNodes{ + "db": { "db.default.dc1": TestUpstreamNodes(t), }, }, @@ -1265,7 +1265,7 @@ func setupTestVariationConfigEntriesAndSnapshot( snap.WatchedUpstreamEndpoints["db"]["db.default.dc2"] = TestUpstreamNodesDC2(t) snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{ - "db": map[string]structs.CheckServiceNodes{ + "db": { "dc2": TestGatewayNodesDC2(t), }, } @@ -1278,7 +1278,7 @@ func setupTestVariationConfigEntriesAndSnapshot( case "failover-through-double-remote-gateway": snap.WatchedUpstreamEndpoints["db"]["db.default.dc3"] = TestUpstreamNodesDC2(t) snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{ - "db": map[string]structs.CheckServiceNodes{ + "db": { "dc2": TestGatewayNodesDC2(t), "dc3": TestGatewayNodesDC3(t), }, @@ -1291,7 +1291,7 @@ func setupTestVariationConfigEntriesAndSnapshot( snap.WatchedUpstreamEndpoints["db"]["db.default.dc2"] = TestUpstreamNodesDC2(t) snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{ - "db": map[string]structs.CheckServiceNodes{ + "db": { "dc1": TestGatewayNodesDC1(t), }, } @@ -1304,7 +1304,7 @@ func setupTestVariationConfigEntriesAndSnapshot( case "failover-through-double-local-gateway": snap.WatchedUpstreamEndpoints["db"]["db.default.dc3"] = TestUpstreamNodesDC2(t) snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{ - "db": map[string]structs.CheckServiceNodes{ + "db": { "dc1": TestGatewayNodesDC1(t), }, } @@ -1355,11 +1355,11 @@ func testConfigSnapshotMeshGateway(t testing.T, populateServices bool, useFedera Config: map[string]interface{}{}, }, TaggedAddresses: map[string]structs.ServiceAddress{ - structs.TaggedAddressLAN: structs.ServiceAddress{ + structs.TaggedAddressLAN: { Address: "1.2.3.4", Port: 8443, }, - structs.TaggedAddressWAN: structs.ServiceAddress{ + structs.TaggedAddressWAN: { Address: "198.18.0.1", Port: 443, }, @@ -1535,7 +1535,7 @@ func testConfigSnapshotIngressGateway( t, variation, leaf, additionalEntries..., ), Upstreams: map[IngressListenerKey]structs.Upstreams{ - IngressListenerKey{protocol, 9191}: structs.Upstreams{ + {protocol, 9191}: { { // We rely on this one having default type in a few tests... DestinationName: "db", @@ -1597,7 +1597,7 @@ func testConfigSnapshotTerminatingGateway(t testing.T, populateServices bool) *C ProxyID: structs.NewServiceID("terminating-gateway", nil), Address: "1.2.3.4", TaggedAddresses: map[string]structs.ServiceAddress{ - structs.TaggedAddressWAN: structs.ServiceAddress{ + structs.TaggedAddressWAN: { Address: "198.18.0.1", Port: 443, }, @@ -1741,7 +1741,7 @@ func TestConfigSnapshotIngress_MultipleListenersDuplicateService(t testing.T) *C snap := TestConfigSnapshotIngress_HTTPMultipleServices(t) snap.IngressGateway.Upstreams = map[IngressListenerKey]structs.Upstreams{ - IngressListenerKey{Protocol: "http", Port: 8080}: structs.Upstreams{ + {Protocol: "http", Port: 8080}: { { DestinationName: "foo", LocalBindPort: 8080, @@ -1751,7 +1751,7 @@ func TestConfigSnapshotIngress_MultipleListenersDuplicateService(t testing.T) *C LocalBindPort: 8080, }, }, - IngressListenerKey{Protocol: "http", Port: 443}: structs.Upstreams{ + {Protocol: "http", Port: 443}: { { DestinationName: "foo", LocalBindPort: 443, diff --git a/agent/router/manager_test.go b/agent/router/manager_test.go index 211164e60a..c7e1f299ca 100644 --- a/agent/router/manager_test.go +++ b/agent/router/manager_test.go @@ -316,9 +316,9 @@ func TestServers_RebalanceServers_AvoidFailed(t *testing.T) { // of trials with a small number of servers to try to make sure // the shuffle alone won't give the right answer. servers := []*metadata.Server{ - &metadata.Server{Name: "s1", Addr: &fauxAddr{"s1"}}, - &metadata.Server{Name: "s2", Addr: &fauxAddr{"s2"}}, - &metadata.Server{Name: "s3", Addr: &fauxAddr{"s3"}}, + {Name: "s1", Addr: &fauxAddr{"s1"}}, + {Name: "s2", Addr: &fauxAddr{"s2"}}, + {Name: "s3", Addr: &fauxAddr{"s3"}}, } for i := 0; i < 100; i++ { m := testManagerFailAddr(t, &fauxAddr{"s2"}) diff --git a/agent/sidecar_service.go b/agent/sidecar_service.go index 22d7721bcd..327b0e9f82 100644 --- a/agent/sidecar_service.go +++ b/agent/sidecar_service.go @@ -172,14 +172,14 @@ func (a *Agent) sidecarServiceFromNodeService(ns *structs.NodeService, token str // Setup default check if none given if len(checks) < 1 { checks = []*structs.CheckType{ - &structs.CheckType{ + { Name: "Connect Sidecar Listening", // Default to localhost rather than agent/service public IP. The checks // can always be overridden if a non-loopback IP is needed. TCP: ipaddr.FormatAddressPort(sidecar.Proxy.LocalServiceAddress, sidecar.Port), Interval: 10 * time.Second, }, - &structs.CheckType{ + { Name: "Connect Sidecar Aliasing " + ns.ID, AliasService: ns.ID, }, diff --git a/agent/sidecar_service_test.go b/agent/sidecar_service_test.go index 85f9c0a233..4c26eb61cd 100644 --- a/agent/sidecar_service_test.go +++ b/agent/sidecar_service_test.go @@ -60,12 +60,12 @@ func TestAgent_sidecarServiceFromNodeService(t *testing.T) { }, }, wantChecks: []*structs.CheckType{ - &structs.CheckType{ + { Name: "Connect Sidecar Listening", TCP: "127.0.0.1:2222", Interval: 10 * time.Second, }, - &structs.CheckType{ + { Name: "Connect Sidecar Aliasing web1", AliasService: "web1", }, @@ -128,7 +128,7 @@ func TestAgent_sidecarServiceFromNodeService(t *testing.T) { }, }, wantChecks: []*structs.CheckType{ - &structs.CheckType{ + { ScriptArgs: []string{"sleep", "1"}, Interval: 999 * time.Second, }, @@ -200,12 +200,12 @@ func TestAgent_sidecarServiceFromNodeService(t *testing.T) { }, }, wantChecks: []*structs.CheckType{ - &structs.CheckType{ + { Name: "Connect Sidecar Listening", TCP: "127.0.0.1:2222", Interval: 10 * time.Second, }, - &structs.CheckType{ + { Name: "Connect Sidecar Aliasing web1", AliasService: "web1", }, @@ -288,12 +288,12 @@ func TestAgent_sidecarServiceFromNodeService(t *testing.T) { }, }, wantChecks: []*structs.CheckType{ - &structs.CheckType{ + { Name: "Connect Sidecar Listening", TCP: "127.0.0.1:2222", Interval: 10 * time.Second, }, - &structs.CheckType{ + { Name: "Connect Sidecar Aliasing web1", AliasService: "web1", }, diff --git a/agent/structs/acl_legacy_test.go b/agent/structs/acl_legacy_test.go index 161e904b3e..a17b7c7532 100644 --- a/agent/structs/acl_legacy_test.go +++ b/agent/structs/acl_legacy_test.go @@ -83,7 +83,7 @@ func TestStructs_ACLToken_Convert(t *testing.T) { SecretID: "67c29ecd-cabc-42e0-a20e-771e9a1ab70c", Description: "new token", Policies: []ACLTokenPolicyLink{ - ACLTokenPolicyLink{ + { ID: ACLPolicyGlobalManagementID, }, }, @@ -122,7 +122,7 @@ func TestStructs_ACLToken_Convert(t *testing.T) { SecretID: "67c29ecd-cabc-42e0-a20e-771e9a1ab70c", Description: "new token", Policies: []ACLTokenPolicyLink{ - ACLTokenPolicyLink{ + { ID: ACLPolicyGlobalManagementID, }, }, diff --git a/agent/structs/acl_test.go b/agent/structs/acl_test.go index 1916af829e..86e8dfe20c 100644 --- a/agent/structs/acl_test.go +++ b/agent/structs/acl_test.go @@ -16,13 +16,13 @@ func TestStructs_ACLToken_PolicyIDs(t *testing.T) { token := &ACLToken{ Policies: []ACLTokenPolicyLink{ - ACLTokenPolicyLink{ + { ID: "one", }, - ACLTokenPolicyLink{ + { ID: "two", }, - ACLTokenPolicyLink{ + { ID: "three", }, }, @@ -179,13 +179,13 @@ func TestStructs_ACLToken_SetHash(t *testing.T) { SecretID: "65e98e67-9b29-470c-8ffa-7c5a23cc67c8", Description: "test", Policies: []ACLTokenPolicyLink{ - ACLTokenPolicyLink{ + { ID: "one", }, - ACLTokenPolicyLink{ + { ID: "two", }, - ACLTokenPolicyLink{ + { ID: "three", }, }, @@ -224,13 +224,13 @@ func TestStructs_ACLToken_EstimateSize(t *testing.T) { SecretID: "65e98e67-9b29-470c-8ffa-7c5a23cc67c8", Description: "test", Policies: []ACLTokenPolicyLink{ - ACLTokenPolicyLink{ + { ID: "one", }, - ACLTokenPolicyLink{ + { ID: "two", }, - ACLTokenPolicyLink{ + { ID: "three", }, }, @@ -250,13 +250,13 @@ func TestStructs_ACLToken_Stub(t *testing.T) { SecretID: "65e98e67-9b29-470c-8ffa-7c5a23cc67c8", Description: "test", Policies: []ACLTokenPolicyLink{ - ACLTokenPolicyLink{ + { ID: "one", }, - ACLTokenPolicyLink{ + { ID: "two", }, - ACLTokenPolicyLink{ + { ID: "three", }, }, diff --git a/agent/structs/config_entry_discoverychain.go b/agent/structs/config_entry_discoverychain.go index a0249a71d6..81a6e421a5 100644 --- a/agent/structs/config_entry_discoverychain.go +++ b/agent/structs/config_entry_discoverychain.go @@ -221,7 +221,7 @@ func (e *ServiceRouterConfigEntry) ListRelatedServices() []ServiceID { } out := make([]ServiceID, 0, len(found)) - for svc, _ := range found { + for svc := range found { out = append(out, svc) } sort.Slice(out, func(i, j int) bool { @@ -545,7 +545,7 @@ func (e *ServiceSplitterConfigEntry) ListRelatedServices() []ServiceID { } out := make([]ServiceID, 0, len(found)) - for svc, _ := range found { + for svc := range found { out = append(out, svc) } sort.Slice(out, func(i, j int) bool { @@ -728,7 +728,7 @@ func (e *ServiceResolverConfigEntry) Validate() error { } if len(e.Subsets) > 0 { - for name, _ := range e.Subsets { + for name := range e.Subsets { if name == "" { return fmt.Errorf("Subset defined with empty name") } @@ -859,7 +859,7 @@ func (e *ServiceResolverConfigEntry) ListRelatedServices() []ServiceID { } out := make([]ServiceID, 0, len(found)) - for svc, _ := range found { + for svc := range found { out = append(out, svc) } sort.Slice(out, func(i, j int) bool { diff --git a/agent/structs/config_entry_discoverychain_test.go b/agent/structs/config_entry_discoverychain_test.go index 0695a21965..7b7a2feef3 100644 --- a/agent/structs/config_entry_discoverychain_test.go +++ b/agent/structs/config_entry_discoverychain_test.go @@ -114,10 +114,10 @@ func TestConfigEntries_ListRelatedServices_AndACLs(t *testing.T) { "bar": {OnlyPassing: true}, }, Failover: map[string]ServiceResolverFailover{ - "foo": ServiceResolverFailover{ + "foo": { Service: "other1", }, - "bar": ServiceResolverFailover{ + "bar": { Service: "other2", }, }, @@ -372,7 +372,7 @@ func TestServiceResolverConfigEntry(t *testing.T) { Kind: ServiceResolver, Name: "test", Failover: map[string]ServiceResolverFailover{ - "*": ServiceResolverFailover{ + "*": { Datacenters: []string{"dc2"}, }, }, @@ -384,7 +384,7 @@ func TestServiceResolverConfigEntry(t *testing.T) { Kind: ServiceResolver, Name: "test", Failover: map[string]ServiceResolverFailover{ - "gone": ServiceResolverFailover{ + "gone": { Datacenters: []string{"dc2"}, }, }, @@ -400,7 +400,7 @@ func TestServiceResolverConfigEntry(t *testing.T) { "v1": {Filter: "Service.Meta.version == v1"}, }, Failover: map[string]ServiceResolverFailover{ - "v1": ServiceResolverFailover{ + "v1": { Datacenters: []string{"dc2"}, }, }, @@ -415,7 +415,7 @@ func TestServiceResolverConfigEntry(t *testing.T) { "v1": {Filter: "Service.Meta.version == v1"}, }, Failover: map[string]ServiceResolverFailover{ - "v1": ServiceResolverFailover{}, + "v1": {}, }, }, validateErr: `Bad Failover["v1"] one of Service, ServiceSubset, Namespace, or Datacenters is required`, @@ -429,7 +429,7 @@ func TestServiceResolverConfigEntry(t *testing.T) { "v1": {Filter: "Service.Meta.version == v1"}, }, Failover: map[string]ServiceResolverFailover{ - "v1": ServiceResolverFailover{ + "v1": { Service: "test", ServiceSubset: "gone", }, @@ -447,7 +447,7 @@ func TestServiceResolverConfigEntry(t *testing.T) { "v2": {Filter: "Service.Meta.version == v2"}, }, Failover: map[string]ServiceResolverFailover{ - "v1": ServiceResolverFailover{ + "v1": { Service: "test", ServiceSubset: "v2", }, @@ -460,7 +460,7 @@ func TestServiceResolverConfigEntry(t *testing.T) { Kind: ServiceResolver, Name: "test", Failover: map[string]ServiceResolverFailover{ - "*": ServiceResolverFailover{ + "*": { Service: "backup", Datacenters: []string{"", "dc2", "dc3"}, }, diff --git a/agent/structs/config_entry_test.go b/agent/structs/config_entry_test.go index cc1798ee69..9f699aa2c0 100644 --- a/agent/structs/config_entry_test.go +++ b/agent/structs/config_entry_test.go @@ -622,33 +622,33 @@ func TestDecodeConfigEntry(t *testing.T) { Enabled: true, }, Listeners: []IngressListener{ - IngressListener{ + { Port: 8080, Protocol: "http", Services: []IngressService{ - IngressService{ + { Name: "web", Hosts: []string{"test.example.com", "test2.example.com"}, }, - IngressService{ + { Name: "db", }, }, }, - IngressListener{ + { Port: 9999, Protocol: "tcp", Services: []IngressService{ - IngressService{ + { Name: "mysql", }, }, }, - IngressListener{ + { Port: 2234, Protocol: "tcp", Services: []IngressService{ - IngressService{ + { Name: "postgres", }, }, @@ -760,13 +760,13 @@ func TestServiceConfigResponse_MsgPack(t *testing.T) { // }, }, UpstreamConfigs: map[string]map[string]interface{}{ - "a": map[string]interface{}{ + "a": { "string": "aaaa", // "map": map[string]interface{}{ // "baz": "aa", // }, }, - "b": map[string]interface{}{ + "b": { "string": "bbbb", // "map": map[string]interface{}{ // "baz": "bb", @@ -793,8 +793,8 @@ func TestServiceConfigResponse_MsgPack(t *testing.T) { func TestConfigEntryResponseMarshalling(t *testing.T) { cases := map[string]ConfigEntryResponse{ - "nil entry": ConfigEntryResponse{}, - "proxy-default entry": ConfigEntryResponse{ + "nil entry": {}, + "proxy-default entry": { Entry: &ProxyConfigEntry{ Kind: ProxyDefaults, Name: ProxyConfigGlobal, @@ -803,7 +803,7 @@ func TestConfigEntryResponseMarshalling(t *testing.T) { }, }, }, - "service-default entry": ConfigEntryResponse{ + "service-default entry": { Entry: &ServiceConfigEntry{ Kind: ServiceDefaults, Name: "foo", diff --git a/agent/structs/intention_test.go b/agent/structs/intention_test.go index 6665ef43c3..924da25599 100644 --- a/agent/structs/intention_test.go +++ b/agent/structs/intention_test.go @@ -19,7 +19,7 @@ func TestIntention_ACLs(t *testing.T) { } cases := map[string]testCase{ - "all-denied": testCase{ + "all-denied": { intention: Intention{ SourceNS: "default", SourceName: "web", @@ -29,7 +29,7 @@ func TestIntention_ACLs(t *testing.T) { read: false, write: false, }, - "deny-write-read-dest": testCase{ + "deny-write-read-dest": { rules: `service "api" { policy = "deny" intentions = "read" }`, intention: Intention{ SourceNS: "default", @@ -40,7 +40,7 @@ func TestIntention_ACLs(t *testing.T) { read: true, write: false, }, - "deny-write-read-source": testCase{ + "deny-write-read-source": { rules: `service "web" { policy = "deny" intentions = "read" }`, intention: Intention{ SourceNS: "default", @@ -51,7 +51,7 @@ func TestIntention_ACLs(t *testing.T) { read: true, write: false, }, - "allow-write-with-dest-write": testCase{ + "allow-write-with-dest-write": { rules: `service "api" { policy = "deny" intentions = "write" }`, intention: Intention{ SourceNS: "default", @@ -62,7 +62,7 @@ func TestIntention_ACLs(t *testing.T) { read: true, write: true, }, - "deny-write-with-source-write": testCase{ + "deny-write-with-source-write": { rules: `service "web" { policy = "deny" intentions = "write" }`, intention: Intention{ SourceNS: "default", @@ -73,7 +73,7 @@ func TestIntention_ACLs(t *testing.T) { read: true, write: false, }, - "deny-wildcard-write-allow-read": testCase{ + "deny-wildcard-write-allow-read": { rules: `service "*" { policy = "deny" intentions = "write" }`, intention: Intention{ SourceNS: "default", @@ -86,7 +86,7 @@ func TestIntention_ACLs(t *testing.T) { read: true, write: false, }, - "allow-wildcard-write": testCase{ + "allow-wildcard-write": { rules: `service_prefix "" { policy = "deny" intentions = "write" }`, intention: Intention{ SourceNS: "default", @@ -97,7 +97,7 @@ func TestIntention_ACLs(t *testing.T) { read: true, write: true, }, - "allow-wildcard-read": testCase{ + "allow-wildcard-read": { rules: `service "foo" { policy = "deny" intentions = "read" }`, intention: Intention{ SourceNS: "default", diff --git a/agent/structs/structs.go b/agent/structs/structs.go index 484f011cfa..e1d638a261 100644 --- a/agent/structs/structs.go +++ b/agent/structs/structs.go @@ -120,7 +120,7 @@ const ( WildcardSpecifier = "*" ) -var allowedConsulMetaKeysForMeshGateway = map[string]struct{}{MetaWANFederationKey: struct{}{}} +var allowedConsulMetaKeysForMeshGateway = map[string]struct{}{MetaWANFederationKey: {}} var ( NodeMaintCheckID = NewCheckID(NodeMaint, nil) @@ -1147,7 +1147,7 @@ func (s *NodeService) Validate() error { path.Protocol = strings.ToLower(path.Protocol) if ok := allowedExposeProtocols[path.Protocol]; !ok && path.Protocol != "" { protocols := make([]string, 0) - for p, _ := range allowedExposeProtocols { + for p := range allowedExposeProtocols { protocols = append(protocols, p) } diff --git a/agent/structs/structs_filtering_test.go b/agent/structs/structs_filtering_test.go index da63441118..e13c98043c 100644 --- a/agent/structs/structs_filtering_test.go +++ b/agent/structs/structs_filtering_test.go @@ -582,37 +582,37 @@ var expectedFieldConfigIntention bexpr.FieldConfigurations = bexpr.FieldConfigur // Only need to generate the field configurations for the top level filtered types // The internal types will be checked within these. var fieldConfigTests map[string]fieldConfigTest = map[string]fieldConfigTest{ - "Node": fieldConfigTest{ + "Node": { dataType: (*Node)(nil), expected: expectedFieldConfigNode, }, - "NodeService": fieldConfigTest{ + "NodeService": { dataType: (*NodeService)(nil), expected: expectedFieldConfigNodeService, }, - "ServiceNode": fieldConfigTest{ + "ServiceNode": { dataType: (*ServiceNode)(nil), expected: expectedFieldConfigServiceNode, }, - "HealthCheck": fieldConfigTest{ + "HealthCheck": { dataType: (*HealthCheck)(nil), expected: expectedFieldConfigHealthCheck, }, - "CheckServiceNode": fieldConfigTest{ + "CheckServiceNode": { dataType: (*CheckServiceNode)(nil), expected: expectedFieldConfigCheckServiceNode, }, - "NodeInfo": fieldConfigTest{ + "NodeInfo": { dataType: (*NodeInfo)(nil), expected: expectedFieldConfigNodeInfo, }, - "api.AgentService": fieldConfigTest{ + "api.AgentService": { dataType: (*api.AgentService)(nil), // this also happens to ensure that our API representation of a service that can be // registered with an agent stays in sync with our internal NodeService structure expected: expectedFieldConfigNodeService, }, - "Intention": fieldConfigTest{ + "Intention": { dataType: (*Intention)(nil), expected: expectedFieldConfigIntention, }, diff --git a/agent/structs/structs_test.go b/agent/structs/structs_test.go index 0ba448a24f..ae42a905a6 100644 --- a/agent/structs/structs_test.go +++ b/agent/structs/structs_test.go @@ -148,11 +148,11 @@ func testServiceNode(t *testing.T) *ServiceNode { ServiceTags: []string{"prod", "v1"}, ServiceAddress: "127.0.0.2", ServiceTaggedAddresses: map[string]ServiceAddress{ - "lan": ServiceAddress{ + "lan": { Address: "127.0.0.2", Port: 8080, }, - "wan": ServiceAddress{ + "wan": { Address: "198.18.0.1", Port: 80, }, @@ -367,36 +367,36 @@ func TestStructs_NodeService_ValidateMeshGateway(t *testing.T) { Err string } cases := map[string]testCase{ - "valid": testCase{ + "valid": { func(x *NodeService) {}, "", }, - "zero-port": testCase{ + "zero-port": { func(x *NodeService) { x.Port = 0 }, "Port must be non-zero", }, - "sidecar-service": testCase{ + "sidecar-service": { func(x *NodeService) { x.Connect.SidecarService = &ServiceDefinition{} }, "cannot have a sidecar service", }, - "proxy-destination-name": testCase{ + "proxy-destination-name": { func(x *NodeService) { x.Proxy.DestinationServiceName = "foo" }, "Proxy.DestinationServiceName configuration is invalid", }, - "proxy-destination-id": testCase{ + "proxy-destination-id": { func(x *NodeService) { x.Proxy.DestinationServiceID = "foo" }, "Proxy.DestinationServiceID configuration is invalid", }, - "proxy-local-address": testCase{ + "proxy-local-address": { func(x *NodeService) { x.Proxy.LocalServiceAddress = "127.0.0.1" }, "Proxy.LocalServiceAddress configuration is invalid", }, - "proxy-local-port": testCase{ + "proxy-local-port": { func(x *NodeService) { x.Proxy.LocalServicePort = 36 }, "Proxy.LocalServicePort configuration is invalid", }, - "proxy-upstreams": testCase{ - func(x *NodeService) { x.Proxy.Upstreams = []Upstream{Upstream{}} }, + "proxy-upstreams": { + func(x *NodeService) { x.Proxy.Upstreams = []Upstream{{}} }, "Proxy.Upstreams configuration is invalid", }, } @@ -423,32 +423,32 @@ func TestStructs_NodeService_ValidateTerminatingGateway(t *testing.T) { } cases := map[string]testCase{ - "valid": testCase{ + "valid": { func(x *NodeService) {}, "", }, - "sidecar-service": testCase{ + "sidecar-service": { func(x *NodeService) { x.Connect.SidecarService = &ServiceDefinition{} }, "cannot have a sidecar service", }, - "proxy-destination-name": testCase{ + "proxy-destination-name": { func(x *NodeService) { x.Proxy.DestinationServiceName = "foo" }, "Proxy.DestinationServiceName configuration is invalid", }, - "proxy-destination-id": testCase{ + "proxy-destination-id": { func(x *NodeService) { x.Proxy.DestinationServiceID = "foo" }, "Proxy.DestinationServiceID configuration is invalid", }, - "proxy-local-address": testCase{ + "proxy-local-address": { func(x *NodeService) { x.Proxy.LocalServiceAddress = "127.0.0.1" }, "Proxy.LocalServiceAddress configuration is invalid", }, - "proxy-local-port": testCase{ + "proxy-local-port": { func(x *NodeService) { x.Proxy.LocalServicePort = 36 }, "Proxy.LocalServicePort configuration is invalid", }, - "proxy-upstreams": testCase{ - func(x *NodeService) { x.Proxy.Upstreams = []Upstream{Upstream{}} }, + "proxy-upstreams": { + func(x *NodeService) { x.Proxy.Upstreams = []Upstream{{}} }, "Proxy.Upstreams configuration is invalid", }, } @@ -476,32 +476,32 @@ func TestStructs_NodeService_ValidateIngressGateway(t *testing.T) { } cases := map[string]testCase{ - "valid": testCase{ + "valid": { func(x *NodeService) {}, "", }, - "sidecar-service": testCase{ + "sidecar-service": { func(x *NodeService) { x.Connect.SidecarService = &ServiceDefinition{} }, "cannot have a sidecar service", }, - "proxy-destination-name": testCase{ + "proxy-destination-name": { func(x *NodeService) { x.Proxy.DestinationServiceName = "foo" }, "Proxy.DestinationServiceName configuration is invalid", }, - "proxy-destination-id": testCase{ + "proxy-destination-id": { func(x *NodeService) { x.Proxy.DestinationServiceID = "foo" }, "Proxy.DestinationServiceID configuration is invalid", }, - "proxy-local-address": testCase{ + "proxy-local-address": { func(x *NodeService) { x.Proxy.LocalServiceAddress = "127.0.0.1" }, "Proxy.LocalServiceAddress configuration is invalid", }, - "proxy-local-port": testCase{ + "proxy-local-port": { func(x *NodeService) { x.Proxy.LocalServicePort = 36 }, "Proxy.LocalServicePort configuration is invalid", }, - "proxy-upstreams": testCase{ - func(x *NodeService) { x.Proxy.Upstreams = []Upstream{Upstream{}} }, + "proxy-upstreams": { + func(x *NodeService) { x.Proxy.Upstreams = []Upstream{{}} }, "Proxy.Upstreams configuration is invalid", }, } @@ -892,11 +892,11 @@ func TestStructs_NodeService_IsSame(t *testing.T) { Tags: []string{"foo", "bar"}, Address: "127.0.0.1", TaggedAddresses: map[string]ServiceAddress{ - "lan": ServiceAddress{ + "lan": { Address: "127.0.0.1", Port: 3456, }, - "wan": ServiceAddress{ + "wan": { Address: "198.18.0.1", Port: 1234, }, @@ -927,11 +927,11 @@ func TestStructs_NodeService_IsSame(t *testing.T) { Port: 1234, EnableTagOverride: true, TaggedAddresses: map[string]ServiceAddress{ - "wan": ServiceAddress{ + "wan": { Address: "198.18.0.1", Port: 1234, }, - "lan": ServiceAddress{ + "lan": { Address: "127.0.0.1", Port: 3456, }, @@ -1395,9 +1395,9 @@ func TestStructs_validateMetaPair(t *testing.T) { // reserved prefix, allowed {metaKeyReservedPrefix + "key", "value", "", true, nil}, // reserved prefix, not allowed via an allowlist - {metaKeyReservedPrefix + "bad", "value", "reserved for internal use", false, map[string]struct{}{metaKeyReservedPrefix + "good": struct{}{}}}, + {metaKeyReservedPrefix + "bad", "value", "reserved for internal use", false, map[string]struct{}{metaKeyReservedPrefix + "good": {}}}, // reserved prefix, allowed via an allowlist - {metaKeyReservedPrefix + "good", "value", "", true, map[string]struct{}{metaKeyReservedPrefix + "good": struct{}{}}}, + {metaKeyReservedPrefix + "good", "value", "", true, map[string]struct{}{metaKeyReservedPrefix + "good": {}}}, // value too long {"key", longValue, "Value is too long", false, nil}, } @@ -1628,7 +1628,7 @@ func TestNode_BestAddress(t *testing.T) { nodeWANAddr := "198.18.19.20" cases := map[string]testCase{ - "address": testCase{ + "address": { input: Node{ Address: nodeAddr, }, @@ -1636,7 +1636,7 @@ func TestNode_BestAddress(t *testing.T) { lanAddr: nodeAddr, wanAddr: nodeAddr, }, - "wan-address": testCase{ + "wan-address": { input: Node{ Address: nodeAddr, TaggedAddresses: map[string]string{ @@ -1676,7 +1676,7 @@ func TestNodeService_BestAddress(t *testing.T) { serviceWANPort := 987 cases := map[string]testCase{ - "no-address": testCase{ + "no-address": { input: NodeService{ Port: servicePort, }, @@ -1686,7 +1686,7 @@ func TestNodeService_BestAddress(t *testing.T) { wanAddr: "", wanPort: servicePort, }, - "service-address": testCase{ + "service-address": { input: NodeService{ Address: serviceAddr, Port: servicePort, @@ -1697,12 +1697,12 @@ func TestNodeService_BestAddress(t *testing.T) { wanAddr: serviceAddr, wanPort: servicePort, }, - "service-wan-address": testCase{ + "service-wan-address": { input: NodeService{ Address: serviceAddr, Port: servicePort, TaggedAddresses: map[string]ServiceAddress{ - "wan": ServiceAddress{ + "wan": { Address: serviceWANAddr, Port: serviceWANPort, }, @@ -1714,12 +1714,12 @@ func TestNodeService_BestAddress(t *testing.T) { wanAddr: serviceWANAddr, wanPort: serviceWANPort, }, - "service-wan-address-default-port": testCase{ + "service-wan-address-default-port": { input: NodeService{ Address: serviceAddr, Port: servicePort, TaggedAddresses: map[string]ServiceAddress{ - "wan": ServiceAddress{ + "wan": { Address: serviceWANAddr, Port: 0, }, @@ -1731,11 +1731,11 @@ func TestNodeService_BestAddress(t *testing.T) { wanAddr: serviceWANAddr, wanPort: servicePort, }, - "service-wan-address-node-lan": testCase{ + "service-wan-address-node-lan": { input: NodeService{ Port: servicePort, TaggedAddresses: map[string]ServiceAddress{ - "wan": ServiceAddress{ + "wan": { Address: serviceWANAddr, Port: serviceWANPort, }, @@ -1783,7 +1783,7 @@ func TestCheckServiceNode_BestAddress(t *testing.T) { serviceWANPort := 987 cases := map[string]testCase{ - "node-address": testCase{ + "node-address": { input: CheckServiceNode{ Node: &Node{ Address: nodeAddr, @@ -1798,7 +1798,7 @@ func TestCheckServiceNode_BestAddress(t *testing.T) { wanAddr: nodeAddr, wanPort: servicePort, }, - "node-wan-address": testCase{ + "node-wan-address": { input: CheckServiceNode{ Node: &Node{ Address: nodeAddr, @@ -1816,7 +1816,7 @@ func TestCheckServiceNode_BestAddress(t *testing.T) { wanAddr: nodeWANAddr, wanPort: servicePort, }, - "service-address": testCase{ + "service-address": { input: CheckServiceNode{ Node: &Node{ Address: nodeAddr, @@ -1836,7 +1836,7 @@ func TestCheckServiceNode_BestAddress(t *testing.T) { wanAddr: serviceAddr, wanPort: servicePort, }, - "service-wan-address": testCase{ + "service-wan-address": { input: CheckServiceNode{ Node: &Node{ Address: nodeAddr, @@ -1849,7 +1849,7 @@ func TestCheckServiceNode_BestAddress(t *testing.T) { Address: serviceAddr, Port: servicePort, TaggedAddresses: map[string]ServiceAddress{ - "wan": ServiceAddress{ + "wan": { Address: serviceWANAddr, Port: serviceWANPort, }, @@ -1862,7 +1862,7 @@ func TestCheckServiceNode_BestAddress(t *testing.T) { wanAddr: serviceWANAddr, wanPort: serviceWANPort, }, - "service-wan-address-default-port": testCase{ + "service-wan-address-default-port": { input: CheckServiceNode{ Node: &Node{ Address: nodeAddr, @@ -1875,7 +1875,7 @@ func TestCheckServiceNode_BestAddress(t *testing.T) { Address: serviceAddr, Port: servicePort, TaggedAddresses: map[string]ServiceAddress{ - "wan": ServiceAddress{ + "wan": { Address: serviceWANAddr, Port: 0, }, @@ -1888,7 +1888,7 @@ func TestCheckServiceNode_BestAddress(t *testing.T) { wanAddr: serviceWANAddr, wanPort: servicePort, }, - "service-wan-address-node-lan": testCase{ + "service-wan-address-node-lan": { input: CheckServiceNode{ Node: &Node{ Address: nodeAddr, @@ -1900,7 +1900,7 @@ func TestCheckServiceNode_BestAddress(t *testing.T) { Service: &NodeService{ Port: servicePort, TaggedAddresses: map[string]ServiceAddress{ - "wan": ServiceAddress{ + "wan": { Address: serviceWANAddr, Port: serviceWANPort, }, @@ -2072,7 +2072,7 @@ func makeMonster() *monsterStruct { "aaa": "bbb", }, MapStringSlice: map[string][]string{ - "aaa": []string{"bbb"}, + "aaa": {"bbb"}, }, Dur: 5 * time.Second, diff --git a/agent/ui_endpoint_test.go b/agent/ui_endpoint_test.go index 3e9c5540c8..356fa2fcc0 100644 --- a/agent/ui_endpoint_test.go +++ b/agent/ui_endpoint_test.go @@ -204,7 +204,7 @@ func TestUiServices(t *testing.T) { requests := []*structs.RegisterRequest{ // register foo node - &structs.RegisterRequest{ + { Datacenter: "dc1", Node: "foo", Address: "127.0.0.1", @@ -217,7 +217,7 @@ func TestUiServices(t *testing.T) { }, }, //register api service on node foo - &structs.RegisterRequest{ + { Datacenter: "dc1", Node: "foo", SkipNodeUpdate: true, @@ -236,7 +236,7 @@ func TestUiServices(t *testing.T) { }, }, // register web svc on node foo - &structs.RegisterRequest{ + { Datacenter: "dc1", Node: "foo", SkipNodeUpdate: true, @@ -260,7 +260,7 @@ func TestUiServices(t *testing.T) { }, }, // register bar node with service web - &structs.RegisterRequest{ + { Datacenter: "dc1", Node: "bar", Address: "127.0.0.2", @@ -275,7 +275,7 @@ func TestUiServices(t *testing.T) { }, }, Checks: []*structs.HealthCheck{ - &structs.HealthCheck{ + { Node: "bar", Name: "web svc check", Status: api.HealthCritical, @@ -284,7 +284,7 @@ func TestUiServices(t *testing.T) { }, }, // register zip node with service cache - &structs.RegisterRequest{ + { Datacenter: "dc1", Node: "zip", Address: "127.0.0.3", @@ -319,7 +319,7 @@ func TestUiServices(t *testing.T) { } expected := []*ServiceSummary{ - &ServiceSummary{ + { Kind: structs.ServiceKindTypical, Name: "api", Tags: []string{"tag1", "tag2"}, @@ -330,7 +330,7 @@ func TestUiServices(t *testing.T) { ChecksCritical: 0, EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - &ServiceSummary{ + { Kind: structs.ServiceKindTypical, Name: "cache", Tags: nil, @@ -341,7 +341,7 @@ func TestUiServices(t *testing.T) { ChecksCritical: 0, EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - &ServiceSummary{ + { Kind: structs.ServiceKindConnectProxy, Name: "web", Tags: nil, @@ -354,7 +354,7 @@ func TestUiServices(t *testing.T) { ExternalSources: []string{"k8s"}, EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - &ServiceSummary{ + { Kind: structs.ServiceKindTypical, Name: "consul", Tags: nil, @@ -388,7 +388,7 @@ func TestUiServices(t *testing.T) { } expected := []*ServiceSummary{ - &ServiceSummary{ + { Kind: structs.ServiceKindTypical, Name: "api", Tags: []string{"tag1", "tag2"}, @@ -399,7 +399,7 @@ func TestUiServices(t *testing.T) { ChecksCritical: 0, EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, - &ServiceSummary{ + { Kind: structs.ServiceKindConnectProxy, Name: "web", Tags: nil, diff --git a/agent/xds/clusters.go b/agent/xds/clusters.go index 8d923d6601..f6ab901a28 100644 --- a/agent/xds/clusters.go +++ b/agent/xds/clusters.go @@ -201,7 +201,7 @@ func (s *Server) makeGatewayServiceClusters(cfgSnap *proxycfg.ConfigSnapshot) ([ clusters := make([]proto.Message, 0, len(services)) - for svc, _ := range services { + for svc := range services { clusterName := connect.ServiceSNI(svc.Name, "", svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain) resolver, hasResolver := resolvers[svc] diff --git a/agent/xds/clusters_test.go b/agent/xds/clusters_test.go index 43de5e2433..4cf0460c9a 100644 --- a/agent/xds/clusters_test.go +++ b/agent/xds/clusters_test.go @@ -269,14 +269,14 @@ func TestClustersFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshotMeshGateway, setup: func(snap *proxycfg.ConfigSnapshot) { snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{ - structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("bar", nil): { Kind: structs.ServiceResolver, Name: "bar", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.Version == 1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.Version == 2", OnlyPassing: true, }, @@ -290,29 +290,29 @@ func TestClustersFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshotMeshGateway, setup: func(snap *proxycfg.ConfigSnapshot) { snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{ - structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("bar", nil): { Kind: structs.ServiceResolver, Name: "bar", DefaultSubset: "v2", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.Version == 1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.Version == 2", OnlyPassing: true, }, }, }, - structs.NewServiceName("notfound", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("notfound", nil): { Kind: structs.ServiceResolver, Name: "notfound", DefaultSubset: "v2", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.Version == 1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.Version == 2", OnlyPassing: true, }, @@ -326,15 +326,15 @@ func TestClustersFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshotMeshGateway, setup: func(snap *proxycfg.ConfigSnapshot) { snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{ - structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("bar", nil): { Kind: structs.ServiceResolver, Name: "bar", ConnectTimeout: 10 * time.Second, Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.Version == 1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.Version == 2", OnlyPassing: true, }, diff --git a/agent/xds/endpoints_test.go b/agent/xds/endpoints_test.go index bbcca387cd..dee1fcc449 100644 --- a/agent/xds/endpoints_test.go +++ b/agent/xds/endpoints_test.go @@ -123,7 +123,7 @@ func Test_makeLoadAssignment(t *testing.T) { ClusterName: "service:test", Endpoints: []envoyendpoint.LocalityLbEndpoints{{ LbEndpoints: []envoyendpoint.LbEndpoint{ - envoyendpoint.LbEndpoint{ + { HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{ Endpoint: &envoyendpoint.Endpoint{ Address: makeAddressPtr("10.10.10.10", 1234), @@ -131,7 +131,7 @@ func Test_makeLoadAssignment(t *testing.T) { HealthStatus: core.HealthStatus_HEALTHY, LoadBalancingWeight: makeUint32Value(1), }, - envoyendpoint.LbEndpoint{ + { HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{ Endpoint: &envoyendpoint.Endpoint{ Address: makeAddressPtr("10.10.10.20", 1234), @@ -153,7 +153,7 @@ func Test_makeLoadAssignment(t *testing.T) { ClusterName: "service:test", Endpoints: []envoyendpoint.LocalityLbEndpoints{{ LbEndpoints: []envoyendpoint.LbEndpoint{ - envoyendpoint.LbEndpoint{ + { HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{ Endpoint: &envoyendpoint.Endpoint{ Address: makeAddressPtr("10.10.10.10", 1234), @@ -161,7 +161,7 @@ func Test_makeLoadAssignment(t *testing.T) { HealthStatus: core.HealthStatus_HEALTHY, LoadBalancingWeight: makeUint32Value(10), }, - envoyendpoint.LbEndpoint{ + { HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{ Endpoint: &envoyendpoint.Endpoint{ Address: makeAddressPtr("10.10.10.20", 1234), @@ -183,7 +183,7 @@ func Test_makeLoadAssignment(t *testing.T) { ClusterName: "service:test", Endpoints: []envoyendpoint.LocalityLbEndpoints{{ LbEndpoints: []envoyendpoint.LbEndpoint{ - envoyendpoint.LbEndpoint{ + { HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{ Endpoint: &envoyendpoint.Endpoint{ Address: makeAddressPtr("10.10.10.10", 1234), @@ -191,7 +191,7 @@ func Test_makeLoadAssignment(t *testing.T) { HealthStatus: core.HealthStatus_HEALTHY, LoadBalancingWeight: makeUint32Value(1), }, - envoyendpoint.LbEndpoint{ + { HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{ Endpoint: &envoyendpoint.Endpoint{ Address: makeAddressPtr("10.10.10.20", 1234), @@ -327,27 +327,27 @@ func Test_endpointsFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshotMeshGateway, setup: func(snap *proxycfg.ConfigSnapshot) { snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{ - structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("bar", nil): { Kind: structs.ServiceResolver, Name: "bar", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == 1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == 2", OnlyPassing: true, }, }, }, - structs.NewServiceName("foo", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("foo", nil): { Kind: structs.ServiceResolver, Name: "foo", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == 1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == 2", OnlyPassing: true, }, @@ -361,29 +361,29 @@ func Test_endpointsFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshotMeshGateway, setup: func(snap *proxycfg.ConfigSnapshot) { snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{ - structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("bar", nil): { Kind: structs.ServiceResolver, Name: "bar", DefaultSubset: "v2", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == 1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == 2", OnlyPassing: true, }, }, }, - structs.NewServiceName("foo", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("foo", nil): { Kind: structs.ServiceResolver, Name: "foo", DefaultSubset: "v2", Subsets: map[string]structs.ServiceResolverSubset{ - "v1": structs.ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == 1", }, - "v2": structs.ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == 2", OnlyPassing: true, }, @@ -516,7 +516,7 @@ func Test_endpointsFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshotTerminatingGateway, setup: func(snap *proxycfg.ConfigSnapshot) { snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{ - structs.NewServiceName("web", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("web", nil): { Kind: structs.ServiceResolver, Name: "web", DefaultSubset: "v2", @@ -530,7 +530,7 @@ func Test_endpointsFromSnapshot(t *testing.T) { }, }, }, - structs.NewServiceName("web", nil): &structs.ServiceResolverConfigEntry{ + structs.NewServiceName("web", nil): { Kind: structs.ServiceResolver, Name: "web", DefaultSubset: "v2", diff --git a/agent/xds/listeners.go b/agent/xds/listeners.go index db5b93c21f..357ee4f25d 100644 --- a/agent/xds/listeners.go +++ b/agent/xds/listeners.go @@ -551,7 +551,7 @@ func (s *Server) makeTerminatingGatewayListener(name, addr string, port int, cfg // Make a FilterChain for each linked service // Match on the cluster name, - for svc, _ := range cfgSnap.TerminatingGateway.ServiceGroups { + for svc := range cfgSnap.TerminatingGateway.ServiceGroups { clusterName := connect.ServiceSNI(svc.Name, "", svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain) resolver, hasResolver := cfgSnap.TerminatingGateway.ServiceResolvers[svc] @@ -916,7 +916,7 @@ func makeHTTPFilter( StatPrefix: makeStatPrefix(proto, statPrefix, filterName), CodecType: envoyhttp.AUTO, HttpFilters: []*envoyhttp.HttpFilter{ - &envoyhttp.HttpFilter{ + { Name: "envoy.router", }, }, @@ -1011,7 +1011,7 @@ func makeExtAuthFilter(token string) (envoylistener.Filter, error) { // implementation to need service:write and since we have the token that // has that it's pretty reasonable to set it up here. InitialMetadata: []*envoycore.HeaderValue{ - &envoycore.HeaderValue{ + { Key: "x-consul-token", Value: token, }, @@ -1055,7 +1055,7 @@ func makeCommonTLSContextFromLeaf(cfgSnap *proxycfg.ConfigSnapshot, leaf *struct return &envoyauth.CommonTlsContext{ TlsParams: &envoyauth.TlsParameters{}, TlsCertificates: []*envoyauth.TlsCertificate{ - &envoyauth.TlsCertificate{ + { CertificateChain: &envoycore.DataSource{ Specifier: &envoycore.DataSource_InlineString{ InlineString: leaf.CertPEM, diff --git a/agent/xds/listeners_test.go b/agent/xds/listeners_test.go index 275f7a0838..d681be604e 100644 --- a/agent/xds/listeners_test.go +++ b/agent/xds/listeners_test.go @@ -258,15 +258,15 @@ func TestListenersFromSnapshot(t *testing.T) { setup: func(snap *proxycfg.ConfigSnapshot) { snap.Proxy.Config = map[string]interface{}{ "envoy_mesh_gateway_bind_addresses": map[string]structs.ServiceAddress{ - "foo": structs.ServiceAddress{ + "foo": { Address: "198.17.2.3", Port: 8080, }, - "bar": structs.ServiceAddress{ + "bar": { Address: "2001:db8::ff", Port: 9999, }, - "baz": structs.ServiceAddress{ + "baz": { Address: "127.0.0.1", Port: 8765, }, @@ -284,14 +284,14 @@ func TestListenersFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshotIngressGateway, setup: func(snap *proxycfg.ConfigSnapshot) { snap.TaggedAddresses = map[string]structs.ServiceAddress{ - "lan": structs.ServiceAddress{Address: "10.0.0.1"}, - "wan": structs.ServiceAddress{Address: "172.16.0.1"}, + "lan": {Address: "10.0.0.1"}, + "wan": {Address: "172.16.0.1"}, } snap.Proxy.Config = map[string]interface{}{ "envoy_gateway_no_default_bind": true, "envoy_gateway_bind_tagged_addresses": true, "envoy_gateway_bind_addresses": map[string]structs.ServiceAddress{ - "foo": structs.ServiceAddress{Address: "8.8.8.8"}, + "foo": {Address: "8.8.8.8"}, }, } }, @@ -396,7 +396,7 @@ func TestListenersFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshotIngress_HTTPMultipleServices, setup: func(snap *proxycfg.ConfigSnapshot) { snap.IngressGateway.Upstreams = map[proxycfg.IngressListenerKey]structs.Upstreams{ - proxycfg.IngressListenerKey{Protocol: "http", Port: 8080}: structs.Upstreams{ + {Protocol: "http", Port: 8080}: { { DestinationName: "foo", LocalBindPort: 8080, @@ -406,7 +406,7 @@ func TestListenersFromSnapshot(t *testing.T) { LocalBindPort: 8080, }, }, - proxycfg.IngressListenerKey{Protocol: "http", Port: 443}: structs.Upstreams{ + {Protocol: "http", Port: 443}: { { DestinationName: "baz", LocalBindPort: 443, diff --git a/agent/xds/routes_test.go b/agent/xds/routes_test.go index d6614025c6..176e4492a2 100644 --- a/agent/xds/routes_test.go +++ b/agent/xds/routes_test.go @@ -113,7 +113,7 @@ func TestRoutesFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshotIngress_HTTPMultipleServices, setup: func(snap *proxycfg.ConfigSnapshot) { snap.IngressGateway.Upstreams = map[proxycfg.IngressListenerKey]structs.Upstreams{ - proxycfg.IngressListenerKey{Protocol: "http", Port: 8080}: structs.Upstreams{ + {Protocol: "http", Port: 8080}: { { DestinationName: "foo", LocalBindPort: 8080, @@ -124,7 +124,7 @@ func TestRoutesFromSnapshot(t *testing.T) { LocalBindPort: 8080, }, }, - proxycfg.IngressListenerKey{Protocol: "http", Port: 443}: structs.Upstreams{ + {Protocol: "http", Port: 443}: { { DestinationName: "baz", LocalBindPort: 443, diff --git a/api/acl_test.go b/api/acl_test.go index ace0ae22c8..082608c87c 100644 --- a/api/acl_test.go +++ b/api/acl_test.go @@ -423,16 +423,16 @@ func TestAPI_ACLToken_CreateReadDelete(t *testing.T) { created, wm, err := acl.TokenCreate(&ACLToken{ Description: "token created", Policies: []*ACLTokenPolicyLink{ - &ACLTokenPolicyLink{ + { ID: policies[0].ID, }, - &ACLTokenPolicyLink{ + { ID: policies[1].ID, }, - &ACLTokenPolicyLink{ + { Name: policies[2].Name, }, - &ACLTokenPolicyLink{ + { Name: policies[3].Name, }, }, @@ -476,10 +476,10 @@ func TestAPI_ACLToken_CreateUpdate(t *testing.T) { created, _, err := acl.TokenCreate(&ACLToken{ Description: "token created", Policies: []*ACLTokenPolicyLink{ - &ACLTokenPolicyLink{ + { ID: policies[0].ID, }, - &ACLTokenPolicyLink{ + { Name: policies[2].Name, }, }, @@ -498,15 +498,15 @@ func TestAPI_ACLToken_CreateUpdate(t *testing.T) { read.Policies = append(read.Policies, &ACLTokenPolicyLink{Name: policies[2].Name}) expectedPolicies := []*ACLTokenPolicyLink{ - &ACLTokenPolicyLink{ + { ID: policies[0].ID, Name: policies[0].Name, }, - &ACLTokenPolicyLink{ + { ID: policies[1].ID, Name: policies[1].Name, }, - &ACLTokenPolicyLink{ + { ID: policies[2].ID, Name: policies[2].Name, }, @@ -540,7 +540,7 @@ func TestAPI_ACLToken_List(t *testing.T) { created1, _, err := acl.TokenCreate(&ACLToken{ Description: "token created1", Policies: []*ACLTokenPolicyLink{ - &ACLTokenPolicyLink{ + { ID: policies[0].ID, }, }, @@ -554,7 +554,7 @@ func TestAPI_ACLToken_List(t *testing.T) { created2, _, err := acl.TokenCreate(&ACLToken{ Description: "token created2", Policies: []*ACLTokenPolicyLink{ - &ACLTokenPolicyLink{ + { ID: policies[1].ID, }, }, @@ -568,7 +568,7 @@ func TestAPI_ACLToken_List(t *testing.T) { created3, _, err := acl.TokenCreate(&ACLToken{ Description: "token created3", Policies: []*ACLTokenPolicyLink{ - &ACLTokenPolicyLink{ + { ID: policies[2].ID, }, }, diff --git a/api/agent_test.go b/api/agent_test.go index 352d0ad9a2..21462df355 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -181,7 +181,7 @@ func TestAPI_AgentServiceAndReplaceChecks(t *testing.T) { ID: "foo", Tags: []string{"bar", "baz"}, TaggedAddresses: map[string]ServiceAddress{ - "lan": ServiceAddress{ + "lan": { Address: "198.18.0.1", Port: 80, }, @@ -197,7 +197,7 @@ func TestAPI_AgentServiceAndReplaceChecks(t *testing.T) { ID: "foo", Tags: []string{"bar", "baz"}, TaggedAddresses: map[string]ServiceAddress{ - "lan": ServiceAddress{ + "lan": { Address: "198.18.0.1", Port: 80, }, @@ -261,7 +261,7 @@ func TestAPI_AgentServices(t *testing.T) { ID: "foo", Tags: []string{"bar", "baz"}, TaggedAddresses: map[string]ServiceAddress{ - "lan": ServiceAddress{ + "lan": { Address: "198.18.0.1", Port: 80, }, @@ -555,11 +555,11 @@ func TestAPI_AgentServiceAddress(t *testing.T) { Name: "foo2", Port: 8000, TaggedAddresses: map[string]ServiceAddress{ - "lan": ServiceAddress{ + "lan": { Address: "192.168.0.43", Port: 8000, }, - "wan": ServiceAddress{ + "wan": { Address: "198.18.0.1", Port: 80, }, diff --git a/api/api_test.go b/api/api_test.go index f8de4486f6..f9bf4915fc 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -99,7 +99,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter t.Helper() registrations := map[string]*CatalogRegistration{ - "Node foo": &CatalogRegistration{ + "Node foo": { Datacenter: datacenter, Node: "foo", ID: "e0155642-135d-4739-9853-a1ee6c9f945b", @@ -129,7 +129,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Service redis v1 on foo": &CatalogRegistration{ + "Service redis v1 on foo": { Datacenter: datacenter, Node: "foo", SkipNodeUpdate: true, @@ -154,7 +154,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Service redis v2 on foo": &CatalogRegistration{ + "Service redis v2 on foo": { Datacenter: datacenter, Node: "foo", SkipNodeUpdate: true, @@ -179,7 +179,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Node bar": &CatalogRegistration{ + "Node bar": { Datacenter: datacenter, Node: "bar", ID: "c6e7a976-8f4f-44b5-bdd3-631be7e8ecac", @@ -202,7 +202,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Service redis v1 on bar": &CatalogRegistration{ + "Service redis v1 on bar": { Datacenter: datacenter, Node: "bar", SkipNodeUpdate: true, @@ -227,7 +227,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Service web v1 on bar": &CatalogRegistration{ + "Service web v1 on bar": { Datacenter: datacenter, Node: "bar", SkipNodeUpdate: true, @@ -253,7 +253,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Node baz": &CatalogRegistration{ + "Node baz": { Datacenter: datacenter, Node: "baz", ID: "12f96b27-a7b0-47bd-add7-044a2bfc7bfb", @@ -282,7 +282,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Service web v1 on baz": &CatalogRegistration{ + "Service web v1 on baz": { Datacenter: datacenter, Node: "baz", SkipNodeUpdate: true, @@ -308,7 +308,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Service web v2 on baz": &CatalogRegistration{ + "Service web v2 on baz": { Datacenter: datacenter, Node: "baz", SkipNodeUpdate: true, @@ -334,7 +334,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Service critical on baz": &CatalogRegistration{ + "Service critical on baz": { Datacenter: datacenter, Node: "baz", SkipNodeUpdate: true, @@ -359,7 +359,7 @@ func testNodeServiceCheckRegistrations(t *testing.T, client *Client, datacenter }, }, }, - "Service warning on baz": &CatalogRegistration{ + "Service warning on baz": { Datacenter: datacenter, Node: "baz", SkipNodeUpdate: true, diff --git a/api/config_entry_discoverychain_test.go b/api/config_entry_discoverychain_test.go index f9321d36d4..d01f7b6286 100644 --- a/api/config_entry_discoverychain_test.go +++ b/api/config_entry_discoverychain_test.go @@ -133,18 +133,18 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) { Namespace: defaultNamespace, DefaultSubset: "v1", Subsets: map[string]ServiceResolverSubset{ - "v1": ServiceResolverSubset{ + "v1": { Filter: "Service.Meta.version == v1", }, - "v2": ServiceResolverSubset{ + "v2": { Filter: "Service.Meta.version == v2", }, }, Failover: map[string]ServiceResolverFailover{ - "*": ServiceResolverFailover{ + "*": { Datacenters: []string{"dc2"}, }, - "v1": ServiceResolverFailover{ + "v1": { Service: "alternate", Namespace: defaultNamespace, }, diff --git a/api/config_entry_test.go b/api/config_entry_test.go index deedd81959..d850f40d5b 100644 --- a/api/config_entry_test.go +++ b/api/config_entry_test.go @@ -655,24 +655,24 @@ func TestDecodeConfigEntry(t *testing.T) { Enabled: true, }, Listeners: []IngressListener{ - IngressListener{ + { Port: 8080, Protocol: "http", Services: []IngressService{ - IngressService{ + { Name: "web", Namespace: "foo", }, - IngressService{ + { Name: "db", }, }, }, - IngressListener{ + { Port: 9999, Protocol: "tcp", Services: []IngressService{ - IngressService{ + { Name: "mysql", }, }, diff --git a/api/discovery_chain_test.go b/api/discovery_chain_test.go index f43f0f93f0..c4073fbf1b 100644 --- a/api/discovery_chain_test.go +++ b/api/discovery_chain_test.go @@ -34,7 +34,7 @@ func TestAPI_DiscoveryChain_Get(t *testing.T) { Protocol: "tcp", StartNode: "resolver:web.default.dc1", Nodes: map[string]*DiscoveryGraphNode{ - "resolver:web.default.dc1": &DiscoveryGraphNode{ + "resolver:web.default.dc1": { Type: DiscoveryGraphNodeTypeResolver, Name: "web.default.dc1", Resolver: &DiscoveryResolver{ @@ -45,7 +45,7 @@ func TestAPI_DiscoveryChain_Get(t *testing.T) { }, }, Targets: map[string]*DiscoveryTarget{ - "web.default.dc1": &DiscoveryTarget{ + "web.default.dc1": { ID: "web.default.dc1", Service: "web", Namespace: "default", @@ -74,7 +74,7 @@ func TestAPI_DiscoveryChain_Get(t *testing.T) { Protocol: "tcp", StartNode: "resolver:web.default.dc2", Nodes: map[string]*DiscoveryGraphNode{ - "resolver:web.default.dc2": &DiscoveryGraphNode{ + "resolver:web.default.dc2": { Type: DiscoveryGraphNodeTypeResolver, Name: "web.default.dc2", Resolver: &DiscoveryResolver{ @@ -85,7 +85,7 @@ func TestAPI_DiscoveryChain_Get(t *testing.T) { }, }, Targets: map[string]*DiscoveryTarget{ - "web.default.dc2": &DiscoveryTarget{ + "web.default.dc2": { ID: "web.default.dc2", Service: "web", Namespace: "default", @@ -121,7 +121,7 @@ func TestAPI_DiscoveryChain_Get(t *testing.T) { Protocol: "tcp", StartNode: "resolver:web.default.dc1", Nodes: map[string]*DiscoveryGraphNode{ - "resolver:web.default.dc1": &DiscoveryGraphNode{ + "resolver:web.default.dc1": { Type: DiscoveryGraphNodeTypeResolver, Name: "web.default.dc1", Resolver: &DiscoveryResolver{ @@ -131,7 +131,7 @@ func TestAPI_DiscoveryChain_Get(t *testing.T) { }, }, Targets: map[string]*DiscoveryTarget{ - "web.default.dc1": &DiscoveryTarget{ + "web.default.dc1": { ID: "web.default.dc1", Service: "web", Namespace: "default", @@ -166,7 +166,7 @@ func TestAPI_DiscoveryChain_Get(t *testing.T) { CustomizationHash: "98809527", StartNode: "resolver:web.default.dc2", Nodes: map[string]*DiscoveryGraphNode{ - "resolver:web.default.dc2": &DiscoveryGraphNode{ + "resolver:web.default.dc2": { Type: DiscoveryGraphNodeTypeResolver, Name: "web.default.dc2", Resolver: &DiscoveryResolver{ @@ -176,7 +176,7 @@ func TestAPI_DiscoveryChain_Get(t *testing.T) { }, }, Targets: map[string]*DiscoveryTarget{ - "web.default.dc2": &DiscoveryTarget{ + "web.default.dc2": { ID: "web.default.dc2", Service: "web", Namespace: "default", diff --git a/api/namespace_test.go b/api/namespace_test.go index aec09a78ed..f8edd992d9 100644 --- a/api/namespace_test.go +++ b/api/namespace_test.go @@ -25,7 +25,7 @@ func TestAPI_Namespaces(t *testing.T) { nsRole, _, err := acl.RoleCreate(&ACLRole{ Name: "ns-role", Policies: []*ACLRolePolicyLink{ - &ACLRolePolicyLink{ + { ID: nsPolicy.ID, }, }, @@ -61,10 +61,10 @@ func TestAPI_Namespaces(t *testing.T) { Description: "This namespace has ACL config attached", ACLs: &NamespaceACLConfig{ PolicyDefaults: []ACLLink{ - ACLLink{ID: nsPolicy.ID}, + {ID: nsPolicy.ID}, }, RoleDefaults: []ACLLink{ - ACLLink{ID: nsRole.ID}, + {ID: nsRole.ID}, }, }, }, nil) diff --git a/api/watch/funcs_test.go b/api/watch/funcs_test.go index 46b0be3b2a..10c67da4e6 100644 --- a/api/watch/funcs_test.go +++ b/api/watch/funcs_test.go @@ -73,7 +73,7 @@ func updateConnectCA(t *testing.T, client *api.Client) { template := x509.Certificate{ SerialNumber: big.NewInt(42), Subject: pkix.Name{CommonName: "CA Modified"}, - URIs: []*url.URL{&url.URL{Scheme: "spiffe", Host: fmt.Sprintf("11111111-2222-3333-4444-555555555555.%s", "consul")}}, + URIs: []*url.URL{{Scheme: "spiffe", Host: fmt.Sprintf("11111111-2222-3333-4444-555555555555.%s", "consul")}}, BasicConstraintsValid: true, KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign | diff --git a/command/acl/role/delete/role_delete_test.go b/command/acl/role/delete/role_delete_test.go index addecdbbb0..e2abeeac75 100644 --- a/command/acl/role/delete/role_delete_test.go +++ b/command/acl/role/delete/role_delete_test.go @@ -62,7 +62,7 @@ func TestRoleDeleteCommand(t *testing.T) { &api.ACLRole{ Name: "test-role-for-id-delete", ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "fake", }, }, @@ -102,7 +102,7 @@ func TestRoleDeleteCommand(t *testing.T) { &api.ACLRole{ Name: "test-role-for-id-prefix-delete", ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "fake", }, }, diff --git a/command/acl/role/formatter_test.go b/command/acl/role/formatter_test.go index c986d23d37..b6b3bd7c2c 100644 --- a/command/acl/role/formatter_test.go +++ b/command/acl/role/formatter_test.go @@ -59,23 +59,23 @@ func TestFormatRole(t *testing.T) { CreateIndex: 5, ModifyIndex: 10, Policies: []*api.ACLLink{ - &api.ACLLink{ + { ID: "beb04680-815b-4d7c-9e33-3d707c24672c", Name: "hobbiton", }, - &api.ACLLink{ + { ID: "18788457-584c-4812-80d3-23d403148a90", Name: "bywater", }, }, ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "gardener", Datacenters: []string{"middleearth-northwest"}, }, }, NodeIdentities: []*api.ACLNodeIdentity{ - &api.ACLNodeIdentity{ + { NodeName: "bagend", Datacenter: "middleearth-northwest", }, @@ -120,7 +120,7 @@ func TestFormatTokenList(t *testing.T) { cases := map[string]testCase{ "basic": { roles: []*api.ACLRole{ - &api.ACLRole{ + { ID: "bd6c9fb0-2d1a-4b96-acaf-669f5d7e7852", Name: "basic", Description: "test role", @@ -132,7 +132,7 @@ func TestFormatTokenList(t *testing.T) { }, "complex": { roles: []*api.ACLRole{ - &api.ACLRole{ + { ID: "c29c4ee4-bca6-474e-be37-7d9606f9582a", Name: "complex", Namespace: "foo", @@ -141,23 +141,23 @@ func TestFormatTokenList(t *testing.T) { CreateIndex: 5, ModifyIndex: 10, Policies: []*api.ACLLink{ - &api.ACLLink{ + { ID: "beb04680-815b-4d7c-9e33-3d707c24672c", Name: "hobbiton", }, - &api.ACLLink{ + { ID: "18788457-584c-4812-80d3-23d403148a90", Name: "bywater", }, }, ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "gardener", Datacenters: []string{"middleearth-northwest"}, }, }, NodeIdentities: []*api.ACLNodeIdentity{ - &api.ACLNodeIdentity{ + { NodeName: "bagend", Datacenter: "middleearth-northwest", }, diff --git a/command/acl/role/list/role_list_test.go b/command/acl/role/list/role_list_test.go index fa9fa7eb01..203630c699 100644 --- a/command/acl/role/list/role_list_test.go +++ b/command/acl/role/list/role_list_test.go @@ -51,7 +51,7 @@ func TestRoleListCommand(t *testing.T) { // Create a couple roles to list client := a.Client() svcids := []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ServiceName: "fake"}, + {ServiceName: "fake"}, } for i := 0; i < 5; i++ { name := fmt.Sprintf("test-role-%d", i) @@ -108,7 +108,7 @@ func TestRoleListCommand_JSON(t *testing.T) { // Create a couple roles to list client := a.Client() svcids := []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ServiceName: "fake"}, + {ServiceName: "fake"}, } for i := 0; i < 5; i++ { name := fmt.Sprintf("test-role-%d", i) diff --git a/command/acl/role/read/role_read_test.go b/command/acl/role/read/role_read_test.go index d78ffe0b11..588fe6a493 100644 --- a/command/acl/role/read/role_read_test.go +++ b/command/acl/role/read/role_read_test.go @@ -98,7 +98,7 @@ func TestRoleReadCommand(t *testing.T) { &api.ACLRole{ Name: "test-role-by-id", ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "fake", }, }, @@ -131,7 +131,7 @@ func TestRoleReadCommand(t *testing.T) { &api.ACLRole{ Name: "test-role-by-id-prefix", ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "fake", }, }, @@ -164,7 +164,7 @@ func TestRoleReadCommand(t *testing.T) { &api.ACLRole{ Name: "test-role-by-name", ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "fake", }, }, @@ -218,7 +218,7 @@ func TestRoleReadCommand_JSON(t *testing.T) { &api.ACLRole{ Name: "test-role-by-id", ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "fake", }, }, diff --git a/command/acl/role/update/role_update_test.go b/command/acl/role/update/role_update_test.go index ad3df1309a..c7c59bd973 100644 --- a/command/acl/role/update/role_update_test.go +++ b/command/acl/role/update/role_update_test.go @@ -62,7 +62,7 @@ func TestRoleUpdateCommand(t *testing.T) { &api.ACLRole{ Name: "test-role", ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "fake", }, }, @@ -229,7 +229,7 @@ func TestRoleUpdateCommand_JSON(t *testing.T) { &api.ACLRole{ Name: "test-role", ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "fake", }, }, @@ -327,12 +327,12 @@ func TestRoleUpdateCommand_noMerge(t *testing.T) { Name: "test-role-" + roleUnq, Description: "original description", ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "fake", }, }, Policies: []*api.ACLRolePolicyLink{ - &api.ACLRolePolicyLink{ + { ID: policy3.ID, }, }, diff --git a/command/acl/token/clone/token_clone_test.go b/command/acl/token/clone/token_clone_test.go index 0b2caeed68..76daf405d3 100644 --- a/command/acl/token/clone/token_clone_test.go +++ b/command/acl/token/clone/token_clone_test.go @@ -89,7 +89,7 @@ func TestTokenCloneCommand_Pretty(t *testing.T) { // create a token token, _, err := client.ACL().TokenCreate( - &api.ACLToken{Description: "test", Policies: []*api.ACLTokenPolicyLink{&api.ACLTokenPolicyLink{Name: "test-policy"}}}, + &api.ACLToken{Description: "test", Policies: []*api.ACLTokenPolicyLink{{Name: "test-policy"}}}, &api.WriteOptions{Token: "root"}, ) req.NoError(err) @@ -196,7 +196,7 @@ func TestTokenCloneCommand_JSON(t *testing.T) { // create a token token, _, err := client.ACL().TokenCreate( - &api.ACLToken{Description: "test", Policies: []*api.ACLTokenPolicyLink{&api.ACLTokenPolicyLink{Name: "test-policy"}}}, + &api.ACLToken{Description: "test", Policies: []*api.ACLTokenPolicyLink{{Name: "test-policy"}}}, &api.WriteOptions{Token: "root"}, ) req.NoError(err) diff --git a/command/acl/token/formatter_test.go b/command/acl/token/formatter_test.go index 84d2411565..54daea161c 100644 --- a/command/acl/token/formatter_test.go +++ b/command/acl/token/formatter_test.go @@ -78,33 +78,33 @@ func TestFormatToken(t *testing.T) { CreateIndex: 5, ModifyIndex: 10, Policies: []*api.ACLLink{ - &api.ACLLink{ + { ID: "beb04680-815b-4d7c-9e33-3d707c24672c", Name: "hobbiton", }, - &api.ACLLink{ + { ID: "18788457-584c-4812-80d3-23d403148a90", Name: "bywater", }, }, Roles: []*api.ACLLink{ - &api.ACLLink{ + { ID: "3b0a78fe-b9c3-40de-b8ea-7d4d6674b366", Name: "shire", }, - &api.ACLLink{ + { ID: "6c9d1e1d-34bc-4d55-80f3-add0890ad791", Name: "west-farthing", }, }, ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "gardener", Datacenters: []string{"middleearth-northwest"}, }, }, NodeIdentities: []*api.ACLNodeIdentity{ - &api.ACLNodeIdentity{ + { NodeName: "bagend", Datacenter: "middleearth-northwest", }, @@ -153,7 +153,7 @@ func TestFormatTokenList(t *testing.T) { cases := map[string]testCase{ "basic": { tokens: []*api.ACLTokenListEntry{ - &api.ACLTokenListEntry{ + { AccessorID: "fbd2447f-7479-4329-ad13-b021d74f86ba", Description: "test token", Local: false, @@ -166,7 +166,7 @@ func TestFormatTokenList(t *testing.T) { }, "legacy": { tokens: []*api.ACLTokenListEntry{ - &api.ACLTokenListEntry{ + { AccessorID: "8acc7486-ca54-4d3c-9aed-5cd85651b0ee", Description: "legacy", Legacy: true, @@ -175,7 +175,7 @@ func TestFormatTokenList(t *testing.T) { }, "complex": { tokens: []*api.ACLTokenListEntry{ - &api.ACLTokenListEntry{ + { AccessorID: "fbd2447f-7479-4329-ad13-b021d74f86ba", Namespace: "foo", Description: "test token", @@ -187,33 +187,33 @@ func TestFormatTokenList(t *testing.T) { CreateIndex: 5, ModifyIndex: 10, Policies: []*api.ACLLink{ - &api.ACLLink{ + { ID: "beb04680-815b-4d7c-9e33-3d707c24672c", Name: "hobbiton", }, - &api.ACLLink{ + { ID: "18788457-584c-4812-80d3-23d403148a90", Name: "bywater", }, }, Roles: []*api.ACLLink{ - &api.ACLLink{ + { ID: "3b0a78fe-b9c3-40de-b8ea-7d4d6674b366", Name: "shire", }, - &api.ACLLink{ + { ID: "6c9d1e1d-34bc-4d55-80f3-add0890ad791", Name: "west-farthing", }, }, ServiceIdentities: []*api.ACLServiceIdentity{ - &api.ACLServiceIdentity{ + { ServiceName: "gardener", Datacenters: []string{"middleearth-northwest"}, }, }, NodeIdentities: []*api.ACLNodeIdentity{ - &api.ACLNodeIdentity{ + { NodeName: "bagend", Datacenter: "middleearth-northwest", }, diff --git a/command/acl/token/update/token_update_test.go b/command/acl/token/update/token_update_test.go index 2877bc61ad..cf8cc2d767 100644 --- a/command/acl/token/update/token_update_test.go +++ b/command/acl/token/update/token_update_test.go @@ -112,11 +112,11 @@ func TestTokenUpdateCommand(t *testing.T) { require.Len(t, token.NodeIdentities, 2) expected := []*api.ACLNodeIdentity{ - &api.ACLNodeIdentity{ + { NodeName: "foo", Datacenter: "bar", }, - &api.ACLNodeIdentity{ + { NodeName: "bar", Datacenter: "baz", }, diff --git a/command/config/delete/config_delete_test.go b/command/config/delete/config_delete_test.go index 8a3cbde6fb..b7a0ad2560 100644 --- a/command/config/delete/config_delete_test.go +++ b/command/config/delete/config_delete_test.go @@ -52,8 +52,8 @@ func TestConfigDelete_InvalidArgs(t *testing.T) { t.Parallel() cases := map[string][]string{ - "no kind": []string{}, - "no name": []string{"-kind", "service-defaults"}, + "no kind": {}, + "no name": {"-kind", "service-defaults"}, } for name, tcase := range cases { diff --git a/command/config/list/config_list_test.go b/command/config/list/config_list_test.go index 6674f5c690..ebd711979e 100644 --- a/command/config/list/config_list_test.go +++ b/command/config/list/config_list_test.go @@ -62,7 +62,7 @@ func TestConfigList_InvalidArgs(t *testing.T) { t.Parallel() cases := map[string][]string{ - "no kind": []string{}, + "no kind": {}, } for name, tcase := range cases { diff --git a/command/config/read/config_read_test.go b/command/config/read/config_read_test.go index 2967b814c1..8c48a86ea1 100644 --- a/command/config/read/config_read_test.go +++ b/command/config/read/config_read_test.go @@ -54,8 +54,8 @@ func TestConfigRead_InvalidArgs(t *testing.T) { t.Parallel() cases := map[string][]string{ - "no kind": []string{}, - "no name": []string{"-kind", "service-defaults"}, + "no kind": {}, + "no name": {"-kind", "service-defaults"}, } for name, tcase := range cases { diff --git a/command/connect/proxy/flag_upstreams_test.go b/command/connect/proxy/flag_upstreams_test.go index 16eab61dcb..03100cc519 100644 --- a/command/connect/proxy/flag_upstreams_test.go +++ b/command/connect/proxy/flag_upstreams_test.go @@ -44,7 +44,7 @@ func TestFlagUpstreams(t *testing.T) { "single value", []string{"db:8181"}, map[string]proxy.UpstreamConfig{ - "db": proxy.UpstreamConfig{ + "db": { LocalBindPort: 8181, DestinationName: "db", DestinationType: "service", @@ -57,7 +57,7 @@ func TestFlagUpstreams(t *testing.T) { "single value prepared query", []string{"db.query:8181"}, map[string]proxy.UpstreamConfig{ - "db": proxy.UpstreamConfig{ + "db": { LocalBindPort: 8181, DestinationName: "db", DestinationType: "prepared_query", @@ -77,7 +77,7 @@ func TestFlagUpstreams(t *testing.T) { "address specified", []string{"db:127.0.0.55:8181"}, map[string]proxy.UpstreamConfig{ - "db": proxy.UpstreamConfig{ + "db": { LocalBindAddress: "127.0.0.55", LocalBindPort: 8181, DestinationName: "db", @@ -91,7 +91,7 @@ func TestFlagUpstreams(t *testing.T) { "repeat value, overwrite", []string{"db:8181", "db:8282"}, map[string]proxy.UpstreamConfig{ - "db": proxy.UpstreamConfig{ + "db": { LocalBindPort: 8282, DestinationName: "db", DestinationType: "service", diff --git a/command/intention/create/create.go b/command/intention/create/create.go index 2f3b0b15a1..66bdcb4b9c 100644 --- a/command/intention/create/create.go +++ b/command/intention/create/create.go @@ -181,7 +181,7 @@ func (c *cmd) ixnsFromArgs(args []string) ([]*api.Intention, error) { return nil, fmt.Errorf("Invalid intention destination: %v", err) } - return []*api.Intention{&api.Intention{ + return []*api.Intention{{ SourceNS: srcNamespace, SourceName: srcName, DestinationNS: dstNamespace, diff --git a/command/intention/finder/finder_test.go b/command/intention/finder/finder_test.go index 7428dd94e6..54af9e8e8c 100644 --- a/command/intention/finder/finder_test.go +++ b/command/intention/finder/finder_test.go @@ -20,7 +20,7 @@ func TestFinder(t *testing.T) { var ids []string { insert := [][]string{ - []string{"a", "b", "c", "d"}, + {"a", "b", "c", "d"}, } for _, v := range insert { diff --git a/command/services/deregister/deregister.go b/command/services/deregister/deregister.go index fc8efedd09..07c8c13cdf 100644 --- a/command/services/deregister/deregister.go +++ b/command/services/deregister/deregister.go @@ -51,7 +51,7 @@ func (c *cmd) Run(args []string) int { return 1 } - svcs := []*api.AgentServiceRegistration{&api.AgentServiceRegistration{ + svcs := []*api.AgentServiceRegistration{{ ID: c.flagId}} if len(args) > 0 { var err error diff --git a/command/services/register/register.go b/command/services/register/register.go index 96835de09a..da6818bb1e 100644 --- a/command/services/register/register.go +++ b/command/services/register/register.go @@ -80,7 +80,7 @@ func (c *cmd) Run(args []string) int { } } - svcs := []*api.AgentServiceRegistration{&api.AgentServiceRegistration{ + svcs := []*api.AgentServiceRegistration{{ Kind: api.ServiceKind(c.flagKind), ID: c.flagId, Name: c.flagName, diff --git a/internal/go-sso/oidcauth/jwt_test.go b/internal/go-sso/oidcauth/jwt_test.go index 33012edd11..e4b7d77c60 100644 --- a/internal/go-sso/oidcauth/jwt_test.go +++ b/internal/go-sso/oidcauth/jwt_test.go @@ -232,7 +232,7 @@ func testJWT_ClaimsFromJWT(t *testing.T, authType int) { "is_remote": "true", }, Lists: map[string][]string{ - "groups": []string{"foo", "bar"}, + "groups": {"foo", "bar"}, }, } @@ -375,7 +375,7 @@ func testJWT_ClaimsFromJWT(t *testing.T, authType int) { expectedClaims := &Claims{ Values: map[string]string{}, Lists: map[string][]string{ - "groups": []string{"foo", "bar"}, + "groups": {"foo", "bar"}, }, } require.Equal(t, expectedClaims, claims) diff --git a/internal/go-sso/oidcauth/oidc_test.go b/internal/go-sso/oidcauth/oidc_test.go index 7b9e3a1ced..ae1cd87b69 100644 --- a/internal/go-sso/oidcauth/oidc_test.go +++ b/internal/go-sso/oidcauth/oidc_test.go @@ -191,7 +191,7 @@ func TestOIDC_ClaimsFromAuthCode(t *testing.T) { "flavor": "umami", // from userinfo }, Lists: map[string][]string{ - "groups": []string{"a", "b"}, + "groups": {"a", "b"}, }, } @@ -269,7 +269,7 @@ func TestOIDC_ClaimsFromAuthCode(t *testing.T) { // "flavor": "umami", // from userinfo }, Lists: map[string][]string{ - "groups": []string{"a", "b"}, + "groups": {"a", "b"}, }, } diff --git a/internal/go-sso/oidcauth/oidcauthtest/testing.go b/internal/go-sso/oidcauth/oidcauthtest/testing.go index 6d9d273168..e53fb99f46 100644 --- a/internal/go-sso/oidcauth/oidcauthtest/testing.go +++ b/internal/go-sso/oidcauth/oidcauthtest/testing.go @@ -406,7 +406,7 @@ func newJWKS(pubKey string) (*jose.JSONWebKeySet, error) { } return &jose.JSONWebKeySet{ Keys: []jose.JSONWebKey{ - jose.JSONWebKey{ + { Key: pub, }, }, diff --git a/internal/go-sso/oidcauth/oidcjwt_test.go b/internal/go-sso/oidcauth/oidcjwt_test.go index e3a0b33d0e..814f54c67b 100644 --- a/internal/go-sso/oidcauth/oidcjwt_test.go +++ b/internal/go-sso/oidcauth/oidcjwt_test.go @@ -154,8 +154,8 @@ func TestExtractListMetadata(t *testing.T) { "data2": "val2", }, map[string][]string{ - "val1": []string{"foo"}, - "val2": []string{"bar"}, + "val1": {"foo"}, + "val2": {"bar"}, }, false, }, @@ -169,7 +169,7 @@ func TestExtractListMetadata(t *testing.T) { "data3": "val2", }, map[string][]string{ - "val1": []string{"foo"}, + "val1": {"foo"}, }, false, }, @@ -212,14 +212,14 @@ func TestExtractListMetadata(t *testing.T) { "data8": "val8", }, map[string][]string{ - "val1": []string{"foo"}, - "val2": []string{"bar"}, - "val3": []string{"true"}, - "val4": []string{"false"}, - "val5": []string{"7"}, - "val6": []string{"-12345"}, - "val7": []string{"42"}, - "val8": []string{ + "val1": {"foo"}, + "val2": {"bar"}, + "val3": {"true"}, + "val4": {"false"}, + "val5": {"7"}, + "val6": {"-12345"}, + "val7": {"42"}, + "val8": { "foo", "true", "7", "-12345", "42", }, }, @@ -261,7 +261,7 @@ func TestExtractListMetadata(t *testing.T) { "data1": "val1", }, map[string][]string{ - "val1": []string{"foo"}, // singular values become lists + "val1": {"foo"}, // singular values become lists }, false, }, @@ -276,8 +276,8 @@ func TestExtractListMetadata(t *testing.T) { "data2": "val2", }, map[string][]string{ - "val1": []string{"foo", "otherFoo"}, - "val2": []string{"bar", "otherBar"}, + "val1": {"foo", "otherFoo"}, + "val2": {"bar", "otherBar"}, }, false, }, @@ -293,8 +293,8 @@ func TestExtractListMetadata(t *testing.T) { "/data2/child": "val2", }, map[string][]string{ - "val1": []string{"foo", "otherFoo"}, - "val2": []string{"bar", "otherBar"}, + "val1": {"foo", "otherFoo"}, + "val2": {"bar", "otherBar"}, }, false, }, @@ -320,8 +320,8 @@ func TestExtractListMetadata(t *testing.T) { "data2": "val2", }, map[string][]string{ - "val1": []string{"foo", "otherFoo"}, - "val2": []string{}, + "val1": {"foo", "otherFoo"}, + "val2": {}, }, false, }, @@ -352,14 +352,14 @@ func TestExtractListMetadata(t *testing.T) { "data8": "val8", }, map[string][]string{ - "val1": []string{"foo"}, - "val2": []string{"bar"}, - "val3": []string{"true"}, - "val4": []string{"false"}, - "val5": []string{"7"}, - "val6": []string{"-12345"}, - "val7": []string{"42"}, - "val8": []string{ + "val1": {"foo"}, + "val2": {"bar"}, + "val3": {"true"}, + "val4": {"false"}, + "val5": {"7"}, + "val6": {"-12345"}, + "val7": {"42"}, + "val8": { "foo", "true", "7", "-12345", "42", }, }, @@ -378,8 +378,8 @@ func TestExtractListMetadata(t *testing.T) { "/bar/baz/1": "val2", }, map[string][]string{ - "val1": []string{"a"}, - "val2": []string{"y"}, + "val1": {"a"}, + "val2": {"y"}, }, false, }, @@ -395,7 +395,7 @@ func TestExtractListMetadata(t *testing.T) { "/bar/XXX/1243": "val2", }, map[string][]string{ - "val1": []string{"a"}, + "val1": {"a"}, }, false, }, diff --git a/lib/map_walker_test.go b/lib/map_walker_test.go index ad276c6846..2642802f9d 100644 --- a/lib/map_walker_test.go +++ b/lib/map_walker_test.go @@ -18,7 +18,7 @@ func TestMapWalk(t *testing.T) { cases := map[string]tcase{ // basically tests that []uint8 gets turned into // a string - "simple": tcase{ + "simple": { input: map[string]interface{}{ "foo": []uint8("bar"), }, @@ -29,7 +29,7 @@ func TestMapWalk(t *testing.T) { // ensures that it was actually converted and not // just the require.Equal masking the underlying // type differences - "uint8 conversion": tcase{ + "uint8 conversion": { input: map[string]interface{}{ "foo": []uint8("bar"), }, @@ -39,7 +39,7 @@ func TestMapWalk(t *testing.T) { unexpected: true, }, // ensure nested maps get processed correctly - "nested": tcase{ + "nested": { input: map[string]interface{}{ "foo": map[interface{}]interface{}{ "bar": []uint8("baz"), @@ -53,7 +53,7 @@ func TestMapWalk(t *testing.T) { "bar": "baz", }, }, - "map with slice": tcase{ + "map with slice": { input: map[string]interface{}{ "foo": []uint8("bar"), "bar": []interface{}{ diff --git a/snapshot/archive_test.go b/snapshot/archive_test.go index e41802ab34..67582af099 100644 --- a/snapshot/archive_test.go +++ b/snapshot/archive_test.go @@ -21,7 +21,7 @@ func TestArchive(t *testing.T) { Term: 2011, Configuration: raft.Configuration{ Servers: []raft.Server{ - raft.Server{ + { Suffrage: raft.Voter, ID: raft.ServerID("hello"), Address: raft.ServerAddress("127.0.0.1:8300"),