Skip to content

Commit

Permalink
updated k8s tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaezon committed Jan 12, 2022
1 parent 036d915 commit a825384
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (

"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
nginx "github.com/nginxinc/kubernetes-ingress/pkg/apis/configuration/v1"
k8s_nginx "github.com/nginxinc/kubernetes-ingress/pkg/client/clientset/versioned"
k8s_nginx_fake "github.com/nginxinc/kubernetes-ingress/pkg/client/clientset/versioned/fake"
core "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -15,12 +18,15 @@ import (

func TestController(t *testing.T) {
client := fake.NewSimpleClientset()
nginxClient := k8s_nginx_fake.NewSimpleClientset()
ctrl := &KubeController{
client: client,
hasSynced: true,
client: client,
nginxClient: nginxClient,
hasSynced: true,
}
addServices(client)
addIngresses(client)
addVirtualServers(nginxClient)

gw := newGateway()
gw.Zones = []string{"example.com."}
Expand All @@ -41,6 +47,13 @@ func TestController(t *testing.T) {
}
}

for index, testObj := range testVirtualServers {
found, _ := virtualServerHostnameIndexFunc(testObj)
if !isFound(index, found) {
t.Errorf("VirtualServer ksy %s not found in index: %v", index, found)
}
}

for index, testObj := range testBadServices {
found, _ := serviceHostnameIndexFunc(testObj)
if isFound(index, found) {
Expand Down Expand Up @@ -79,6 +92,16 @@ func addIngresses(client kubernetes.Interface) {
}
}

func addVirtualServers(client k8s_nginx.Interface) {
ctx := context.TODO()
for _, virtualServer := range testVirtualServers {
_, err := client.K8sV1().VirtualServers("ns1").Create(ctx, virtualServer, meta.CreateOptions{})
if err != nil {
log.Warningf("Failed to Create VirtualServer Objects :%s", err)
}
}
}

var testIngresses = map[string]*networking.Ingress{
"a.example.org": {
ObjectMeta: meta.ObjectMeta{
Expand Down Expand Up @@ -172,6 +195,23 @@ var testServices = map[string]*core.Service{
},
}

var testVirtualServers = map[string]*nginx.VirtualServer{
"vs1.example.org": {
ObjectMeta: meta.ObjectMeta{
Name: "vs1",
Namespace: "ns1",
},
Spec: nginx.VirtualServerSpec{
Host: "vs1.example.org",
},
Status: nginx.VirtualServerStatus{
ExternalEndpoints: []nginx.ExternalEndpoint{
{IP: "192.0.0.1"},
},
},
},
}

var testBadServices = map[string]*core.Service{
"svc1.ns2": {
ObjectMeta: meta.ObjectMeta{
Expand Down

0 comments on commit a825384

Please sign in to comment.