Skip to content

Commit

Permalink
Add unit tests for updating endpoints
Browse files Browse the repository at this point in the history
* Added test for UpdateEndpoints
* Added test for UpdateEndpointsMergeableIngress
  • Loading branch information
Dean-Coakley committed Aug 24, 2018
1 parent fe6bf81 commit 6051d2b
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion nginx-controller/nginx/configurator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 6051d2b

Please sign in to comment.