This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 558
Unit tests #3344
Merged
Merged
Unit tests #3344
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fb520bc
add root command test
3339bfb
remove flag test
311a4d7
wip
946cb1f
wip tls writer tests
dd4d62e
go fmt
60629ba
fix test imports
3f9924e
add cases
7cf7f3e
fix typo
8213fd6
fix upgrade test
fb14a11
add certs
298bd61
fix all locations kubeconfig test
2b3a0a1
move mock container function out
5630613
go fmt
88c543c
add completion cmd
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func TestNewRootCmd(t *testing.T) { | ||
output := NewRootCmd() | ||
if output.Use != rootName || output.Short != rootShortDescription || output.Long != rootLongDescription { | ||
t.Fatalf("root command should have use %s equal %s, short %s equal %s and long %s equal to %s", output.Use, rootName, output.Short, rootShortDescription, output.Long, rootLongDescription) | ||
} | ||
expectedCommands := []*cobra.Command{getCompletionCmd(output), newDcosUpgradeCmd(), newDeployCmd(), newGenerateCmd(), newOrchestratorsCmd(), newScaleCmd(), newUpgradeCmd(), newVersionCmd()} | ||
rc := output.Commands() | ||
for i, c := range expectedCommands { | ||
if rc[i].Use != c.Use { | ||
t.Fatalf("root command should have command %s", c.Use) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,13 @@ import ( | |
|
||
"github.com/Azure/acs-engine/pkg/api" | ||
"github.com/Azure/acs-engine/pkg/helpers" | ||
"github.com/satori/go.uuid" | ||
) | ||
|
||
const defaultTestClusterVer = "1.7.12" | ||
|
||
func TestAPIServerConfigEnableDataEncryptionAtRest(t *testing.T) { | ||
// Test EnableDataEncryptionAtRest = true | ||
cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs := CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableDataEncryptionAtRest = helpers.PointerToBool(true) | ||
setAPIServerConfig(cs) | ||
a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -22,7 +21,7 @@ func TestAPIServerConfigEnableDataEncryptionAtRest(t *testing.T) { | |
} | ||
|
||
// Test EnableDataEncryptionAtRest = false | ||
cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs = CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableDataEncryptionAtRest = helpers.PointerToBool(false) | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -34,7 +33,7 @@ func TestAPIServerConfigEnableDataEncryptionAtRest(t *testing.T) { | |
|
||
func TestAPIServerConfigEnableEncryptionWithExternalKms(t *testing.T) { | ||
// Test EnableEncryptionWithExternalKms = true | ||
cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs := CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableEncryptionWithExternalKms = helpers.PointerToBool(true) | ||
setAPIServerConfig(cs) | ||
a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -44,7 +43,7 @@ func TestAPIServerConfigEnableEncryptionWithExternalKms(t *testing.T) { | |
} | ||
|
||
// Test EnableEncryptionWithExternalKms = false | ||
cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs = CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableEncryptionWithExternalKms = helpers.PointerToBool(false) | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -56,7 +55,7 @@ func TestAPIServerConfigEnableEncryptionWithExternalKms(t *testing.T) { | |
|
||
func TestAPIServerConfigEnableAggregatedAPIs(t *testing.T) { | ||
// Test EnableAggregatedAPIs = true | ||
cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs := CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableAggregatedAPIs = true | ||
setAPIServerConfig(cs) | ||
a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -90,7 +89,7 @@ func TestAPIServerConfigEnableAggregatedAPIs(t *testing.T) { | |
} | ||
|
||
// Test EnableAggregatedAPIs = false | ||
cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs = CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableAggregatedAPIs = false | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -106,7 +105,7 @@ func TestAPIServerConfigEnableAggregatedAPIs(t *testing.T) { | |
|
||
func TestAPIServerConfigUseCloudControllerManager(t *testing.T) { | ||
// Test UseCloudControllerManager = true | ||
cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs := CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = helpers.PointerToBool(true) | ||
setAPIServerConfig(cs) | ||
a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -120,7 +119,7 @@ func TestAPIServerConfigUseCloudControllerManager(t *testing.T) { | |
} | ||
|
||
// Test UseCloudControllerManager = false | ||
cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs = CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = helpers.PointerToBool(false) | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -136,7 +135,7 @@ func TestAPIServerConfigUseCloudControllerManager(t *testing.T) { | |
|
||
func TestAPIServerConfigHasAadProfile(t *testing.T) { | ||
// Test HasAadProfile = true | ||
cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs := CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.AADProfile = &api.AADProfile{ | ||
ServerAppID: "test-id", | ||
TenantID: "test-tenant", | ||
|
@@ -161,7 +160,7 @@ func TestAPIServerConfigHasAadProfile(t *testing.T) { | |
} | ||
|
||
// Test OIDC user overrides | ||
cs = createContainerService("testcluster", "1.7.12", 3, 2) | ||
cs = CreateMockContainerService("testcluster", "1.7.12", 3, 2, false) | ||
cs.Properties.AADProfile = &api.AADProfile{ | ||
ServerAppID: "test-id", | ||
TenantID: "test-tenant", | ||
|
@@ -196,7 +195,7 @@ func TestAPIServerConfigHasAadProfile(t *testing.T) { | |
} | ||
|
||
// Test China Cloud settings | ||
cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs = CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.AADProfile = &api.AADProfile{ | ||
ServerAppID: "test-id", | ||
TenantID: "test-tenant", | ||
|
@@ -234,7 +233,7 @@ func TestAPIServerConfigHasAadProfile(t *testing.T) { | |
} | ||
|
||
// Test HasAadProfile = false | ||
cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs = CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
for _, key := range []string{"--oidc-username-claim", "--oidc-groups-claim", "--oidc-client-id", "--oidc-issuer-url"} { | ||
|
@@ -247,7 +246,7 @@ func TestAPIServerConfigHasAadProfile(t *testing.T) { | |
|
||
func TestAPIServerConfigEnableRbac(t *testing.T) { | ||
// Test EnableRbac = true | ||
cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs := CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(true) | ||
setAPIServerConfig(cs) | ||
a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -257,7 +256,7 @@ func TestAPIServerConfigEnableRbac(t *testing.T) { | |
} | ||
|
||
// Test EnableRbac = true with 1.6 cluster | ||
cs = createContainerService("testcluster", "1.6.11", 3, 2) | ||
cs = CreateMockContainerService("testcluster", "1.6.11", 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(true) | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -267,7 +266,7 @@ func TestAPIServerConfigEnableRbac(t *testing.T) { | |
} | ||
|
||
// Test EnableRbac = false | ||
cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs = CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(false) | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -277,7 +276,7 @@ func TestAPIServerConfigEnableRbac(t *testing.T) { | |
} | ||
|
||
// Test EnableRbac = false with 1.6 cluster | ||
cs = createContainerService("testcluster", "1.6.11", 3, 2) | ||
cs = CreateMockContainerService("testcluster", "1.6.11", 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(false) | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -289,7 +288,7 @@ func TestAPIServerConfigEnableRbac(t *testing.T) { | |
|
||
func TestAPIServerConfigEnableSecureKubelet(t *testing.T) { | ||
// Test EnableSecureKubelet = true | ||
cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs := CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = helpers.PointerToBool(true) | ||
setAPIServerConfig(cs) | ||
a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -303,7 +302,7 @@ func TestAPIServerConfigEnableSecureKubelet(t *testing.T) { | |
} | ||
|
||
// Test EnableSecureKubelet = false | ||
cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) | ||
cs = CreateMockContainerService("testcluster", defaultTestClusterVer, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = helpers.PointerToBool(false) | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
@@ -320,7 +319,7 @@ func TestAPIServerConfigDefaultAdmissionControls(t *testing.T) { | |
version := "1.10.0" | ||
enableAdmissionPluginsKey := "--enable-admission-plugins" | ||
admissonControlKey := "--admission-control" | ||
cs := createContainerService("testcluster", version, 3, 2) | ||
cs := CreateMockContainerService("testcluster", version, 3, 2, false) | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig = map[string]string{} | ||
cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig[admissonControlKey] = "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota,DenyEscalatingExec,AlwaysPullImages,ExtendedResourceToleration" | ||
setAPIServerConfig(cs) | ||
|
@@ -338,7 +337,7 @@ func TestAPIServerConfigDefaultAdmissionControls(t *testing.T) { | |
|
||
// Test --admission-control for v1.9 and below | ||
version = "1.9.0" | ||
cs = createContainerService("testcluster", version, 3, 2) | ||
cs = CreateMockContainerService("testcluster", version, 3, 2, false) | ||
setAPIServerConfig(cs) | ||
a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig | ||
|
||
|
@@ -352,71 +351,3 @@ func TestAPIServerConfigDefaultAdmissionControls(t *testing.T) { | |
t.Fatalf("Admission control key '%s' not set in API server config for version %s", enableAdmissionPluginsKey, version) | ||
} | ||
} | ||
|
||
func createContainerService(containerServiceName string, orchestratorVersion string, masterCount int, agentCount int) *api.ContainerService { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactored in common place, function was duplicated |
||
cs := api.ContainerService{} | ||
cs.ID = uuid.NewV4().String() | ||
cs.Location = "eastus" | ||
cs.Name = containerServiceName | ||
|
||
cs.Properties = &api.Properties{} | ||
|
||
cs.Properties.MasterProfile = &api.MasterProfile{} | ||
cs.Properties.MasterProfile.Count = masterCount | ||
cs.Properties.MasterProfile.DNSPrefix = "testmaster" | ||
cs.Properties.MasterProfile.VMSize = "Standard_D2_v2" | ||
|
||
cs.Properties.AgentPoolProfiles = []*api.AgentPoolProfile{} | ||
agentPool := &api.AgentPoolProfile{} | ||
agentPool.Count = agentCount | ||
agentPool.Name = "agentpool1" | ||
agentPool.VMSize = "Standard_D2_v2" | ||
agentPool.OSType = "Linux" | ||
agentPool.AvailabilityProfile = "AvailabilitySet" | ||
agentPool.StorageProfile = "StorageAccount" | ||
|
||
cs.Properties.AgentPoolProfiles = append(cs.Properties.AgentPoolProfiles, agentPool) | ||
|
||
cs.Properties.LinuxProfile = &api.LinuxProfile{ | ||
AdminUsername: "azureuser", | ||
SSH: struct { | ||
PublicKeys []api.PublicKey `json:"publicKeys"` | ||
}{}, | ||
} | ||
|
||
cs.Properties.LinuxProfile.AdminUsername = "azureuser" | ||
cs.Properties.LinuxProfile.SSH.PublicKeys = append( | ||
cs.Properties.LinuxProfile.SSH.PublicKeys, api.PublicKey{KeyData: "test"}) | ||
|
||
cs.Properties.ServicePrincipalProfile = &api.ServicePrincipalProfile{} | ||
cs.Properties.ServicePrincipalProfile.ClientID = "DEC923E3-1EF1-4745-9516-37906D56DEC4" | ||
cs.Properties.ServicePrincipalProfile.Secret = "DEC923E3-1EF1-4745-9516-37906D56DEC4" | ||
|
||
cs.Properties.OrchestratorProfile = &api.OrchestratorProfile{} | ||
cs.Properties.OrchestratorProfile.OrchestratorType = api.Kubernetes | ||
cs.Properties.OrchestratorProfile.OrchestratorVersion = orchestratorVersion | ||
cs.Properties.OrchestratorProfile.KubernetesConfig = &api.KubernetesConfig{ | ||
EnableSecureKubelet: helpers.PointerToBool(api.DefaultSecureKubeletEnabled), | ||
EnableRbac: helpers.PointerToBool(api.DefaultRBACEnabled), | ||
EtcdDiskSizeGB: DefaultEtcdDiskSize, | ||
ServiceCIDR: DefaultKubernetesServiceCIDR, | ||
DockerBridgeSubnet: DefaultDockerBridgeSubnet, | ||
DNSServiceIP: DefaultKubernetesDNSServiceIP, | ||
GCLowThreshold: DefaultKubernetesGCLowThreshold, | ||
GCHighThreshold: DefaultKubernetesGCHighThreshold, | ||
MaxPods: DefaultKubernetesMaxPodsVNETIntegrated, | ||
ClusterSubnet: DefaultKubernetesSubnet, | ||
ContainerRuntime: DefaultContainerRuntime, | ||
NetworkPlugin: DefaultNetworkPlugin, | ||
NetworkPolicy: DefaultNetworkPolicy, | ||
EtcdVersion: DefaultEtcdVersion, | ||
KubeletConfig: make(map[string]string), | ||
} | ||
|
||
cs.Properties.CertificateProfile = &api.CertificateProfile{} | ||
cs.Properties.CertificateProfile.CaCertificate = "cacert" | ||
cs.Properties.CertificateProfile.KubeConfigCertificate = "kubeconfigcert" | ||
cs.Properties.CertificateProfile.KubeConfigPrivateKey = "kubeconfigkey" | ||
|
||
return &cs | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this to a function, fyi @stuartleeks @jackfrancis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool :-)