Add unit tests
This commit is contained in:
committed by
Robbie Zhang
parent
844d8a71d0
commit
df90c71875
@@ -602,7 +602,7 @@ func (p *ACIProvider) getDNSConfig(dnsPolicy v1.DNSPolicy, dnsConfig *v1.PodDNSC
|
|||||||
}
|
}
|
||||||
|
|
||||||
result := aci.DNSConfig{
|
result := aci.DNSConfig{
|
||||||
NameServers: formDNSNameserversFitsLimits(nameServers),
|
NameServers: formDNSNameserversFitsLimits(nameServers),
|
||||||
SearchDomains: formDNSSearchFitsLimits(searchDomains),
|
SearchDomains: formDNSSearchFitsLimits(searchDomains),
|
||||||
Options: strings.Join(options, " "),
|
Options: strings.Join(options, " "),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package aci
|
package aci
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -14,7 +15,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
client *Client
|
client *Client
|
||||||
location = "westcentralus"
|
location = "westus"
|
||||||
resourceGroup = "virtual-kubelet-tests"
|
resourceGroup = "virtual-kubelet-tests"
|
||||||
containerGroup = "virtual-kubelet-test-container-group"
|
containerGroup = "virtual-kubelet-test-container-group"
|
||||||
subscriptionID string
|
subscriptionID string
|
||||||
@@ -272,8 +273,8 @@ func TestListContainerGroup(t *testing.T) {
|
|||||||
|
|
||||||
func TestCreateContainerGroupWithLivenessProbe(t *testing.T) {
|
func TestCreateContainerGroupWithLivenessProbe(t *testing.T) {
|
||||||
uid := uuid.New()
|
uid := uuid.New()
|
||||||
congainerGroupName := containerGroup + "-" + uid.String()[0:6]
|
containerGroupName := containerGroup + "-" + uid.String()[0:6]
|
||||||
cg, err := client.CreateContainerGroup(resourceGroup, congainerGroupName, ContainerGroup{
|
cg, err := client.CreateContainerGroup(resourceGroup, containerGroupName, ContainerGroup{
|
||||||
Location: location,
|
Location: location,
|
||||||
ContainerGroupProperties: ContainerGroupProperties{
|
ContainerGroupProperties: ContainerGroupProperties{
|
||||||
OsType: Linux,
|
OsType: Linux,
|
||||||
@@ -312,15 +313,15 @@ func TestCreateContainerGroupWithLivenessProbe(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if cg.Name != congainerGroupName {
|
if cg.Name != containerGroupName {
|
||||||
t.Fatalf("resource group name is %s, expected %s", cg.Name, congainerGroupName)
|
t.Fatalf("resource group name is %s, expected %s", cg.Name, containerGroupName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateContainerGroupFailsWithLivenessProbeMissingPort(t *testing.T) {
|
func TestCreateContainerGroupFailsWithLivenessProbeMissingPort(t *testing.T) {
|
||||||
uid := uuid.New()
|
uid := uuid.New()
|
||||||
congainerGroupName := containerGroup + "-" + uid.String()[0:6]
|
containerGroupName := containerGroup + "-" + uid.String()[0:6]
|
||||||
_, err := client.CreateContainerGroup(resourceGroup, congainerGroupName, ContainerGroup{
|
_, err := client.CreateContainerGroup(resourceGroup, containerGroupName, ContainerGroup{
|
||||||
Location: location,
|
Location: location,
|
||||||
ContainerGroupProperties: ContainerGroupProperties{
|
ContainerGroupProperties: ContainerGroupProperties{
|
||||||
OsType: Linux,
|
OsType: Linux,
|
||||||
@@ -363,8 +364,8 @@ func TestCreateContainerGroupFailsWithLivenessProbeMissingPort(t *testing.T) {
|
|||||||
|
|
||||||
func TestCreateContainerGroupWithReadinessProbe(t *testing.T) {
|
func TestCreateContainerGroupWithReadinessProbe(t *testing.T) {
|
||||||
uid := uuid.New()
|
uid := uuid.New()
|
||||||
congainerGroupName := containerGroup + "-" + uid.String()[0:6]
|
containerGroupName := containerGroup + "-" + uid.String()[0:6]
|
||||||
cg, err := client.CreateContainerGroup(resourceGroup, congainerGroupName, ContainerGroup{
|
cg, err := client.CreateContainerGroup(resourceGroup, containerGroupName, ContainerGroup{
|
||||||
Location: location,
|
Location: location,
|
||||||
ContainerGroupProperties: ContainerGroupProperties{
|
ContainerGroupProperties: ContainerGroupProperties{
|
||||||
OsType: Linux,
|
OsType: Linux,
|
||||||
@@ -408,8 +409,8 @@ func TestCreateContainerGroupWithReadinessProbe(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if cg.Name != congainerGroupName {
|
if cg.Name != containerGroupName {
|
||||||
t.Fatalf("resource group name is %s, expected %s", cg.Name, congainerGroupName)
|
t.Fatalf("resource group name is %s, expected %s", cg.Name, containerGroupName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,6 +504,84 @@ func TestCreateContainerGroupWithInvalidLogAnalytics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateContainerGroupWithVNet(t *testing.T) {
|
||||||
|
uid := uuid.New()
|
||||||
|
containerGroupName := containerGroup + "-" + uid.String()[0:6]
|
||||||
|
fakeKubeConfig := base64.StdEncoding.EncodeToString([]byte(uid.String()))
|
||||||
|
networkProfileId := "/subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/aci-connector/providers/Microsoft.Network/networkprofiles/aci-connector-network-profile-westus"
|
||||||
|
diagnostics, err := NewContainerGroupDiagnosticsFromFile("../../../../loganalytics.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
diagnostics.LogAnalytics.LogType = LogAnlyticsLogTypeContainerInsights
|
||||||
|
|
||||||
|
cg, err := client.CreateContainerGroup(resourceGroup, containerGroupName, ContainerGroup{
|
||||||
|
Location: location,
|
||||||
|
ContainerGroupProperties: ContainerGroupProperties{
|
||||||
|
OsType: Linux,
|
||||||
|
Containers: []Container{
|
||||||
|
{
|
||||||
|
Name: "nginx",
|
||||||
|
ContainerProperties: ContainerProperties{
|
||||||
|
Image: "nginx",
|
||||||
|
Command: []string{"nginx", "-g", "daemon off;"},
|
||||||
|
Ports: []ContainerPort{
|
||||||
|
{
|
||||||
|
Protocol: ContainerNetworkProtocolTCP,
|
||||||
|
Port: 80,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Resources: ResourceRequirements{
|
||||||
|
Requests: &ResourceRequests{
|
||||||
|
CPU: 1,
|
||||||
|
MemoryInGB: 1,
|
||||||
|
},
|
||||||
|
Limits: &ResourceLimits{
|
||||||
|
CPU: 1,
|
||||||
|
MemoryInGB: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NetworkProfile: &NetworkProfileDefinition{
|
||||||
|
ID: networkProfileId,
|
||||||
|
},
|
||||||
|
Extensions: []*Extension{
|
||||||
|
&Extension{
|
||||||
|
Name: "kube-proxy",
|
||||||
|
Properties: &ExtensionProperties{
|
||||||
|
Type: ExtensionTypeKubeProxy,
|
||||||
|
Version: ExtensionVersion1_0,
|
||||||
|
Settings: map[string]string{
|
||||||
|
KubeProxyExtensionSettingClusterCIDR: "10.240.0.0/16",
|
||||||
|
KubeProxyExtensionSettingKubeVersion: KubeProxyExtensionKubeVersion,
|
||||||
|
},
|
||||||
|
ProtectedSettings: map[string]string{
|
||||||
|
KubeProxyExtensionSettingKubeConfig: fakeKubeConfig,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DNSConfig: &DNSConfig{
|
||||||
|
NameServers: []string{"1.1.1.1"},
|
||||||
|
},
|
||||||
|
Diagnostics: diagnostics,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if cg.Name != containerGroupName {
|
||||||
|
t.Fatalf("resource group name is %s, expected %s", cg.Name, containerGroupName)
|
||||||
|
}
|
||||||
|
if err := client.DeleteContainerGroup(resourceGroup, containerGroupName); err != nil {
|
||||||
|
t.Fatalf("Delete Container Group failed: %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDeleteContainerGroup(t *testing.T) {
|
func TestDeleteContainerGroup(t *testing.T) {
|
||||||
err := client.DeleteContainerGroup(resourceGroup, containerGroup)
|
err := client.DeleteContainerGroup(resourceGroup, containerGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user