Skip to content

Commit

Permalink
Updating Kubernetes tests to properly test missing endpoints code path
Browse files Browse the repository at this point in the history
This fixes #1307
  • Loading branch information
Regner Blok-Andersen authored and ldez committed Apr 28, 2017
1 parent 9ed55e9 commit d24ba90
Showing 1 changed file with 10 additions and 71 deletions.
81 changes: 10 additions & 71 deletions provider/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,6 @@ func TestLoadIngresses(t *testing.T) {
},
"bar": {
Servers: map[string]types.Server{
"2": {
URL: "http://10.0.0.2:802",
Weight: 1,
},
"https://10.15.0.1:8443": {
URL: "https://10.15.0.1:8443",
Weight: 1,
Expand Down Expand Up @@ -498,12 +494,7 @@ func TestGetPassHostHeader(t *testing.T) {
expected := &types.Configuration{
Backends: map[string]*types.Backend{
"foo/bar": {
Servers: map[string]types.Server{
"1": {
URL: "http://10.0.0.1:801",
Weight: 1,
},
},
Servers: map[string]types.Server{},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{
Sticky: false,
Expand Down Expand Up @@ -610,12 +601,7 @@ func TestOnlyReferencesServicesFromOwnNamespace(t *testing.T) {
expected := &types.Configuration{
Backends: map[string]*types.Backend{
"foo": {
Servers: map[string]types.Server{
"1": {
URL: "http://10.0.0.1:80",
Weight: 1,
},
},
Servers: map[string]types.Server{},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{
Sticky: false,
Expand Down Expand Up @@ -799,29 +785,15 @@ func TestLoadNamespacedIngresses(t *testing.T) {
expected := &types.Configuration{
Backends: map[string]*types.Backend{
"foo/bar": {
Servers: map[string]types.Server{
"1": {
URL: "http://10.0.0.1:801",
Weight: 1,
},
},
Servers: map[string]types.Server{},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{
Sticky: false,
Method: "wrr",
},
},
"bar": {
Servers: map[string]types.Server{
"2": {
URL: "http://10.0.0.2:802",
Weight: 1,
},
"3": {
URL: "https://10.0.0.3:443",
Weight: 1,
},
},
Servers: map[string]types.Server{},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{
Sticky: false,
Expand Down Expand Up @@ -1043,42 +1015,23 @@ func TestLoadMultipleNamespacedIngresses(t *testing.T) {
expected := &types.Configuration{
Backends: map[string]*types.Backend{
"foo/bar": {
Servers: map[string]types.Server{
"1": {
URL: "http://10.0.0.1:801",
Weight: 1,
},
},
Servers: map[string]types.Server{},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{
Sticky: false,
Method: "wrr",
},
},
"bar": {
Servers: map[string]types.Server{
"2": {
URL: "http://10.0.0.2:802",
Weight: 1,
},
"3": {
URL: "https://10.0.0.3:443",
Weight: 1,
},
},
Servers: map[string]types.Server{},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{
Sticky: false,
Method: "wrr",
},
},
"awesome/quix": {
Servers: map[string]types.Server{
"17": {
URL: "http://10.0.0.4:801",
Weight: 1,
},
},
Servers: map[string]types.Server{},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{
Sticky: false,
Expand Down Expand Up @@ -1190,12 +1143,7 @@ func TestHostlessIngress(t *testing.T) {
expected := &types.Configuration{
Backends: map[string]*types.Backend{
"/bar": {
Servers: map[string]types.Server{
"1": {
URL: "http://10.0.0.1:801",
Weight: 1,
},
},
Servers: map[string]types.Server{},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{
Sticky: false,
Expand Down Expand Up @@ -2016,11 +1964,8 @@ func TestMissingResources(t *testing.T) {
services: services,
endpoints: endpoints,
watchChan: watchChan,

// TODO: Update all tests to cope with "properExists == true" correctly and remove flag.
// See https://github.com/containous/traefik/issues/1307
properExists: true,
}

provider := Provider{}
actual, err := provider.loadIngresses(client)
if err != nil {
Expand Down Expand Up @@ -2093,8 +2038,6 @@ type clientMock struct {

apiServiceError error
apiEndpointsError error

properExists bool
}

func (c clientMock) GetIngresses(namespaces Namespaces) []*v1beta1.Ingress {
Expand Down Expand Up @@ -2132,11 +2075,7 @@ func (c clientMock) GetEndpoints(namespace, name string) (*v1.Endpoints, bool, e
}
}

if c.properExists {
return nil, false, nil
}

return &v1.Endpoints{}, true, nil
return &v1.Endpoints{}, false, nil
}

func (c clientMock) WatchAll(labelString string, stopCh <-chan struct{}) (<-chan interface{}, error) {
Expand Down

0 comments on commit d24ba90

Please sign in to comment.