mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-02 20:16:15 -04:00
Ref/want err from err expected (#82)
consistent naming for test values using 'want' instead of 'expect/ed'
This commit is contained in:
parent
6265b307af
commit
51068abc27
91 changed files with 2319 additions and 2319 deletions
|
@ -9,6 +9,6 @@ import (
|
|||
func TestAutoscalingNodeGroup(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
nodeGroups := AutoscalingNodeGroup("some-project", "some-zone", "some-group", 0, 100)
|
||||
expectedNodeGroups := "0:100:https://www.googleapis.com/compute/v1/projects/some-project/zones/some-zone/instanceGroups/some-group"
|
||||
assert.Equal(expectedNodeGroups, nodeGroups)
|
||||
wantNodeGroups := "0:100:https://www.googleapis.com/compute/v1/projects/some-project/zones/some-zone/instanceGroups/some-group"
|
||||
assert.Equal(wantNodeGroups, nodeGroups)
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
|
||||
func TestSetGetState(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
state state.ConstellationState
|
||||
errExpected bool
|
||||
state state.ConstellationState
|
||||
wantErr bool
|
||||
}{
|
||||
"valid state": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -68,7 +68,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing coordinator": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -92,7 +92,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing node group": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -121,7 +121,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing coordinator group": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -150,7 +150,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing project id": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -179,7 +179,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing zone": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -208,7 +208,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing region": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -237,7 +237,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing name": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -265,7 +265,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing uid": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -294,7 +294,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing firewalls": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -323,7 +323,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing network": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -351,7 +351,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing external network": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -380,7 +380,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing subnetwork": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -409,7 +409,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing external subnetwork": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -438,7 +438,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPNodeInstanceTemplate: "temp-id",
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing node template": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -467,7 +467,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
||||
GCPCoordinatorInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing coordinator template": {
|
||||
state: state.ConstellationState{
|
||||
|
@ -496,7 +496,7 @@ func TestSetGetState(t *testing.T) {
|
|||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
||||
GCPNodeInstanceTemplate: "temp-id",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -506,7 +506,7 @@ func TestSetGetState(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
|
||||
client := Client{}
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.SetState(tc.state))
|
||||
} else {
|
||||
assert.NoError(client.SetState(tc.state))
|
||||
|
@ -550,7 +550,7 @@ func TestSetGetState(t *testing.T) {
|
|||
coordinatorTemplate: tc.state.GCPCoordinatorInstanceTemplate,
|
||||
serviceAccount: tc.state.GCPServiceAccount,
|
||||
}
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
_, err := client.GetState()
|
||||
assert.Error(err)
|
||||
} else {
|
||||
|
|
|
@ -57,7 +57,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
instanceGroupManagersAPI instanceGroupManagersAPI
|
||||
input CreateInstancesInput
|
||||
network string
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
instanceAPI: stubInstanceAPI{listIterator: &stubInstanceIterator{instances: testInstances}},
|
||||
|
@ -75,7 +75,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
instanceTemplateAPI: stubInstanceTemplateAPI{},
|
||||
instanceGroupManagersAPI: stubInstanceGroupManagersAPI{listIterator: &stubManagedInstanceIterator{instances: testManagedInstances}},
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed wait zonal op": {
|
||||
instanceAPI: stubInstanceAPI{listIterator: &stubInstanceIterator{instances: testInstances}},
|
||||
|
@ -85,7 +85,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
instanceGroupManagersAPI: stubInstanceGroupManagersAPI{listIterator: &stubManagedInstanceIterator{instances: testManagedInstances}},
|
||||
network: "network",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed wait global op": {
|
||||
instanceAPI: stubInstanceAPI{listIterator: &stubInstanceIterator{instances: testInstances}},
|
||||
|
@ -95,7 +95,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
instanceGroupManagersAPI: stubInstanceGroupManagersAPI{listIterator: &stubManagedInstanceIterator{instances: testManagedInstances}},
|
||||
network: "network",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed insert template": {
|
||||
instanceAPI: stubInstanceAPI{listIterator: &stubInstanceIterator{instances: testInstances}},
|
||||
|
@ -105,7 +105,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
instanceGroupManagersAPI: stubInstanceGroupManagersAPI{listIterator: &stubManagedInstanceIterator{instances: testManagedInstances}},
|
||||
input: testInput,
|
||||
network: "network",
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed insert instanceGroupManager": {
|
||||
instanceAPI: stubInstanceAPI{listIterator: &stubInstanceIterator{instances: testInstances}},
|
||||
|
@ -115,7 +115,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
instanceGroupManagersAPI: stubInstanceGroupManagersAPI{insertErr: someErr},
|
||||
network: "network",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed instanceGroupManager iterator": {
|
||||
instanceAPI: stubInstanceAPI{listIterator: &stubInstanceIterator{instances: testInstances}},
|
||||
|
@ -125,7 +125,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
instanceGroupManagersAPI: stubInstanceGroupManagersAPI{listIterator: &stubManagedInstanceIterator{nextErr: someErr}},
|
||||
network: "network",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed instance iterator": {
|
||||
instanceAPI: stubInstanceAPI{listIterator: &stubInstanceIterator{nextErr: someErr}},
|
||||
|
@ -135,7 +135,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
instanceGroupManagersAPI: stubInstanceGroupManagersAPI{listIterator: &stubManagedInstanceIterator{instances: testManagedInstances}},
|
||||
network: "network",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
coordinators: make(gcp.Instances),
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.CreateInstances(ctx, tc.input))
|
||||
} else {
|
||||
assert.NoError(client.CreateInstances(ctx, tc.input))
|
||||
|
@ -187,7 +187,7 @@ func TestTerminateInstances(t *testing.T) {
|
|||
instanceGroupManagersAPI instanceGroupManagersAPI
|
||||
|
||||
missingNodeInstanceGroup bool
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful terminate": {
|
||||
operationZoneAPI: stubOperationZoneAPI{},
|
||||
|
@ -207,14 +207,14 @@ func TestTerminateInstances(t *testing.T) {
|
|||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
instanceTemplateAPI: stubInstanceTemplateAPI{},
|
||||
instanceGroupManagersAPI: stubInstanceGroupManagersAPI{deleteErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail delete instanceTemplate": {
|
||||
operationZoneAPI: stubOperationZoneAPI{},
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
instanceTemplateAPI: stubInstanceTemplateAPI{deleteErr: someErr},
|
||||
instanceGroupManagersAPI: stubInstanceGroupManagersAPI{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
@ -245,7 +245,7 @@ func TestTerminateInstances(t *testing.T) {
|
|||
client.nodes = gcp.Instances{}
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.TerminateInstances(ctx))
|
||||
} else {
|
||||
assert.NoError(client.TerminateInstances(ctx))
|
||||
|
|
|
@ -23,7 +23,7 @@ func TestCreateVPCs(t *testing.T) {
|
|||
operationRegionAPI operationRegionAPI
|
||||
networksAPI networksAPI
|
||||
subnetworksAPI subnetworksAPI
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
|
@ -36,28 +36,28 @@ func TestCreateVPCs(t *testing.T) {
|
|||
operationRegionAPI: stubOperationRegionAPI{},
|
||||
networksAPI: stubNetworksAPI{},
|
||||
subnetworksAPI: stubSubnetworksAPI{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed wait region op": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
operationRegionAPI: stubOperationRegionAPI{waitErr: someErr},
|
||||
networksAPI: stubNetworksAPI{},
|
||||
subnetworksAPI: stubSubnetworksAPI{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed insert networks": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
operationRegionAPI: stubOperationRegionAPI{},
|
||||
networksAPI: stubNetworksAPI{insertErr: someErr},
|
||||
subnetworksAPI: stubSubnetworksAPI{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed insert subnetworks": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
operationRegionAPI: stubOperationRegionAPI{},
|
||||
networksAPI: stubNetworksAPI{},
|
||||
subnetworksAPI: stubSubnetworksAPI{insertErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ func TestCreateVPCs(t *testing.T) {
|
|||
coordinators: make(gcp.Instances),
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.CreateVPCs(ctx, testInput))
|
||||
} else {
|
||||
assert.NoError(client.CreateVPCs(ctx, testInput))
|
||||
|
@ -97,7 +97,7 @@ func TestTerminateVPCs(t *testing.T) {
|
|||
networksAPI networksAPI
|
||||
subnetworksAPI subnetworksAPI
|
||||
firewalls []string
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful terminate": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
|
@ -110,21 +110,21 @@ func TestTerminateVPCs(t *testing.T) {
|
|||
operationRegionAPI: stubOperationRegionAPI{},
|
||||
networksAPI: stubNetworksAPI{},
|
||||
subnetworksAPI: stubSubnetworksAPI{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed delete networks": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
operationRegionAPI: stubOperationRegionAPI{},
|
||||
networksAPI: stubNetworksAPI{deleteErr: someErr},
|
||||
subnetworksAPI: stubSubnetworksAPI{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed delete subnetworks": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
operationRegionAPI: stubOperationRegionAPI{},
|
||||
networksAPI: stubNetworksAPI{},
|
||||
subnetworksAPI: stubSubnetworksAPI{deleteErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"must delete firewalls first": {
|
||||
firewalls: []string{"firewall-1", "firewall-2"},
|
||||
|
@ -132,7 +132,7 @@ func TestTerminateVPCs(t *testing.T) {
|
|||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
networksAPI: stubNetworksAPI{},
|
||||
subnetworksAPI: stubSubnetworksAPI{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ func TestTerminateVPCs(t *testing.T) {
|
|||
subnetwork: "subnetwork-id-1",
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.TerminateVPCs(ctx))
|
||||
} else {
|
||||
assert.NoError(client.TerminateVPCs(ctx))
|
||||
|
@ -192,7 +192,7 @@ func TestCreateFirewall(t *testing.T) {
|
|||
operationGlobalAPI operationGlobalAPI
|
||||
firewallsAPI firewallsAPI
|
||||
firewallInput FirewallInput
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
network: "network",
|
||||
|
@ -203,18 +203,18 @@ func TestCreateFirewall(t *testing.T) {
|
|||
network: "network",
|
||||
operationGlobalAPI: stubOperationGlobalAPI{waitErr: someErr},
|
||||
firewallsAPI: stubFirewallsAPI{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed insert networks": {
|
||||
network: "network",
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
firewallsAPI: stubFirewallsAPI{insertErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"no network set": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
firewallsAPI: stubFirewallsAPI{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ func TestCreateFirewall(t *testing.T) {
|
|||
firewallsAPI: tc.firewallsAPI,
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.CreateFirewall(ctx, testFirewallInput))
|
||||
} else {
|
||||
assert.NoError(client.CreateFirewall(ctx, testFirewallInput))
|
||||
|
@ -250,7 +250,7 @@ func TestTerminateFirewall(t *testing.T) {
|
|||
operationGlobalAPI operationGlobalAPI
|
||||
firewallsAPI firewallsAPI
|
||||
firewalls []string
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful terminate": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
|
@ -266,13 +266,13 @@ func TestTerminateFirewall(t *testing.T) {
|
|||
operationGlobalAPI: stubOperationGlobalAPI{waitErr: someErr},
|
||||
firewallsAPI: stubFirewallsAPI{},
|
||||
firewalls: []string{"firewall-1", "firewall-2"},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed to delete firewalls": {
|
||||
operationGlobalAPI: stubOperationGlobalAPI{},
|
||||
firewallsAPI: stubFirewallsAPI{deleteErr: someErr},
|
||||
firewalls: []string{"firewall-1", "firewall-2"},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ func TestTerminateFirewall(t *testing.T) {
|
|||
firewallsAPI: tc.firewallsAPI,
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.TerminateFirewall(ctx))
|
||||
} else {
|
||||
assert.NoError(client.TerminateFirewall(ctx))
|
||||
|
|
|
@ -16,7 +16,7 @@ func TestAddIAMPolicyBindings(t *testing.T) {
|
|||
testCases := map[string]struct {
|
||||
projectsAPI stubProjectsAPI
|
||||
input AddIAMPolicyBindingInput
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful set without new bindings": {
|
||||
input: AddIAMPolicyBindingInput{
|
||||
|
@ -37,13 +37,13 @@ func TestAddIAMPolicyBindings(t *testing.T) {
|
|||
projectsAPI: stubProjectsAPI{
|
||||
getPolicyErr: someErr,
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"setting iam policy fails": {
|
||||
projectsAPI: stubProjectsAPI{
|
||||
setPolicyErr: someErr,
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ func TestAddIAMPolicyBindings(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.addIAMPolicyBindings(ctx, tc.input)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
@ -72,10 +72,10 @@ func TestAddIAMPolicyBindings(t *testing.T) {
|
|||
|
||||
func TestAddIAMPolicy(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
binding PolicyBinding
|
||||
policy *iampb.Policy
|
||||
errExpected bool
|
||||
policyExpected *iampb.Policy
|
||||
binding PolicyBinding
|
||||
policy *iampb.Policy
|
||||
wantErr bool
|
||||
wantPolicy *iampb.Policy
|
||||
}{
|
||||
"successful on empty policy": {
|
||||
binding: PolicyBinding{
|
||||
|
@ -85,7 +85,7 @@ func TestAddIAMPolicy(t *testing.T) {
|
|||
policy: &iampb.Policy{
|
||||
Bindings: []*iampb.Binding{},
|
||||
},
|
||||
policyExpected: &iampb.Policy{
|
||||
wantPolicy: &iampb.Policy{
|
||||
Bindings: []*iampb.Binding{
|
||||
{
|
||||
Role: "role",
|
||||
|
@ -107,7 +107,7 @@ func TestAddIAMPolicy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
policyExpected: &iampb.Policy{
|
||||
wantPolicy: &iampb.Policy{
|
||||
Bindings: []*iampb.Binding{
|
||||
{
|
||||
Role: "other-role",
|
||||
|
@ -133,7 +133,7 @@ func TestAddIAMPolicy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
policyExpected: &iampb.Policy{
|
||||
wantPolicy: &iampb.Policy{
|
||||
Bindings: []*iampb.Binding{
|
||||
{
|
||||
Role: "role",
|
||||
|
@ -155,7 +155,7 @@ func TestAddIAMPolicy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
policyExpected: &iampb.Policy{
|
||||
wantPolicy: &iampb.Policy{
|
||||
Bindings: []*iampb.Binding{
|
||||
{
|
||||
Role: "role",
|
||||
|
@ -171,7 +171,7 @@ func TestAddIAMPolicy(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
|
||||
addIAMPolicy(tc.policy, tc.binding)
|
||||
assert.True(proto.Equal(tc.policyExpected, tc.policy))
|
||||
assert.True(proto.Equal(tc.wantPolicy, tc.policy))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func TestCreateServiceAccount(t *testing.T) {
|
|||
iamAPI iamAPI
|
||||
projectsAPI stubProjectsAPI
|
||||
input ServiceAccountInput
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
iamAPI: stubIAMAPI{serviceAccountKeyData: keyData},
|
||||
|
@ -45,30 +45,30 @@ func TestCreateServiceAccount(t *testing.T) {
|
|||
iamAPI: stubIAMAPI{serviceAccountKeyData: keyData},
|
||||
},
|
||||
"creating account fails": {
|
||||
iamAPI: stubIAMAPI{createErr: someErr},
|
||||
errExpected: true,
|
||||
iamAPI: stubIAMAPI{createErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"creating account key fails": {
|
||||
iamAPI: stubIAMAPI{createKeyErr: someErr},
|
||||
errExpected: true,
|
||||
iamAPI: stubIAMAPI{createKeyErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"key data missing": {
|
||||
iamAPI: stubIAMAPI{},
|
||||
errExpected: true,
|
||||
iamAPI: stubIAMAPI{},
|
||||
wantErr: true,
|
||||
},
|
||||
"key data corrupt": {
|
||||
iamAPI: stubIAMAPI{serviceAccountKeyData: []byte("invalid key data")},
|
||||
errExpected: true,
|
||||
iamAPI: stubIAMAPI{serviceAccountKeyData: []byte("invalid key data")},
|
||||
wantErr: true,
|
||||
},
|
||||
"retrieving iam policy bindings fails": {
|
||||
iamAPI: stubIAMAPI{},
|
||||
projectsAPI: stubProjectsAPI{getPolicyErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"setting iam policy bindings fails": {
|
||||
iamAPI: stubIAMAPI{},
|
||||
projectsAPI: stubProjectsAPI{setPolicyErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ func TestCreateServiceAccount(t *testing.T) {
|
|||
}
|
||||
|
||||
serviceAccountKey, err := client.CreateServiceAccount(ctx, tc.input)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
@ -100,8 +100,8 @@ func TestCreateServiceAccount(t *testing.T) {
|
|||
|
||||
func TestTerminateServiceAccount(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
iamAPI iamAPI
|
||||
errExpected bool
|
||||
iamAPI iamAPI
|
||||
wantErr bool
|
||||
}{
|
||||
"delete works": {
|
||||
iamAPI: stubIAMAPI{},
|
||||
|
@ -110,7 +110,7 @@ func TestTerminateServiceAccount(t *testing.T) {
|
|||
iamAPI: stubIAMAPI{
|
||||
deleteServiceAccountErr: errors.New("someErr"),
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ func TestTerminateServiceAccount(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.TerminateServiceAccount(ctx)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
@ -9,22 +9,22 @@ import (
|
|||
func TestIDs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
testState := testInstances()
|
||||
expectedIDs := []string{"id-9", "id-10", "id-11", "id-12"}
|
||||
assert.ElementsMatch(expectedIDs, testState.IDs())
|
||||
wantIDs := []string{"id-9", "id-10", "id-11", "id-12"}
|
||||
assert.ElementsMatch(wantIDs, testState.IDs())
|
||||
}
|
||||
|
||||
func TestPublicIPs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
testState := testInstances()
|
||||
expectedIPs := []string{"192.0.2.1", "192.0.2.3", "192.0.2.5", "192.0.2.7"}
|
||||
assert.ElementsMatch(expectedIPs, testState.PublicIPs())
|
||||
wantIPs := []string{"192.0.2.1", "192.0.2.3", "192.0.2.5", "192.0.2.7"}
|
||||
assert.ElementsMatch(wantIPs, testState.PublicIPs())
|
||||
}
|
||||
|
||||
func TestPrivateIPs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
testState := testInstances()
|
||||
expectedIPs := []string{"192.0.2.2", "192.0.2.4", "192.0.2.6", "192.0.2.8"}
|
||||
assert.ElementsMatch(expectedIPs, testState.PrivateIPs())
|
||||
wantIPs := []string{"192.0.2.2", "192.0.2.4", "192.0.2.6", "192.0.2.8"}
|
||||
assert.ElementsMatch(wantIPs, testState.PrivateIPs())
|
||||
}
|
||||
|
||||
func TestGetOne(t *testing.T) {
|
||||
|
@ -43,9 +43,9 @@ func TestGetOthers(t *testing.T) {
|
|||
for _, id := range testCases {
|
||||
others := testInstances().GetOthers(id)
|
||||
assert.NotContains(others, id)
|
||||
expectedInstances := testInstances()
|
||||
delete(expectedInstances, id)
|
||||
assert.ElementsMatch(others.IDs(), expectedInstances.IDs())
|
||||
wantInstances := testInstances()
|
||||
delete(wantInstances, id)
|
||||
assert.ElementsMatch(others.IDs(), wantInstances.IDs())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue