2022-03-22 11:03:15 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-06-07 05:08:44 -04:00
|
|
|
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
2022-06-08 02:17:52 -04:00
|
|
|
"github.com/edgelesssys/constellation/internal/cloud/cloudtypes"
|
2022-03-22 11:03:15 -04:00
|
|
|
"github.com/edgelesssys/constellation/internal/state"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-06-30 09:24:36 -04:00
|
|
|
"go.uber.org/goleak"
|
2022-03-22 11:03:15 -04:00
|
|
|
)
|
|
|
|
|
2022-06-30 09:24:36 -04:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(m)
|
|
|
|
}
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
func TestSetGetState(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
state state.ConstellationState
|
|
|
|
wantErr bool
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"valid state": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
"missing workers": {
|
2022-03-22 11:03:15 -04:00
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
"missing controlplane": {
|
2022-03-22 11:03:15 -04:00
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"missing name": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"missing uid": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"missing bootstrapper host": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
|
|
|
AzureWorkers: cloudtypes.Instances{
|
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"missing resource group": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"missing location": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"missing subscription": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"missing tenant": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"missing subnet": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"missing network security group": {
|
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
"missing worker scale set": {
|
2022-03-29 07:30:50 -04:00
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-29 07:30:50 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-29 07:30:50 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-29 07:30:50 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-29 07:30:50 -04:00
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
"missing controlplane scale set": {
|
2022-03-29 07:30:50 -04:00
|
|
|
state: state.ConstellationState{
|
|
|
|
CloudProvider: cloudprovider.Azure.String(),
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-29 07:30:50 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-29 07:30:50 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
2022-07-08 04:59:59 -04:00
|
|
|
BootstrapperHost: "bootstrapper-host",
|
2022-03-29 07:30:50 -04:00
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureTenant: "tenant",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
2022-03-29 07:30:50 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-29 07:30:50 -04:00
|
|
|
},
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("SetState", func(t *testing.T) {
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
client := Client{}
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(client.SetState(tc.state))
|
|
|
|
} else {
|
|
|
|
assert.NoError(client.SetState(tc.state))
|
2022-06-29 09:26:29 -04:00
|
|
|
assert.Equal(tc.state.AzureWorkers, client.workers)
|
|
|
|
assert.Equal(tc.state.AzureControlPlane, client.controlPlanes)
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Equal(tc.state.Name, client.name)
|
|
|
|
assert.Equal(tc.state.UID, client.uid)
|
|
|
|
assert.Equal(tc.state.AzureResourceGroup, client.resourceGroup)
|
|
|
|
assert.Equal(tc.state.AzureLocation, client.location)
|
|
|
|
assert.Equal(tc.state.AzureSubscription, client.subscriptionID)
|
|
|
|
assert.Equal(tc.state.AzureTenant, client.tenantID)
|
|
|
|
assert.Equal(tc.state.AzureSubnet, client.subnetID)
|
|
|
|
assert.Equal(tc.state.AzureNetworkSecurityGroup, client.networkSecurityGroup)
|
2022-06-29 09:26:29 -04:00
|
|
|
assert.Equal(tc.state.AzureWorkersScaleSet, client.workerScaleSet)
|
|
|
|
assert.Equal(tc.state.AzureControlPlanesScaleSet, client.controlPlaneScaleSet)
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetState", func(t *testing.T) {
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
client := Client{
|
2022-06-29 09:26:29 -04:00
|
|
|
workers: tc.state.AzureWorkers,
|
|
|
|
controlPlanes: tc.state.AzureControlPlane,
|
2022-03-22 11:03:15 -04:00
|
|
|
name: tc.state.Name,
|
|
|
|
uid: tc.state.UID,
|
2022-07-08 04:59:59 -04:00
|
|
|
loadBalancerPubIP: tc.state.BootstrapperHost,
|
2022-03-22 11:03:15 -04:00
|
|
|
resourceGroup: tc.state.AzureResourceGroup,
|
|
|
|
location: tc.state.AzureLocation,
|
|
|
|
subscriptionID: tc.state.AzureSubscription,
|
|
|
|
tenantID: tc.state.AzureTenant,
|
|
|
|
subnetID: tc.state.AzureSubnet,
|
|
|
|
networkSecurityGroup: tc.state.AzureNetworkSecurityGroup,
|
2022-06-29 09:26:29 -04:00
|
|
|
workerScaleSet: tc.state.AzureWorkersScaleSet,
|
|
|
|
controlPlaneScaleSet: tc.state.AzureControlPlanesScaleSet,
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
_, err := client.GetState()
|
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
state, err := client.GetState()
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(tc.state, state)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetStateCloudProvider(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
client := Client{}
|
|
|
|
stateMissingCloudProvider := state.ConstellationState{
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
assert.Error(client.SetState(stateMissingCloudProvider))
|
|
|
|
stateIncorrectCloudProvider := state.ConstellationState{
|
|
|
|
CloudProvider: "incorrect",
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureWorkers: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip1",
|
|
|
|
PrivateIP: "ip2",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
AzureControlPlane: cloudtypes.Instances{
|
2022-03-22 11:03:15 -04:00
|
|
|
"0": {
|
|
|
|
PublicIP: "ip3",
|
|
|
|
PrivateIP: "ip4",
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 09:26:29 -04:00
|
|
|
Name: "name",
|
|
|
|
UID: "uid",
|
|
|
|
AzureResourceGroup: "resource-group",
|
|
|
|
AzureLocation: "location",
|
|
|
|
AzureSubscription: "subscription",
|
|
|
|
AzureSubnet: "azure-subnet",
|
|
|
|
AzureNetworkSecurityGroup: "network-security-group",
|
|
|
|
AzureWorkersScaleSet: "worker-scale-set",
|
|
|
|
AzureControlPlanesScaleSet: "controlplane-scale-set",
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
assert.Error(client.SetState(stateIncorrectCloudProvider))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInit(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
client := Client{}
|
|
|
|
require.NoError(client.init("location", "name"))
|
|
|
|
assert.Equal("location", client.location)
|
|
|
|
assert.Equal("name", client.name)
|
|
|
|
assert.NotEmpty(client.uid)
|
|
|
|
}
|