From 6051d2bee11b53d75f0782638114f735f85ab5f9 Mon Sep 17 00:00:00 2001 From: dean-coakley Date: Thu, 23 Aug 2018 16:25:18 +0100 Subject: [PATCH] Add unit tests for updating endpoints * Added test for UpdateEndpoints * Added test for UpdateEndpointsMergeableIngress --- nginx-controller/nginx/configurator_test.go | 68 ++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/nginx-controller/nginx/configurator_test.go b/nginx-controller/nginx/configurator_test.go index 997362b47e..fbb8732d6e 100644 --- a/nginx-controller/nginx/configurator_test.go +++ b/nginx-controller/nginx/configurator_test.go @@ -707,6 +707,72 @@ func TestAddOrUpdateMergableIngressFailsWithInvalidIngressTemplate(t *testing.T) mergeableIngess := createMergeableCafeIngress() err = cnf.AddOrUpdateMergableIngress(mergeableIngess) if err == nil { - t.Errorf("AddOrUpdateMergableIngress returned \n%v, expected \n%v", nil, "template execution error") + t.Errorf("AddOrUpdateMergableIngress returned \n%v, but expected \n%v", nil, "template execution error") + } +} + +func TestUpdateEndpoints(t *testing.T) { + cnf, err := createTestConfigurator() + if err != nil { + t.Errorf("Failed to create a test configurator: %v", err) + } + + ingress := createCafeIngressEx() + err = cnf.UpdateEndpoints(&ingress) + if err != nil { + t.Errorf("UpdateEndpoints returned\n%v, but expected \n%v", err, nil) + } + + // test with OSS Configurator + cnf.nginxAPI = nil + err = cnf.UpdateEndpoints(&ingress) + if err != nil { + t.Errorf("UpdateEndpoints returned\n%v, but expected \n%v", err, nil) + } +} + +func TestUpdateEndpointsMergeableIngress(t *testing.T) { + cnf, err := createTestConfigurator() + if err != nil { + t.Errorf("Failed to create a test configurator: %v", err) + } + + mergeableIngress := createMergeableCafeIngress() + err = cnf.UpdateEndpointsMergeableIngress(mergeableIngress) + if err != nil { + t.Errorf("UpdateEndpointsMergeableIngress returned \n%v, but expected \n%v", err, nil) + } + + // test with OSS Configurator + cnf.nginxAPI = nil + err = cnf.UpdateEndpointsMergeableIngress(mergeableIngress) + if err != nil { + t.Errorf("UpdateEndpointsMergeableIngress returned \n%v, but expected \n%v", err, nil) + } +} + +func TestUpdateEndpointsFailsWithInvalidTemplate(t *testing.T) { + cnf, err := createTestConfiguratorInvalidIngressTemplate() + if err != nil { + t.Errorf("Failed to create a test configurator: %v", err) + } + + ingress := createCafeIngressEx() + err = cnf.UpdateEndpoints(&ingress) + if err == nil { + t.Errorf("UpdateEndpoints returned\n%v, but expected \n%v", nil, "template execution error") + } +} + +func TestUpdateEndpointsMergeableIngressFailsWithInvalidTemplate(t *testing.T) { + cnf, err := createTestConfiguratorInvalidIngressTemplate() + if err != nil { + t.Errorf("Failed to create a test configurator: %v", err) + } + + mergeableIngress := createMergeableCafeIngress() + err = cnf.UpdateEndpointsMergeableIngress(mergeableIngress) + if err == nil { + t.Errorf("UpdateEndpointsMergeableIngress returned \n%v, but expected \n%v", nil, "template execution error") } }