mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-12-15 16:09:39 -05: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("scale-set", 0, 100)
|
||||
expectedNodeGroups := "0:100:scale-set"
|
||||
assert.Equal(expectedNodeGroups, nodeGroups)
|
||||
wantNodeGroups := "0:100:scale-set"
|
||||
assert.Equal(wantNodeGroups, nodeGroups)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func TestCreateServicePrincipal(t *testing.T) {
|
|||
servicePrincipalsAPI servicePrincipalsAPI
|
||||
roleAssignmentsAPI roleAssignmentsAPI
|
||||
resourceGroupAPI resourceGroupAPI
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
applicationsAPI: stubApplicationsAPI{},
|
||||
|
|
@ -39,14 +39,14 @@ func TestCreateServicePrincipal(t *testing.T) {
|
|||
applicationsAPI: stubApplicationsAPI{
|
||||
createErr: someErr,
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed service principal create": {
|
||||
applicationsAPI: stubApplicationsAPI{},
|
||||
servicePrincipalsAPI: stubServicePrincipalsAPI{
|
||||
createErr: someErr,
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed role assignment": {
|
||||
applicationsAPI: stubApplicationsAPI{},
|
||||
|
|
@ -59,7 +59,7 @@ func TestCreateServicePrincipal(t *testing.T) {
|
|||
ID: to.StringPtr("resource-group-id"),
|
||||
},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed update creds": {
|
||||
applicationsAPI: stubApplicationsAPI{
|
||||
|
|
@ -72,7 +72,7 @@ func TestCreateServicePrincipal(t *testing.T) {
|
|||
ID: to.StringPtr("resource-group-id"),
|
||||
},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -93,7 +93,7 @@ func TestCreateServicePrincipal(t *testing.T) {
|
|||
}
|
||||
|
||||
_, err := client.CreateServicePrincipal(ctx)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ func TestTerminateServicePrincipal(t *testing.T) {
|
|||
testCases := map[string]struct {
|
||||
appObjectID string
|
||||
applicationsAPI applicationsAPI
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful terminate": {
|
||||
appObjectID: "object-id",
|
||||
|
|
@ -121,7 +121,7 @@ func TestTerminateServicePrincipal(t *testing.T) {
|
|||
applicationsAPI: stubApplicationsAPI{
|
||||
deleteErr: someErr,
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -139,7 +139,7 @@ func TestTerminateServicePrincipal(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.TerminateServicePrincipal(ctx)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ func TestCreateADApplication(t *testing.T) {
|
|||
someErr := errors.New("failed")
|
||||
testCases := map[string]struct {
|
||||
applicationsAPI applicationsAPI
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
applicationsAPI: stubApplicationsAPI{},
|
||||
|
|
@ -161,7 +161,7 @@ func TestCreateADApplication(t *testing.T) {
|
|||
applicationsAPI: stubApplicationsAPI{
|
||||
createErr: someErr,
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"app create returns invalid appid": {
|
||||
applicationsAPI: stubApplicationsAPI{
|
||||
|
|
@ -169,7 +169,7 @@ func TestCreateADApplication(t *testing.T) {
|
|||
ObjectID: proto.String("00000000-0000-0000-0000-000000000001"),
|
||||
},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"app create returns invalid objectid": {
|
||||
applicationsAPI: stubApplicationsAPI{
|
||||
|
|
@ -177,7 +177,7 @@ func TestCreateADApplication(t *testing.T) {
|
|||
AppID: proto.String("00000000-0000-0000-0000-000000000000"),
|
||||
},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -193,7 +193,7 @@ func TestCreateADApplication(t *testing.T) {
|
|||
}
|
||||
|
||||
appCredentials, err := client.createADApplication(ctx)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -207,7 +207,7 @@ func TestCreateAppServicePrincipal(t *testing.T) {
|
|||
someErr := errors.New("failed")
|
||||
testCases := map[string]struct {
|
||||
servicePrincipalsAPI servicePrincipalsAPI
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
servicePrincipalsAPI: stubServicePrincipalsAPI{},
|
||||
|
|
@ -216,13 +216,13 @@ func TestCreateAppServicePrincipal(t *testing.T) {
|
|||
servicePrincipalsAPI: stubServicePrincipalsAPI{
|
||||
createErr: someErr,
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"service principal create returns invalid objectid": {
|
||||
servicePrincipalsAPI: stubServicePrincipalsAPI{
|
||||
createServicePrincipal: &graphrbac.ServicePrincipal{},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -238,7 +238,7 @@ func TestCreateAppServicePrincipal(t *testing.T) {
|
|||
}
|
||||
|
||||
_, err := client.createAppServicePrincipal(ctx, "app-id")
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -252,7 +252,7 @@ func TestAssignOwnerOfResourceGroup(t *testing.T) {
|
|||
testCases := map[string]struct {
|
||||
roleAssignmentsAPI roleAssignmentsAPI
|
||||
resourceGroupAPI resourceGroupAPI
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful assign": {
|
||||
roleAssignmentsAPI: &stubRoleAssignmentsAPI{},
|
||||
|
|
@ -271,21 +271,21 @@ func TestAssignOwnerOfResourceGroup(t *testing.T) {
|
|||
ID: to.StringPtr("resource-group-id"),
|
||||
},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed resource group get": {
|
||||
roleAssignmentsAPI: &stubRoleAssignmentsAPI{},
|
||||
resourceGroupAPI: stubResourceGroupAPI{
|
||||
getErr: someErr,
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"resource group get returns invalid id": {
|
||||
roleAssignmentsAPI: &stubRoleAssignmentsAPI{},
|
||||
resourceGroupAPI: stubResourceGroupAPI{
|
||||
getResourceGroup: armresources.ResourceGroup{},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"create returns PrincipalNotFound the first time": {
|
||||
roleAssignmentsAPI: &stubRoleAssignmentsAPI{
|
||||
|
|
@ -313,7 +313,7 @@ func TestAssignOwnerOfResourceGroup(t *testing.T) {
|
|||
ID: to.StringPtr("resource-group-id"),
|
||||
},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"create service error code is unknown": {
|
||||
roleAssignmentsAPI: &stubRoleAssignmentsAPI{
|
||||
|
|
@ -331,7 +331,7 @@ func TestAssignOwnerOfResourceGroup(t *testing.T) {
|
|||
ID: to.StringPtr("resource-group-id"),
|
||||
},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -350,7 +350,7 @@ func TestAssignOwnerOfResourceGroup(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.assignResourceGroupRole(ctx, "principal-id", "role-definition-id")
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,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{
|
||||
|
|
@ -62,7 +62,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing coordinator": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -84,7 +84,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing name": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -111,7 +111,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing uid": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -138,7 +138,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing resource group": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -165,7 +165,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing location": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -192,7 +192,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing subscription": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -219,7 +219,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing tenant": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -246,7 +246,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing subnet": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -273,7 +273,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing network security group": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -300,7 +300,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNodesScaleSet: "node-scale-set",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing node scale set": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -327,7 +327,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNetworkSecurityGroup: "network-security-group",
|
||||
AzureCoordinatorsScaleSet: "coordinator-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing coordinator scale set": {
|
||||
state: state.ConstellationState{
|
||||
|
|
@ -354,7 +354,7 @@ func TestSetGetState(t *testing.T) {
|
|||
AzureNetworkSecurityGroup: "network-security-group",
|
||||
AzureNodesScaleSet: "node-scale-set",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -364,7 +364,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))
|
||||
|
|
@ -404,7 +404,7 @@ func TestSetGetState(t *testing.T) {
|
|||
nodesScaleSet: tc.state.AzureNodesScaleSet,
|
||||
coordinatorsScaleSet: tc.state.AzureCoordinatorsScaleSet,
|
||||
}
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
_, err := client.GetState()
|
||||
assert.Error(err)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ func TestCreateResourceGroup(t *testing.T) {
|
|||
someErr := errors.New("failed")
|
||||
testCases := map[string]struct {
|
||||
resourceGroupAPI resourceGroupAPI
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
resourceGroupAPI: stubResourceGroupAPI{},
|
||||
},
|
||||
"failed create": {
|
||||
resourceGroupAPI: stubResourceGroupAPI{createErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -42,7 +42,7 @@ func TestCreateResourceGroup(t *testing.T) {
|
|||
coordinators: make(azure.Instances),
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.CreateResourceGroup(ctx))
|
||||
} else {
|
||||
assert.NoError(client.CreateResourceGroup(ctx))
|
||||
|
|
@ -77,7 +77,7 @@ func TestTerminateResourceGroup(t *testing.T) {
|
|||
resourceGroup string
|
||||
resourceGroupAPI resourceGroupAPI
|
||||
client Client
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful terminate": {
|
||||
resourceGroupAPI: stubResourceGroupAPI{},
|
||||
|
|
@ -91,12 +91,12 @@ func TestTerminateResourceGroup(t *testing.T) {
|
|||
"failed terminate": {
|
||||
resourceGroupAPI: stubResourceGroupAPI{terminateErr: someErr},
|
||||
client: clientWithResourceGroup,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed to poll terminate response": {
|
||||
resourceGroupAPI: stubResourceGroupAPI{stubResponse: stubResourceGroupsDeletePollerResponse{pollerErr: someErr}},
|
||||
client: clientWithResourceGroup,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -105,7 +105,7 @@ func TestTerminateResourceGroup(t *testing.T) {
|
|||
tc.client.resourceGroupAPI = tc.resourceGroupAPI
|
||||
ctx := context.Background()
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(tc.client.TerminateResourceGroup(ctx))
|
||||
return
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
resourceGroupAPI resourceGroupAPI
|
||||
roleAssignmentsAPI roleAssignmentsAPI
|
||||
createInstancesInput CreateInstancesInput
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{},
|
||||
|
|
@ -166,7 +166,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
Image: "image",
|
||||
UserAssingedIdentity: "identity",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"error when polling create scale set response": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{},
|
||||
|
|
@ -181,7 +181,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
Image: "image",
|
||||
UserAssingedIdentity: "identity",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"error when retrieving private IPs": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{},
|
||||
|
|
@ -195,7 +195,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
Image: "image",
|
||||
UserAssingedIdentity: "identity",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -218,7 +218,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
coordinators: make(azure.Instances),
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.CreateInstances(ctx, tc.createInstancesInput))
|
||||
} else {
|
||||
assert.NoError(client.CreateInstances(ctx, tc.createInstancesInput))
|
||||
|
|
@ -243,7 +243,7 @@ func TestCreateInstancesVMs(t *testing.T) {
|
|||
resourceGroupAPI resourceGroupAPI
|
||||
roleAssignmentsAPI roleAssignmentsAPI
|
||||
createInstancesInput CreateInstancesInput
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{},
|
||||
|
|
@ -278,7 +278,7 @@ func TestCreateInstancesVMs(t *testing.T) {
|
|||
InstanceType: "type",
|
||||
Image: "image",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"error when polling create scale set response": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{},
|
||||
|
|
@ -292,7 +292,7 @@ func TestCreateInstancesVMs(t *testing.T) {
|
|||
InstanceType: "type",
|
||||
Image: "image",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"error when creating NIC": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{},
|
||||
|
|
@ -306,7 +306,7 @@ func TestCreateInstancesVMs(t *testing.T) {
|
|||
InstanceType: "type",
|
||||
Image: "image",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"error when creating public IP": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{createErr: someErr},
|
||||
|
|
@ -320,7 +320,7 @@ func TestCreateInstancesVMs(t *testing.T) {
|
|||
InstanceType: "type",
|
||||
Image: "image",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"error when retrieving public IP": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{getErr: someErr},
|
||||
|
|
@ -334,7 +334,7 @@ func TestCreateInstancesVMs(t *testing.T) {
|
|||
InstanceType: "type",
|
||||
Image: "image",
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -358,7 +358,7 @@ func TestCreateInstancesVMs(t *testing.T) {
|
|||
coordinators: make(azure.Instances),
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.CreateInstancesVMs(ctx, tc.createInstancesInput))
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,18 +14,18 @@ func TestCreateVirtualNetwork(t *testing.T) {
|
|||
someErr := errors.New("failed")
|
||||
testCases := map[string]struct {
|
||||
networksAPI networksAPI
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
networksAPI: stubNetworksAPI{},
|
||||
},
|
||||
"failed to get response from successful create": {
|
||||
networksAPI: stubNetworksAPI{stubResponse: stubVirtualNetworksCreateOrUpdatePollerResponse{pollerErr: someErr}},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed create": {
|
||||
networksAPI: stubNetworksAPI{createErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ func TestCreateVirtualNetwork(t *testing.T) {
|
|||
coordinators: make(azure.Instances),
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.CreateVirtualNetwork(ctx))
|
||||
} else {
|
||||
assert.NoError(client.CreateVirtualNetwork(ctx))
|
||||
|
|
@ -78,18 +78,18 @@ func TestCreateSecurityGroup(t *testing.T) {
|
|||
|
||||
testCases := map[string]struct {
|
||||
networkSecurityGroupsAPI networkSecurityGroupsAPI
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
networkSecurityGroupsAPI: stubNetworkSecurityGroupsAPI{},
|
||||
},
|
||||
"failed to get response from successful create": {
|
||||
networkSecurityGroupsAPI: stubNetworkSecurityGroupsAPI{stubPoller: stubNetworkSecurityGroupsCreateOrUpdatePollerResponse{pollerErr: someErr}},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed create": {
|
||||
networkSecurityGroupsAPI: stubNetworkSecurityGroupsAPI{createErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ func TestCreateSecurityGroup(t *testing.T) {
|
|||
networkSecurityGroupsAPI: tc.networkSecurityGroupsAPI,
|
||||
}
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(client.CreateSecurityGroup(ctx, testNetworkSecurityGroupInput))
|
||||
} else {
|
||||
assert.NoError(client.CreateSecurityGroup(ctx, testNetworkSecurityGroupInput))
|
||||
|
|
@ -126,7 +126,7 @@ func TestCreateNIC(t *testing.T) {
|
|||
networkInterfacesAPI networkInterfacesAPI
|
||||
name string
|
||||
publicIPAddressID string
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
networkInterfacesAPI: stubNetworkInterfacesAPI{},
|
||||
|
|
@ -135,11 +135,11 @@ func TestCreateNIC(t *testing.T) {
|
|||
},
|
||||
"failed to get response from successful create": {
|
||||
networkInterfacesAPI: stubNetworkInterfacesAPI{stubResp: stubInterfacesClientCreateOrUpdatePollerResponse{pollErr: someErr}},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed create": {
|
||||
networkInterfacesAPI: stubNetworkInterfacesAPI{createErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ func TestCreateNIC(t *testing.T) {
|
|||
}
|
||||
|
||||
ip, id, err := client.createNIC(ctx, tc.name, tc.publicIPAddressID)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -177,7 +177,7 @@ func TestCreatePublicIPAddress(t *testing.T) {
|
|||
testCases := map[string]struct {
|
||||
publicIPAddressesAPI publicIPAddressesAPI
|
||||
name string
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"successful create": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{},
|
||||
|
|
@ -185,11 +185,11 @@ func TestCreatePublicIPAddress(t *testing.T) {
|
|||
},
|
||||
"failed to get response from successful create": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{stubCreateResponse: stubPublicIPAddressesClientCreateOrUpdatePollerResponse{pollErr: someErr}},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"failed create": {
|
||||
publicIPAddressesAPI: stubPublicIPAddressesAPI{createErr: someErr},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -209,7 +209,7 @@ func TestCreatePublicIPAddress(t *testing.T) {
|
|||
}
|
||||
|
||||
id, err := client.createPublicIPAddress(ctx, tc.name)
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func TestFirewallAzure(t *testing.T) {
|
|||
Port: 4433,
|
||||
},
|
||||
}
|
||||
expectedOutput := []*armnetwork.SecurityRule{
|
||||
wantOutput := []*armnetwork.SecurityRule{
|
||||
{
|
||||
Name: proto.String("perm1"),
|
||||
Properties: &armnetwork.SecurityRulePropertiesFormat{
|
||||
|
|
@ -121,7 +121,7 @@ func TestFirewallAzure(t *testing.T) {
|
|||
}
|
||||
|
||||
out := input.Azure()
|
||||
assert.Equal(expectedOutput, out)
|
||||
assert.Equal(wantOutput, out)
|
||||
}
|
||||
|
||||
func TestIPPermissonsToAWS(t *testing.T) {
|
||||
|
|
@ -147,7 +147,7 @@ func TestIPPermissonsToAWS(t *testing.T) {
|
|||
Port: 4433,
|
||||
},
|
||||
}
|
||||
expectedOutput := []ec2types.IpPermission{
|
||||
wantOutput := []ec2types.IpPermission{
|
||||
{
|
||||
FromPort: proto.Int32(int32(22)),
|
||||
ToPort: proto.Int32(int32(22)),
|
||||
|
|
@ -184,5 +184,5 @@ func TestIPPermissonsToAWS(t *testing.T) {
|
|||
}
|
||||
|
||||
out := input.AWS()
|
||||
assert.Equal(expectedOutput, out)
|
||||
assert.Equal(wantOutput, out)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ func TestInitialize(t *testing.T) {
|
|||
privKey string
|
||||
vpnHandler vpnHandler
|
||||
initVPN bool
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"initialize some gcp instances": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -112,33 +112,33 @@ func TestInitialize(t *testing.T) {
|
|||
client: &fakeProtoClient{
|
||||
respClient: &fakeActivationRespClient{responses: testActivationResps},
|
||||
},
|
||||
waiter: &stubStatusWaiter{},
|
||||
vpnHandler: &stubVPNHandler{applyErr: someErr},
|
||||
initVPN: true,
|
||||
privKey: testKey,
|
||||
errExpected: true,
|
||||
waiter: &stubStatusWaiter{},
|
||||
vpnHandler: &stubVPNHandler{applyErr: someErr},
|
||||
initVPN: true,
|
||||
privKey: testKey,
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid create vpn config": {
|
||||
existingState: testAzureState,
|
||||
client: &fakeProtoClient{
|
||||
respClient: &fakeActivationRespClient{responses: testActivationResps},
|
||||
},
|
||||
waiter: &stubStatusWaiter{},
|
||||
vpnHandler: &stubVPNHandler{createErr: someErr},
|
||||
initVPN: true,
|
||||
privKey: testKey,
|
||||
errExpected: true,
|
||||
waiter: &stubStatusWaiter{},
|
||||
vpnHandler: &stubVPNHandler{createErr: someErr},
|
||||
initVPN: true,
|
||||
privKey: testKey,
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid write vpn config": {
|
||||
existingState: testAzureState,
|
||||
client: &fakeProtoClient{
|
||||
respClient: &fakeActivationRespClient{responses: testActivationResps},
|
||||
},
|
||||
waiter: &stubStatusWaiter{},
|
||||
vpnHandler: &stubVPNHandler{marshalErr: someErr},
|
||||
initVPN: true,
|
||||
privKey: testKey,
|
||||
errExpected: true,
|
||||
waiter: &stubStatusWaiter{},
|
||||
vpnHandler: &stubVPNHandler{marshalErr: someErr},
|
||||
initVPN: true,
|
||||
privKey: testKey,
|
||||
wantErr: true,
|
||||
},
|
||||
"no state exists": {
|
||||
existingState: state.ConstellationState{},
|
||||
|
|
@ -146,18 +146,18 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"no instances to pick one": {
|
||||
existingState: state.ConstellationState{
|
||||
EC2Instances: ec2.Instances{},
|
||||
EC2SecurityGroup: "sg-test",
|
||||
},
|
||||
client: &stubProtoClient{},
|
||||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
client: &stubProtoClient{},
|
||||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
wantErr: true,
|
||||
},
|
||||
"public key to short": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -165,7 +165,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: base64.StdEncoding.EncodeToString([]byte("tooShortKey")),
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"public key to long": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -173,7 +173,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: base64.StdEncoding.EncodeToString([]byte("thisWireguardKeyIsToLongAndHasTooManyBytes")),
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"public key not base64": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -181,7 +181,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: "this is not base64 encoded",
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail Connect": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -189,7 +189,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail Activate": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -197,7 +197,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail respClient WriteLogStream": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -205,7 +205,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail respClient getKubeconfig": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -213,7 +213,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail respClient getCoordinatorVpnKey": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -221,7 +221,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail respClient getClientVpnIp": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -229,7 +229,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail respClient getOwnerID": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -237,7 +237,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail respClient getClusterID": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -245,7 +245,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail to wait for required status": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -253,7 +253,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{waitForAllErr: someErr},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail to create service account": {
|
||||
existingState: testGcpState,
|
||||
|
|
@ -262,7 +262,7 @@ func TestInitialize(t *testing.T) {
|
|||
waiter: &stubStatusWaiter{},
|
||||
privKey: testKey,
|
||||
vpnHandler: &stubVPNHandler{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -294,7 +294,7 @@ func TestInitialize(t *testing.T) {
|
|||
|
||||
err := initialize(ctx, cmd, tc.client, &tc.serviceAccountCreator, fileHandler, tc.waiter, tc.vpnHandler)
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
require.NoError(err)
|
||||
|
|
@ -343,28 +343,28 @@ func TestIpsToEndpoints(t *testing.T) {
|
|||
|
||||
func TestInitCompletion(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
toComplete string
|
||||
resultExpected []string
|
||||
shellCDExpected cobra.ShellCompDirective
|
||||
args []string
|
||||
toComplete string
|
||||
wantResult []string
|
||||
wantShellCD cobra.ShellCompDirective
|
||||
}{
|
||||
"first arg": {
|
||||
args: []string{},
|
||||
toComplete: "hello",
|
||||
resultExpected: []string{},
|
||||
shellCDExpected: cobra.ShellCompDirectiveDefault,
|
||||
args: []string{},
|
||||
toComplete: "hello",
|
||||
wantResult: []string{},
|
||||
wantShellCD: cobra.ShellCompDirectiveDefault,
|
||||
},
|
||||
"secnod arg": {
|
||||
args: []string{"23"},
|
||||
toComplete: "/test/h",
|
||||
resultExpected: []string{},
|
||||
shellCDExpected: cobra.ShellCompDirectiveError,
|
||||
args: []string{"23"},
|
||||
toComplete: "/test/h",
|
||||
wantResult: []string{},
|
||||
wantShellCD: cobra.ShellCompDirectiveError,
|
||||
},
|
||||
"third arg": {
|
||||
args: []string{"./file", "sth"},
|
||||
toComplete: "./file",
|
||||
resultExpected: []string{},
|
||||
shellCDExpected: cobra.ShellCompDirectiveError,
|
||||
args: []string{"./file", "sth"},
|
||||
toComplete: "./file",
|
||||
wantResult: []string{},
|
||||
wantShellCD: cobra.ShellCompDirectiveError,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -374,8 +374,8 @@ func TestInitCompletion(t *testing.T) {
|
|||
|
||||
cmd := &cobra.Command{}
|
||||
result, shellCD := initCompletion(cmd, tc.args, tc.toComplete)
|
||||
assert.Equal(tc.resultExpected, result)
|
||||
assert.Equal(tc.shellCDExpected, shellCD)
|
||||
assert.Equal(tc.wantResult, result)
|
||||
assert.Equal(tc.wantShellCD, shellCD)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -406,55 +406,55 @@ func TestReadOrGeneratedMasterSecret(t *testing.T) {
|
|||
filecontent string
|
||||
createFile bool
|
||||
fs func() afero.Fs
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"file with secret exists": {
|
||||
filename: "someSecret",
|
||||
filecontent: base64.StdEncoding.EncodeToString([]byte("ConstellationSecret")),
|
||||
createFile: true,
|
||||
fs: afero.NewMemMapFs,
|
||||
errExpected: false,
|
||||
wantErr: false,
|
||||
},
|
||||
"no file given": {
|
||||
filename: "",
|
||||
filecontent: "",
|
||||
fs: afero.NewMemMapFs,
|
||||
errExpected: false,
|
||||
wantErr: false,
|
||||
},
|
||||
"file does not exist": {
|
||||
filename: "nonExistingSecret",
|
||||
filecontent: "",
|
||||
createFile: false,
|
||||
fs: afero.NewMemMapFs,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"file is empty": {
|
||||
filename: "emptySecret",
|
||||
filecontent: "",
|
||||
createFile: true,
|
||||
fs: afero.NewMemMapFs,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"secret too short": {
|
||||
filename: "shortSecret",
|
||||
filecontent: base64.StdEncoding.EncodeToString([]byte("short")),
|
||||
createFile: true,
|
||||
fs: afero.NewMemMapFs,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"secret not encoded": {
|
||||
filename: "unencodedSecret",
|
||||
filecontent: "Constellation",
|
||||
createFile: true,
|
||||
fs: afero.NewMemMapFs,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"file not writeable": {
|
||||
filename: "",
|
||||
filecontent: "",
|
||||
createFile: false,
|
||||
fs: func() afero.Fs { return afero.NewReadOnlyFs(afero.NewMemMapFs()) },
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -472,7 +472,7 @@ func TestReadOrGeneratedMasterSecret(t *testing.T) {
|
|||
var out bytes.Buffer
|
||||
secret, err := readOrGeneratedMasterSecret(&out, fileHandler, tc.filename)
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ import (
|
|||
|
||||
func TestTerminateCmdArgumentValidation(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
expectErr bool
|
||||
args []string
|
||||
wantErr bool
|
||||
}{
|
||||
"no args": {[]string{}, false},
|
||||
"some args": {[]string{"hello", "test"}, true},
|
||||
|
|
@ -30,7 +30,7 @@ func TestTerminateCmdArgumentValidation(t *testing.T) {
|
|||
cmd := newTerminateCmd()
|
||||
err := cmd.ValidateArgs(tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ func TestAskToConfirm(t *testing.T) {
|
|||
}
|
||||
|
||||
testCases := map[string]struct {
|
||||
input string
|
||||
expectedErr error
|
||||
input string
|
||||
wantErr error
|
||||
}{
|
||||
"user confirms": {"y\n", nil},
|
||||
"user confirms long": {"yes\n", nil},
|
||||
|
|
@ -53,7 +53,7 @@ func TestAskToConfirm(t *testing.T) {
|
|||
cmd.SetIn(in)
|
||||
|
||||
err := cmd.Execute()
|
||||
assert.ErrorIs(err, tc.expectedErr)
|
||||
assert.ErrorIs(err, tc.wantErr)
|
||||
|
||||
output, err := io.ReadAll(out)
|
||||
assert.NoError(err)
|
||||
|
|
@ -66,10 +66,10 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
zero := []byte("00000000000000000000000000000000")
|
||||
|
||||
testCases := map[string]struct {
|
||||
pcrs map[uint32][]byte
|
||||
dontWarnInit bool
|
||||
expectedWarnings []string
|
||||
errExpected bool
|
||||
pcrs map[uint32][]byte
|
||||
dontWarnInit bool
|
||||
wantWarnings []string
|
||||
wantErr bool
|
||||
}{
|
||||
"no warnings": {
|
||||
pcrs: map[uint32][]byte{
|
||||
|
|
@ -114,7 +114,7 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
11: zero,
|
||||
12: zero,
|
||||
},
|
||||
expectedWarnings: []string{"BIOS"},
|
||||
wantWarnings: []string{"BIOS"},
|
||||
},
|
||||
"warn for OPROM": {
|
||||
pcrs: map[uint32][]byte{
|
||||
|
|
@ -128,7 +128,7 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
11: zero,
|
||||
12: zero,
|
||||
},
|
||||
expectedWarnings: []string{"OPROM"},
|
||||
wantWarnings: []string{"OPROM"},
|
||||
},
|
||||
"warn for MBR": {
|
||||
pcrs: map[uint32][]byte{
|
||||
|
|
@ -142,7 +142,7 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
11: zero,
|
||||
12: zero,
|
||||
},
|
||||
expectedWarnings: []string{"MBR"},
|
||||
wantWarnings: []string{"MBR"},
|
||||
},
|
||||
"warn for kernel": {
|
||||
pcrs: map[uint32][]byte{
|
||||
|
|
@ -156,7 +156,7 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
11: zero,
|
||||
12: zero,
|
||||
},
|
||||
expectedWarnings: []string{"kernel"},
|
||||
wantWarnings: []string{"kernel"},
|
||||
},
|
||||
"warn for initrd": {
|
||||
pcrs: map[uint32][]byte{
|
||||
|
|
@ -170,7 +170,7 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
11: zero,
|
||||
12: zero,
|
||||
},
|
||||
expectedWarnings: []string{"initrd"},
|
||||
wantWarnings: []string{"initrd"},
|
||||
},
|
||||
"warn for initialization": {
|
||||
pcrs: map[uint32][]byte{
|
||||
|
|
@ -184,8 +184,8 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
9: zero,
|
||||
11: zero,
|
||||
},
|
||||
dontWarnInit: false,
|
||||
expectedWarnings: []string{"initialization"},
|
||||
dontWarnInit: false,
|
||||
wantWarnings: []string{"initialization"},
|
||||
},
|
||||
"don't warn for initialization": {
|
||||
pcrs: map[uint32][]byte{
|
||||
|
|
@ -203,7 +203,7 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
},
|
||||
"multi warning": {
|
||||
pcrs: map[uint32][]byte{},
|
||||
expectedWarnings: []string{
|
||||
wantWarnings: []string{
|
||||
"BIOS",
|
||||
"OPROM",
|
||||
"MBR",
|
||||
|
|
@ -216,7 +216,7 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
pcrs: map[uint32][]byte{
|
||||
0: []byte("000"),
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -231,14 +231,14 @@ func TestWarnAboutPCRs(t *testing.T) {
|
|||
cmd.SetErr(&errOut)
|
||||
|
||||
err := warnAboutPCRs(cmd, tc.pcrs, !tc.dontWarnInit)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
if len(tc.expectedWarnings) == 0 {
|
||||
if len(tc.wantWarnings) == 0 {
|
||||
assert.Empty(errOut.String())
|
||||
} else {
|
||||
for _, warning := range tc.expectedWarnings {
|
||||
for _, warning := range tc.wantWarnings {
|
||||
assert.Contains(errOut.String(), warning)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
|
||||
func TestIsIntArg(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
expectErr bool
|
||||
args []string
|
||||
wantErr bool
|
||||
}{
|
||||
"valid int 1": {[]string{"1"}, false},
|
||||
"valid int 2": {[]string{"42"}, false},
|
||||
|
|
@ -31,7 +31,7 @@ func TestIsIntArg(t *testing.T) {
|
|||
|
||||
err := testCmd.ValidateArgs(tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -42,8 +42,8 @@ func TestIsIntArg(t *testing.T) {
|
|||
|
||||
func TestIsIntGreaterArg(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
expectErr bool
|
||||
args []string
|
||||
wantErr bool
|
||||
}{
|
||||
"valid int 1": {[]string{"13"}, false},
|
||||
"valid int 2": {[]string{"42"}, false},
|
||||
|
|
@ -61,7 +61,7 @@ func TestIsIntGreaterArg(t *testing.T) {
|
|||
|
||||
err := testCmd.ValidateArgs(tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -72,8 +72,8 @@ func TestIsIntGreaterArg(t *testing.T) {
|
|||
|
||||
func TestIsIntGreaterZeroArg(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
expectErr bool
|
||||
args []string
|
||||
wantErr bool
|
||||
}{
|
||||
"valid int 1": {[]string{"13"}, false},
|
||||
"valid int 2": {[]string{"42"}, false},
|
||||
|
|
@ -91,7 +91,7 @@ func TestIsIntGreaterZeroArg(t *testing.T) {
|
|||
|
||||
err := testCmd.ValidateArgs(tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -102,8 +102,8 @@ func TestIsIntGreaterZeroArg(t *testing.T) {
|
|||
|
||||
func TestIsEC2InstanceType(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
expectErr bool
|
||||
args []string
|
||||
wantErr bool
|
||||
}{
|
||||
"is instance type 1": {[]string{"4xl"}, false},
|
||||
"is instance type 2": {[]string{"12xlarge", "something else"}, false},
|
||||
|
|
@ -119,7 +119,7 @@ func TestIsEC2InstanceType(t *testing.T) {
|
|||
|
||||
err := testCmd.ValidateArgs(tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -130,8 +130,8 @@ func TestIsEC2InstanceType(t *testing.T) {
|
|||
|
||||
func TestIsGCPInstanceType(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
expectErr bool
|
||||
args []string
|
||||
wantErr bool
|
||||
}{
|
||||
"is instance type 1": {[]string{"n2d-standard-4"}, false},
|
||||
"is instance type 2": {[]string{"n2d-standard-16", "something else"}, false},
|
||||
|
|
@ -147,7 +147,7 @@ func TestIsGCPInstanceType(t *testing.T) {
|
|||
|
||||
err := testCmd.ValidateArgs(tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -158,8 +158,8 @@ func TestIsGCPInstanceType(t *testing.T) {
|
|||
|
||||
func TestIsAzureInstanceType(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
expectErr bool
|
||||
args []string
|
||||
wantErr bool
|
||||
}{
|
||||
"is instance type 1": {[]string{"Standard_DC2as_v5"}, false},
|
||||
"is instance type 2": {[]string{"Standard_DC8as_v5", "something else"}, false},
|
||||
|
|
@ -175,7 +175,7 @@ func TestIsAzureInstanceType(t *testing.T) {
|
|||
|
||||
err := testCmd.ValidateArgs(tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -189,7 +189,7 @@ func TestIsInstanceTypeForProvider(t *testing.T) {
|
|||
typePos int
|
||||
providerPos int
|
||||
args []string
|
||||
expectErr bool
|
||||
wantErr bool
|
||||
}{
|
||||
"valid gcp type 1": {1, 0, []string{"gcp", "n2d-standard-4"}, false},
|
||||
"valid gcp type 2": {1, 0, []string{"gcp", "n2d-standard-16", "foo"}, false},
|
||||
|
|
@ -213,7 +213,7 @@ func TestIsInstanceTypeForProvider(t *testing.T) {
|
|||
|
||||
err := testCmd.ValidateArgs(tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
|||
|
|
@ -11,29 +11,29 @@ import (
|
|||
|
||||
func TestGetAzureValidator(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
ownerID string
|
||||
clusterID string
|
||||
errExpected bool
|
||||
ownerID string
|
||||
clusterID string
|
||||
wantErr bool
|
||||
}{
|
||||
"no input": {
|
||||
ownerID: "",
|
||||
clusterID: "",
|
||||
errExpected: true,
|
||||
ownerID: "",
|
||||
clusterID: "",
|
||||
wantErr: true,
|
||||
},
|
||||
"unencoded secret ID": {
|
||||
ownerID: "owner-id",
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
errExpected: true,
|
||||
ownerID: "owner-id",
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
wantErr: true,
|
||||
},
|
||||
"unencoded cluster ID": {
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: "unique-id",
|
||||
errExpected: true,
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: "unique-id",
|
||||
wantErr: true,
|
||||
},
|
||||
"correct input": {
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
errExpected: false,
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ func TestGetAzureValidator(t *testing.T) {
|
|||
0: []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"),
|
||||
1: []byte("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"),
|
||||
})
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
|||
|
|
@ -11,29 +11,29 @@ import (
|
|||
|
||||
func TestGetGCPNonCVMValidator(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
ownerID string
|
||||
clusterID string
|
||||
errExpected bool
|
||||
ownerID string
|
||||
clusterID string
|
||||
wantErr bool
|
||||
}{
|
||||
"no input": {
|
||||
ownerID: "",
|
||||
clusterID: "",
|
||||
errExpected: true,
|
||||
ownerID: "",
|
||||
clusterID: "",
|
||||
wantErr: true,
|
||||
},
|
||||
"unencoded secret ID": {
|
||||
ownerID: "owner-id",
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
errExpected: true,
|
||||
ownerID: "owner-id",
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
wantErr: true,
|
||||
},
|
||||
"unencoded cluster ID": {
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: "unique-id",
|
||||
errExpected: true,
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: "unique-id",
|
||||
wantErr: true,
|
||||
},
|
||||
"correct input": {
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
errExpected: false,
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ func TestGetGCPNonCVMValidator(t *testing.T) {
|
|||
cmd.SetErr(&errOut)
|
||||
|
||||
_, err := getGCPNonCVMValidator(cmd, map[uint32][]byte{})
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
|||
|
|
@ -11,29 +11,29 @@ import (
|
|||
|
||||
func TestGetGCPValidator(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
ownerID string
|
||||
clusterID string
|
||||
errExpected bool
|
||||
ownerID string
|
||||
clusterID string
|
||||
wantErr bool
|
||||
}{
|
||||
"no input": {
|
||||
ownerID: "",
|
||||
clusterID: "",
|
||||
errExpected: true,
|
||||
ownerID: "",
|
||||
clusterID: "",
|
||||
wantErr: true,
|
||||
},
|
||||
"unencoded secret ID": {
|
||||
ownerID: "owner-id",
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
errExpected: true,
|
||||
ownerID: "owner-id",
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
wantErr: true,
|
||||
},
|
||||
"unencoded cluster ID": {
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: "unique-id",
|
||||
errExpected: true,
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: "unique-id",
|
||||
wantErr: true,
|
||||
},
|
||||
"correct input": {
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
errExpected: false,
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ func TestGetGCPValidator(t *testing.T) {
|
|||
0: []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"),
|
||||
1: []byte("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"),
|
||||
})
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
|||
|
|
@ -23,40 +23,40 @@ import (
|
|||
|
||||
func TestVerify(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
connErr error
|
||||
checkErr error
|
||||
state state.State
|
||||
errExpected bool
|
||||
connErr error
|
||||
checkErr error
|
||||
state state.State
|
||||
wantErr bool
|
||||
}{
|
||||
"connection error": {
|
||||
connErr: errors.New("connection error"),
|
||||
checkErr: nil,
|
||||
state: 0,
|
||||
errExpected: true,
|
||||
connErr: errors.New("connection error"),
|
||||
checkErr: nil,
|
||||
state: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
"check error": {
|
||||
connErr: nil,
|
||||
checkErr: errors.New("check error"),
|
||||
state: 0,
|
||||
errExpected: true,
|
||||
connErr: nil,
|
||||
checkErr: errors.New("check error"),
|
||||
state: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
"check error, rpc status": {
|
||||
connErr: nil,
|
||||
checkErr: rpcStatus.Error(codes.Unavailable, "check error"),
|
||||
state: 0,
|
||||
errExpected: true,
|
||||
connErr: nil,
|
||||
checkErr: rpcStatus.Error(codes.Unavailable, "check error"),
|
||||
state: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
"verify on worker node": {
|
||||
connErr: nil,
|
||||
checkErr: nil,
|
||||
state: state.IsNode,
|
||||
errExpected: false,
|
||||
connErr: nil,
|
||||
checkErr: nil,
|
||||
state: state.IsNode,
|
||||
wantErr: false,
|
||||
},
|
||||
"verify on master node": {
|
||||
connErr: nil,
|
||||
checkErr: nil,
|
||||
state: state.ActivatingNodes,
|
||||
errExpected: false,
|
||||
connErr: nil,
|
||||
checkErr: nil,
|
||||
state: state.ActivatingNodes,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ func TestVerify(t *testing.T) {
|
|||
}
|
||||
err := verify(ctx, &out, "", []atls.Validator{gcp.NewValidator(pcrs)}, verifier)
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -130,29 +130,29 @@ func (c *stubPeerStatusClient) GetState(ctx context.Context, in *pubproto.GetSta
|
|||
|
||||
func TestPrepareValidator(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
ownerID string
|
||||
clusterID string
|
||||
errExpected bool
|
||||
ownerID string
|
||||
clusterID string
|
||||
wantErr bool
|
||||
}{
|
||||
"no input": {
|
||||
ownerID: "",
|
||||
clusterID: "",
|
||||
errExpected: true,
|
||||
ownerID: "",
|
||||
clusterID: "",
|
||||
wantErr: true,
|
||||
},
|
||||
"unencoded secret ID": {
|
||||
ownerID: "owner-id",
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
errExpected: true,
|
||||
ownerID: "owner-id",
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
wantErr: true,
|
||||
},
|
||||
"unencoded cluster ID": {
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: "unique-id",
|
||||
errExpected: true,
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: "unique-id",
|
||||
wantErr: true,
|
||||
},
|
||||
"correct input": {
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
errExpected: false,
|
||||
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
||||
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -177,7 +177,7 @@ func TestPrepareValidator(t *testing.T) {
|
|||
}
|
||||
|
||||
err := prepareValidator(cmd, pcrs)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -204,60 +204,60 @@ func TestAddOrSkipPcr(t *testing.T) {
|
|||
}
|
||||
|
||||
testCases := map[string]struct {
|
||||
pcrMap map[uint32][]byte
|
||||
pcrIndex uint32
|
||||
encoded string
|
||||
expectedEntries int
|
||||
errExpected bool
|
||||
pcrMap map[uint32][]byte
|
||||
pcrIndex uint32
|
||||
encoded string
|
||||
wantEntries int
|
||||
wantErr bool
|
||||
}{
|
||||
"empty input, empty map": {
|
||||
pcrMap: emptyMap,
|
||||
pcrIndex: 10,
|
||||
encoded: "",
|
||||
expectedEntries: 0,
|
||||
errExpected: false,
|
||||
pcrMap: emptyMap,
|
||||
pcrIndex: 10,
|
||||
encoded: "",
|
||||
wantEntries: 0,
|
||||
wantErr: false,
|
||||
},
|
||||
"empty input, default map": {
|
||||
pcrMap: defaultMap,
|
||||
pcrIndex: 10,
|
||||
encoded: "",
|
||||
expectedEntries: len(defaultMap),
|
||||
errExpected: false,
|
||||
pcrMap: defaultMap,
|
||||
pcrIndex: 10,
|
||||
encoded: "",
|
||||
wantEntries: len(defaultMap),
|
||||
wantErr: false,
|
||||
},
|
||||
"correct input, empty map": {
|
||||
pcrMap: emptyMap,
|
||||
pcrIndex: 10,
|
||||
encoded: base64.StdEncoding.EncodeToString([]byte("Constellation")),
|
||||
expectedEntries: 1,
|
||||
errExpected: false,
|
||||
pcrMap: emptyMap,
|
||||
pcrIndex: 10,
|
||||
encoded: base64.StdEncoding.EncodeToString([]byte("Constellation")),
|
||||
wantEntries: 1,
|
||||
wantErr: false,
|
||||
},
|
||||
"correct input, default map": {
|
||||
pcrMap: defaultMap,
|
||||
pcrIndex: 10,
|
||||
encoded: base64.StdEncoding.EncodeToString([]byte("Constellation")),
|
||||
expectedEntries: len(defaultMap) + 1,
|
||||
errExpected: false,
|
||||
pcrMap: defaultMap,
|
||||
pcrIndex: 10,
|
||||
encoded: base64.StdEncoding.EncodeToString([]byte("Constellation")),
|
||||
wantEntries: len(defaultMap) + 1,
|
||||
wantErr: false,
|
||||
},
|
||||
"unencoded input, empty map": {
|
||||
pcrMap: emptyMap,
|
||||
pcrIndex: 10,
|
||||
encoded: "Constellation",
|
||||
expectedEntries: 0,
|
||||
errExpected: true,
|
||||
pcrMap: emptyMap,
|
||||
pcrIndex: 10,
|
||||
encoded: "Constellation",
|
||||
wantEntries: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
"unencoded input, default map": {
|
||||
pcrMap: defaultMap,
|
||||
pcrIndex: 10,
|
||||
encoded: "Constellation",
|
||||
expectedEntries: len(defaultMap),
|
||||
errExpected: true,
|
||||
pcrMap: defaultMap,
|
||||
pcrIndex: 10,
|
||||
encoded: "Constellation",
|
||||
wantEntries: len(defaultMap),
|
||||
wantErr: true,
|
||||
},
|
||||
"empty input at occupied index": {
|
||||
pcrMap: defaultMap,
|
||||
pcrIndex: 0,
|
||||
encoded: "",
|
||||
expectedEntries: len(defaultMap) - 1,
|
||||
errExpected: false,
|
||||
pcrMap: defaultMap,
|
||||
pcrIndex: 0,
|
||||
encoded: "",
|
||||
wantEntries: len(defaultMap) - 1,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -272,12 +272,12 @@ func TestAddOrSkipPcr(t *testing.T) {
|
|||
|
||||
err := addOrSkipPCR(res, tc.pcrIndex, tc.encoded)
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
}
|
||||
assert.Len(res, tc.expectedEntries)
|
||||
assert.Len(res, tc.wantEntries)
|
||||
for _, v := range res {
|
||||
assert.Len(v, 32)
|
||||
}
|
||||
|
|
@ -287,28 +287,28 @@ func TestAddOrSkipPcr(t *testing.T) {
|
|||
|
||||
func TestVerifyCompletion(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
toComplete string
|
||||
resultExpected []string
|
||||
shellCDExpected cobra.ShellCompDirective
|
||||
args []string
|
||||
toComplete string
|
||||
wantResult []string
|
||||
wantShellCD cobra.ShellCompDirective
|
||||
}{
|
||||
"first arg": {
|
||||
args: []string{},
|
||||
toComplete: "192.0.2.1",
|
||||
resultExpected: []string{},
|
||||
shellCDExpected: cobra.ShellCompDirectiveNoFileComp,
|
||||
args: []string{},
|
||||
toComplete: "192.0.2.1",
|
||||
wantResult: []string{},
|
||||
wantShellCD: cobra.ShellCompDirectiveNoFileComp,
|
||||
},
|
||||
"second arg": {
|
||||
args: []string{"192.0.2.1"},
|
||||
toComplete: "443",
|
||||
resultExpected: []string{},
|
||||
shellCDExpected: cobra.ShellCompDirectiveNoFileComp,
|
||||
args: []string{"192.0.2.1"},
|
||||
toComplete: "443",
|
||||
wantResult: []string{},
|
||||
wantShellCD: cobra.ShellCompDirectiveNoFileComp,
|
||||
},
|
||||
"third arg": {
|
||||
args: []string{"192.0.2.1", "443"},
|
||||
toComplete: "./file",
|
||||
resultExpected: []string{},
|
||||
shellCDExpected: cobra.ShellCompDirectiveError,
|
||||
args: []string{"192.0.2.1", "443"},
|
||||
toComplete: "./file",
|
||||
wantResult: []string{},
|
||||
wantShellCD: cobra.ShellCompDirectiveError,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -318,8 +318,8 @@ func TestVerifyCompletion(t *testing.T) {
|
|||
|
||||
cmd := &cobra.Command{}
|
||||
result, shellCD := verifyCompletion(cmd, tc.args, tc.toComplete)
|
||||
assert.Equal(tc.resultExpected, result)
|
||||
assert.Equal(tc.shellCDExpected, shellCD)
|
||||
assert.Equal(tc.wantResult, result)
|
||||
assert.Equal(tc.wantShellCD, shellCD)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
api stubAPI
|
||||
instances ec2.Instances
|
||||
securityGroup string
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
wantInstances ec2.Instances
|
||||
}{
|
||||
"create": {
|
||||
|
|
@ -69,7 +69,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
api: stubAPI{instances: testInstances},
|
||||
instances: ec2.Instances{"id-1": {}, "id-4": {}, "id-5": {}},
|
||||
securityGroup: "sg-test",
|
||||
errExpected: false,
|
||||
wantErr: false,
|
||||
wantInstances: ec2.Instances{
|
||||
"id-1": {PublicIP: "192.0.2.1", PrivateIP: "192.0.2.2"},
|
||||
"id-2": {PublicIP: "192.0.2.3", PrivateIP: "192.0.2.4"},
|
||||
|
|
@ -79,23 +79,23 @@ func TestCreateInstances(t *testing.T) {
|
|||
},
|
||||
},
|
||||
"client has no security group": {
|
||||
api: stubAPI{},
|
||||
errExpected: true,
|
||||
api: stubAPI{},
|
||||
wantErr: true,
|
||||
},
|
||||
"run API error": {
|
||||
api: stubAPI{runInstancesErr: someErr},
|
||||
securityGroup: "sg-test",
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"runDryRun API error": {
|
||||
api: stubAPI{runInstancesDryRunErr: &someErr},
|
||||
securityGroup: "sg-test",
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"runDryRun missing expected API error": {
|
||||
api: stubAPI{runInstancesDryRunErr: &noErr},
|
||||
securityGroup: "sg-test",
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ func TestCreateInstances(t *testing.T) {
|
|||
|
||||
err := client.CreateInstances(context.Background(), input)
|
||||
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -142,32 +142,32 @@ func TestTerminateInstances(t *testing.T) {
|
|||
var noErr error
|
||||
|
||||
testCases := map[string]struct {
|
||||
api stubAPI
|
||||
instances ec2.Instances
|
||||
errExpected bool
|
||||
api stubAPI
|
||||
instances ec2.Instances
|
||||
wantErr bool
|
||||
}{
|
||||
"client with instances": {
|
||||
api: stubAPI{instances: testAWSInstances},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: false,
|
||||
api: stubAPI{instances: testAWSInstances},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: false,
|
||||
},
|
||||
"client no instances set": {
|
||||
api: stubAPI{},
|
||||
},
|
||||
"terminate API error": {
|
||||
api: stubAPI{terminateInstancesErr: someErr},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
api: stubAPI{terminateInstancesErr: someErr},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
"terminateDryRun API error": {
|
||||
api: stubAPI{terminateInstancesDryRunErr: &someErr},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
api: stubAPI{terminateInstancesDryRunErr: &someErr},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
"terminateDryRun miss expected API error": {
|
||||
api: stubAPI{terminateInstancesDryRunErr: &noErr},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
api: stubAPI{terminateInstancesDryRunErr: &noErr},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -185,7 +185,7 @@ func TestTerminateInstances(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.TerminateInstances(context.Background())
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -197,9 +197,9 @@ func TestTerminateInstances(t *testing.T) {
|
|||
|
||||
func TestWaitStateRunning(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
api api
|
||||
instances ec2.Instances
|
||||
errExpected bool
|
||||
api api
|
||||
instances ec2.Instances
|
||||
wantErr bool
|
||||
}{
|
||||
"instances are running": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -216,8 +216,8 @@ func TestWaitStateRunning(t *testing.T) {
|
|||
State: &stateRunning,
|
||||
},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: false,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: false,
|
||||
},
|
||||
"one instance running, rest nil": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -228,8 +228,8 @@ func TestWaitStateRunning(t *testing.T) {
|
|||
{InstanceId: aws.String("id-2")},
|
||||
{InstanceId: aws.String("id-3")},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: false,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: false,
|
||||
},
|
||||
"one instance terminated, rest nil": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -240,8 +240,8 @@ func TestWaitStateRunning(t *testing.T) {
|
|||
{InstanceId: aws.String("id-2")},
|
||||
{InstanceId: aws.String("id-3")},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
"instances with different state": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -255,8 +255,8 @@ func TestWaitStateRunning(t *testing.T) {
|
|||
},
|
||||
{InstanceId: aws.String("id-3")},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
"all instances have nil state": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -264,12 +264,12 @@ func TestWaitStateRunning(t *testing.T) {
|
|||
{InstanceId: aws.String("id-2")},
|
||||
{InstanceId: aws.String("id-3")},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
"client has no instances": {
|
||||
api: &stubAPI{},
|
||||
errExpected: true,
|
||||
api: &stubAPI{},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ func TestWaitStateRunning(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.waitStateRunning(context.Background())
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -297,9 +297,9 @@ func TestWaitStateRunning(t *testing.T) {
|
|||
|
||||
func TestWaitStateTerminated(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
api api
|
||||
instances ec2.Instances
|
||||
errExpected bool
|
||||
api api
|
||||
instances ec2.Instances
|
||||
wantErr bool
|
||||
}{
|
||||
"instances are terminated": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -316,8 +316,8 @@ func TestWaitStateTerminated(t *testing.T) {
|
|||
State: &stateTerminated,
|
||||
},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: false,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: false,
|
||||
},
|
||||
"one instance terminated, rest nil": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -328,8 +328,8 @@ func TestWaitStateTerminated(t *testing.T) {
|
|||
{InstanceId: aws.String("id-2")},
|
||||
{InstanceId: aws.String("id-3")},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: false,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: false,
|
||||
},
|
||||
"one instance running, rest nil": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -340,8 +340,8 @@ func TestWaitStateTerminated(t *testing.T) {
|
|||
{InstanceId: aws.String("id-2")},
|
||||
{InstanceId: aws.String("id-3")},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
"instances with different state": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -355,8 +355,8 @@ func TestWaitStateTerminated(t *testing.T) {
|
|||
},
|
||||
{InstanceId: aws.String("id-3")},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
"all instances have nil state": {
|
||||
api: stubAPI{instances: []types.Instance{
|
||||
|
|
@ -364,12 +364,12 @@ func TestWaitStateTerminated(t *testing.T) {
|
|||
{InstanceId: aws.String("id-2")},
|
||||
{InstanceId: aws.String("id-3")},
|
||||
}},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
"client has no instances": {
|
||||
api: &stubAPI{},
|
||||
errExpected: true,
|
||||
api: &stubAPI{},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -387,7 +387,7 @@ func TestWaitStateTerminated(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.waitStateTerminated(context.Background())
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -403,23 +403,23 @@ func TestTagInstances(t *testing.T) {
|
|||
}
|
||||
|
||||
testCases := map[string]struct {
|
||||
api stubAPI
|
||||
instances ec2.Instances
|
||||
errExpected bool
|
||||
api stubAPI
|
||||
instances ec2.Instances
|
||||
wantErr bool
|
||||
}{
|
||||
"tag": {
|
||||
api: stubAPI{},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: false,
|
||||
api: stubAPI{},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: false,
|
||||
},
|
||||
"client without instances": {
|
||||
api: stubAPI{createTagsErr: errors.New("failed")},
|
||||
errExpected: true,
|
||||
api: stubAPI{createTagsErr: errors.New("failed")},
|
||||
wantErr: true,
|
||||
},
|
||||
"tag API error": {
|
||||
api: stubAPI{createTagsErr: errors.New("failed")},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
errExpected: true,
|
||||
api: stubAPI{createTagsErr: errors.New("failed")},
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
|
|
@ -436,7 +436,7 @@ func TestTagInstances(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.tagInstances(context.Background(), testTags)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -449,8 +449,8 @@ func TestEc2RunInstanceInput(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
|
||||
testCases := []struct {
|
||||
in CreateInput
|
||||
outExpected awsec2.RunInstancesInput
|
||||
in CreateInput
|
||||
wantOutput awsec2.RunInstancesInput
|
||||
}{
|
||||
{
|
||||
in: CreateInput{
|
||||
|
|
@ -459,7 +459,7 @@ func TestEc2RunInstanceInput(t *testing.T) {
|
|||
Count: 13,
|
||||
securityGroupIds: []string{"test-sec-group"},
|
||||
},
|
||||
outExpected: awsec2.RunInstancesInput{
|
||||
wantOutput: awsec2.RunInstancesInput{
|
||||
ImageId: aws.String("test-image"),
|
||||
InstanceType: types.InstanceTypeC5a4xlarge,
|
||||
MinCount: aws.Int32(int32(13)),
|
||||
|
|
@ -475,7 +475,7 @@ func TestEc2RunInstanceInput(t *testing.T) {
|
|||
Count: 2,
|
||||
securityGroupIds: []string{"test-sec-group-2"},
|
||||
},
|
||||
outExpected: awsec2.RunInstancesInput{
|
||||
wantOutput: awsec2.RunInstancesInput{
|
||||
ImageId: aws.String("test-image-2"),
|
||||
InstanceType: types.InstanceTypeC5a12xlarge,
|
||||
MinCount: aws.Int32(int32(2)),
|
||||
|
|
@ -488,6 +488,6 @@ func TestEc2RunInstanceInput(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
out := tc.in.AWS()
|
||||
assert.Equal(tc.outExpected, *out)
|
||||
assert.Equal(tc.wantOutput, *out)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,55 +41,55 @@ func TestCreateSecurityGroup(t *testing.T) {
|
|||
var noErr error
|
||||
|
||||
testCases := map[string]struct {
|
||||
api stubAPI
|
||||
securityGroup string
|
||||
input SecurityGroupInput
|
||||
errExpected bool
|
||||
securityGroupExpected string
|
||||
api stubAPI
|
||||
securityGroup string
|
||||
input SecurityGroupInput
|
||||
wantErr bool
|
||||
wantSecurityGroup string
|
||||
}{
|
||||
"create security group": {
|
||||
api: stubAPI{securityGroup: types.SecurityGroup{GroupId: aws.String("sg-test")}},
|
||||
input: testInput,
|
||||
securityGroupExpected: "sg-test",
|
||||
api: stubAPI{securityGroup: types.SecurityGroup{GroupId: aws.String("sg-test")}},
|
||||
input: testInput,
|
||||
wantSecurityGroup: "sg-test",
|
||||
},
|
||||
"create security group without permissions": {
|
||||
api: stubAPI{securityGroup: types.SecurityGroup{GroupId: aws.String("sg-test")}},
|
||||
input: SecurityGroupInput{},
|
||||
securityGroupExpected: "sg-test",
|
||||
api: stubAPI{securityGroup: types.SecurityGroup{GroupId: aws.String("sg-test")}},
|
||||
input: SecurityGroupInput{},
|
||||
wantSecurityGroup: "sg-test",
|
||||
},
|
||||
"client already has security group": {
|
||||
api: stubAPI{},
|
||||
securityGroup: "sg-test",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"create returns nil security group ID": {
|
||||
api: stubAPI{securityGroup: types.SecurityGroup{GroupId: nil}},
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
api: stubAPI{securityGroup: types.SecurityGroup{GroupId: nil}},
|
||||
input: testInput,
|
||||
wantErr: true,
|
||||
},
|
||||
"create API error": {
|
||||
api: stubAPI{createSecurityGroupErr: someErr},
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
api: stubAPI{createSecurityGroupErr: someErr},
|
||||
input: testInput,
|
||||
wantErr: true,
|
||||
},
|
||||
"create DryRun API error": {
|
||||
api: stubAPI{createSecurityGroupDryRunErr: &someErr},
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
api: stubAPI{createSecurityGroupDryRunErr: &someErr},
|
||||
input: testInput,
|
||||
wantErr: true,
|
||||
},
|
||||
"create DryRun missing expected error": {
|
||||
api: stubAPI{createSecurityGroupDryRunErr: &noErr},
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
api: stubAPI{createSecurityGroupDryRunErr: &noErr},
|
||||
input: testInput,
|
||||
wantErr: true,
|
||||
},
|
||||
"authorize error": {
|
||||
api: stubAPI{
|
||||
securityGroup: types.SecurityGroup{GroupId: aws.String("sg-test")},
|
||||
authorizeSecurityGroupIngressErr: someErr,
|
||||
},
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
input: testInput,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -103,11 +103,11 @@ func TestCreateSecurityGroup(t *testing.T) {
|
|||
client.securityGroup = tc.securityGroup
|
||||
|
||||
err = client.CreateSecurityGroup(context.Background(), tc.input)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
assert.Equal(tc.securityGroupExpected, client.securityGroup)
|
||||
assert.Equal(tc.wantSecurityGroup, client.securityGroup)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ func TestDeleteSecurityGroup(t *testing.T) {
|
|||
testCases := map[string]struct {
|
||||
api stubAPI
|
||||
securityGroup string
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"delete security group": {
|
||||
api: stubAPI{},
|
||||
|
|
@ -132,17 +132,17 @@ func TestDeleteSecurityGroup(t *testing.T) {
|
|||
"delete API error": {
|
||||
api: stubAPI{deleteSecurityGroupErr: someErr},
|
||||
securityGroup: "sg-test",
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"delete DryRun API error": {
|
||||
api: stubAPI{deleteSecurityGroupDryRunErr: &someErr},
|
||||
securityGroup: "sg-test",
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"delete DryRun missing expected error": {
|
||||
api: stubAPI{deleteSecurityGroupDryRunErr: &noErr},
|
||||
securityGroup: "sg-test",
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ func TestDeleteSecurityGroup(t *testing.T) {
|
|||
client.securityGroup = tc.securityGroup
|
||||
|
||||
err = client.DeleteSecurityGroup(context.Background())
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
@ -198,54 +198,54 @@ func TestAuthorizeSecurityGroup(t *testing.T) {
|
|||
api stubAPI
|
||||
securityGroup string
|
||||
input SecurityGroupInput
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"authorize": {
|
||||
api: stubAPI{},
|
||||
securityGroup: "sg-test",
|
||||
input: testInput,
|
||||
errExpected: false,
|
||||
wantErr: false,
|
||||
},
|
||||
"client without security group": {
|
||||
api: stubAPI{},
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
api: stubAPI{},
|
||||
input: testInput,
|
||||
wantErr: true,
|
||||
},
|
||||
"authorizeIngress API error": {
|
||||
api: stubAPI{authorizeSecurityGroupIngressErr: someErr},
|
||||
securityGroup: "sg-test",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"authorizeIngress DryRun API error": {
|
||||
api: stubAPI{authorizeSecurityGroupIngressDryRunErr: &someErr},
|
||||
securityGroup: "sg-test",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"authorizeIngress DryRun missing expected error": {
|
||||
api: stubAPI{authorizeSecurityGroupIngressDryRunErr: &noErr},
|
||||
securityGroup: "sg-test",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"authorizeEgress API error": {
|
||||
api: stubAPI{authorizeSecurityGroupEgressErr: someErr},
|
||||
securityGroup: "sg-test",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"authorizeEgress DryRun API error": {
|
||||
api: stubAPI{authorizeSecurityGroupEgressDryRunErr: &someErr},
|
||||
securityGroup: "sg-test",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"authorizeEgress DryRun missing expected error": {
|
||||
api: stubAPI{authorizeSecurityGroupEgressDryRunErr: &noErr},
|
||||
securityGroup: "sg-test",
|
||||
input: testInput,
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -259,7 +259,7 @@ func TestAuthorizeSecurityGroup(t *testing.T) {
|
|||
client.securityGroup = tc.securityGroup
|
||||
|
||||
err = client.authorizeSecurityGroup(context.Background(), tc.input)
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func TestTagsAws(t *testing.T) {
|
|||
Value: "Bar",
|
||||
},
|
||||
}
|
||||
expected := []types.Tag{
|
||||
wantTags := []types.Tag{
|
||||
{
|
||||
Key: aws.String("Name"),
|
||||
Value: aws.String("Test"),
|
||||
|
|
@ -33,5 +33,5 @@ func TestTagsAws(t *testing.T) {
|
|||
}
|
||||
|
||||
awsTags := testTags.AWS()
|
||||
assert.Equal(expected, awsTags)
|
||||
assert.Equal(wantTags, awsTags)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,42 +73,42 @@ func TestActivate(t *testing.T) {
|
|||
avpn *stubAVPNClient
|
||||
userPublicKey string
|
||||
ips []string
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"normal activation": {
|
||||
avpn: &stubAVPNClient{},
|
||||
userPublicKey: testKey,
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: false,
|
||||
wantErr: false,
|
||||
},
|
||||
"client without avpn": {
|
||||
userPublicKey: testKey,
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"empty public key parameter": {
|
||||
avpn: &stubAVPNClient{},
|
||||
userPublicKey: "",
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid public key parameter": {
|
||||
avpn: &stubAVPNClient{},
|
||||
userPublicKey: "invalid Key",
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"empty ips parameter": {
|
||||
avpn: &stubAVPNClient{},
|
||||
userPublicKey: testKey,
|
||||
ips: []string{},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"fail ActivateAsCoordinator": {
|
||||
avpn: &stubAVPNClient{activateAsCoordinatorErr: someErr},
|
||||
userPublicKey: testKey,
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ func TestActivate(t *testing.T) {
|
|||
client.avpn = tc.avpn
|
||||
}
|
||||
_, err := client.Activate(context.Background(), []byte(tc.userPublicKey), []byte("Constellation"), tc.ips, nil, nil, "serviceaccount://test")
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
|||
|
|
@ -89,32 +89,32 @@ func TestNextLog(t *testing.T) {
|
|||
someErr := errors.New("failed")
|
||||
|
||||
testCases := map[string]struct {
|
||||
msgs []*pubproto.ActivateAsCoordinatorResponse
|
||||
logLenExpected int
|
||||
stateExpected bool
|
||||
recvErr error
|
||||
errExpected bool
|
||||
msgs []*pubproto.ActivateAsCoordinatorResponse
|
||||
wantLogLen int
|
||||
wantState bool
|
||||
recvErr error
|
||||
wantErr bool
|
||||
}{
|
||||
"some logs": {
|
||||
msgs: []*pubproto.ActivateAsCoordinatorResponse{testLogResp, testLogResp, testLogResp},
|
||||
logLenExpected: 3,
|
||||
msgs: []*pubproto.ActivateAsCoordinatorResponse{testLogResp, testLogResp, testLogResp},
|
||||
wantLogLen: 3,
|
||||
},
|
||||
"only admin config": {
|
||||
msgs: []*pubproto.ActivateAsCoordinatorResponse{testConfigResp},
|
||||
stateExpected: true,
|
||||
msgs: []*pubproto.ActivateAsCoordinatorResponse{testConfigResp},
|
||||
wantState: true,
|
||||
},
|
||||
"logs and configs": {
|
||||
msgs: []*pubproto.ActivateAsCoordinatorResponse{testLogResp, testConfigResp, testLogResp, testConfigResp},
|
||||
logLenExpected: 2,
|
||||
stateExpected: true,
|
||||
msgs: []*pubproto.ActivateAsCoordinatorResponse{testLogResp, testConfigResp, testLogResp, testConfigResp},
|
||||
wantLogLen: 2,
|
||||
wantState: true,
|
||||
},
|
||||
"no response": {
|
||||
msgs: []*pubproto.ActivateAsCoordinatorResponse{},
|
||||
logLenExpected: 0,
|
||||
msgs: []*pubproto.ActivateAsCoordinatorResponse{},
|
||||
wantLogLen: 0,
|
||||
},
|
||||
"recv fail": {
|
||||
recvErr: someErr,
|
||||
errExpected: true,
|
||||
recvErr: someErr,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -141,15 +141,15 @@ func TestNextLog(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Error(err)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.NotErrorIs(err, io.EOF)
|
||||
return
|
||||
}
|
||||
|
||||
assert.ErrorIs(err, io.EOF)
|
||||
assert.Len(logs, tc.logLenExpected)
|
||||
assert.Len(logs, tc.wantLogLen)
|
||||
|
||||
if tc.stateExpected {
|
||||
if tc.wantState {
|
||||
ip, err := client.GetClientVpnIp()
|
||||
assert.NoError(err)
|
||||
assert.Equal(testClientVpnIp, ip)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue