Skip to content

Commit

Permalink
internal/featuretests: add simple HTTPProxy fixtures (projectcontour#…
Browse files Browse the repository at this point in the history
…2519)

Add some simple helpers to generate HTTPProxy test fixtures. This
helps reduce some boilerplate in setting up test cases.

Signed-off-by: James Peach <jpeach@vmware.com>
  • Loading branch information
jpeach authored May 20, 2020
1 parent f4d0d23 commit bec00c2
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 244 deletions.
13 changes: 5 additions & 8 deletions internal/featuretests/downstreamvalidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/projectcontour/contour/internal/contour"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/envoy"
"github.com/projectcontour/contour/internal/fixture"
"github.com/projectcontour/contour/internal/k8s"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -68,12 +69,8 @@ func TestDownstreamTLSCertificateValidation(t *testing.T) {
}
rh.OnAdd(service)

proxy := &projcontour.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "example.com",
Namespace: "default",
},
Spec: projcontour.HTTPProxySpec{
proxy := fixture.NewProxy("example.com").
WithSpec(projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{
Fqdn: "example.com",
TLS: &projcontour.TLS{
Expand All @@ -89,8 +86,8 @@ func TestDownstreamTLSCertificateValidation(t *testing.T) {
Port: 8080,
}},
}},
},
}
})

rh.OnAdd(proxy)

ingress_http := &v2.Listener{
Expand Down
29 changes: 11 additions & 18 deletions internal/featuretests/externalname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
envoy_api_v2_route "github.com/envoyproxy/go-control-plane/envoy/api/v2/route"
projcontour "github.com/projectcontour/contour/apis/projectcontour/v1"
"github.com/projectcontour/contour/internal/envoy"
"github.com/projectcontour/contour/internal/fixture"
v1 "k8s.io/api/core/v1"
"k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -86,21 +87,17 @@ func TestExternalNameService(t *testing.T) {

rh.OnDelete(i1)

hp1 := &projcontour.HTTPProxy{
ObjectMeta: i1.ObjectMeta,
Spec: projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{
Fqdn: "kuard.projectcontour.io",
},
rh.OnAdd(fixture.NewProxy("kuard").
WithFQDN("kuard.projectcontour.io").
WithSpec(projcontour.HTTPProxySpec{
Routes: []projcontour.Route{{
Services: []projcontour.Service{{
Name: s1.Name,
Port: 80,
}},
}},
},
}
rh.OnAdd(hp1)
}),
)

c.Request(routeType).Equals(&v2.DiscoveryResponse{
Resources: resources(t,
Expand All @@ -123,12 +120,9 @@ func TestExternalNameService(t *testing.T) {
TypeUrl: clusterType,
})

hp2 := &projcontour.HTTPProxy{
ObjectMeta: i1.ObjectMeta,
Spec: projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{
Fqdn: "kuard.projectcontour.io",
},
rh.OnAdd(fixture.NewProxy("kuard").
WithFQDN("kuard.projectcontour.io").
WithSpec(projcontour.HTTPProxySpec{
Routes: []projcontour.Route{{
Services: []projcontour.Service{{
Name: s1.Name,
Expand All @@ -141,9 +135,8 @@ func TestExternalNameService(t *testing.T) {
}},
},
}},
},
}
rh.OnAdd(hp2)
}),
)

c.Request(routeType).Equals(&v2.DiscoveryResponse{
Resources: resources(t,
Expand Down
45 changes: 13 additions & 32 deletions internal/featuretests/headercondition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
projcontour "github.com/projectcontour/contour/apis/projectcontour/v1"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/envoy"
"github.com/projectcontour/contour/internal/fixture"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -138,12 +139,8 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) {
TypeUrl: routeType,
})

proxy2 := &projcontour.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: projcontour.HTTPProxySpec{
proxy2 := fixture.NewProxy("simple").WithSpec(
projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{Fqdn: "hello.world"},
Routes: []projcontour.Route{{
Services: []projcontour.Service{{
Expand All @@ -169,8 +166,7 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) {
Port: 80,
}},
}},
},
}
})

rh.OnUpdate(proxy1, proxy2)

Expand Down Expand Up @@ -206,12 +202,8 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) {
TypeUrl: routeType,
})

proxy3 := &projcontour.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: projcontour.HTTPProxySpec{
proxy3 := fixture.NewProxy("simple").WithSpec(
projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{Fqdn: "hello.world"},
Routes: []projcontour.Route{{
Services: []projcontour.Service{{
Expand All @@ -237,8 +229,7 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) {
Port: 80,
}},
}},
},
}
})

rh.OnUpdate(proxy2, proxy3)

Expand Down Expand Up @@ -274,12 +265,8 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) {
TypeUrl: routeType,
})

proxy4 := &projcontour.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: projcontour.HTTPProxySpec{
proxy4 := fixture.NewProxy("simple").WithSpec(
projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{Fqdn: "hello.world"},
Routes: []projcontour.Route{{
Services: []projcontour.Service{{
Expand All @@ -305,8 +292,7 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) {
Port: 80,
}},
}},
},
}
})

rh.OnUpdate(proxy3, proxy4)

Expand Down Expand Up @@ -342,12 +328,8 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) {
TypeUrl: routeType,
})

proxy5 := &projcontour.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: projcontour.HTTPProxySpec{
proxy5 := fixture.NewProxy("simple").WithSpec(
projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{Fqdn: "hello.world"},
Routes: []projcontour.Route{{
Services: []projcontour.Service{{
Expand All @@ -373,8 +355,7 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) {
Port: 80,
}},
}},
},
}
})

rh.OnUpdate(proxy4, proxy5)

Expand Down
49 changes: 17 additions & 32 deletions internal/featuretests/headerpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
envoy_api_v2_route "github.com/envoyproxy/go-control-plane/envoy/api/v2/route"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/projectcontour/contour/internal/envoy"
"github.com/projectcontour/contour/internal/fixture"
v1 "k8s.io/api/core/v1"

"testing"
Expand Down Expand Up @@ -46,12 +47,8 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) {
},
})

rh.OnAdd(&projcontour.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: projcontour.HTTPProxySpec{
rh.OnAdd(fixture.NewProxy("simple").WithSpec(
projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{Fqdn: "hello.world"},
Routes: []projcontour.Route{{
Services: []projcontour.Service{{
Expand All @@ -65,8 +62,8 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) {
}},
},
}},
},
})
}),
)

c.Request(routeType).Equals(&v2.DiscoveryResponse{
Resources: resources(t,
Expand All @@ -83,12 +80,8 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) {
})

// Non-Host header
rh.OnAdd(&projcontour.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: projcontour.HTTPProxySpec{
rh.OnAdd(fixture.NewProxy("simple").WithSpec(
projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{Fqdn: "hello.world"},
Routes: []projcontour.Route{{
Services: []projcontour.Service{{
Expand All @@ -102,8 +95,8 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) {
}},
},
}},
},
})
}),
)

c.Request(routeType).Equals(&v2.DiscoveryResponse{
Resources: resources(t,
Expand All @@ -129,12 +122,8 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) {
})

// Empty value for replaceHeader in HeadersPolicy
rh.OnAdd(&projcontour.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: projcontour.HTTPProxySpec{
rh.OnAdd(fixture.NewProxy("simple").WithSpec(
projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{Fqdn: "hello.world"},
Routes: []projcontour.Route{{
Services: []projcontour.Service{{
Expand All @@ -147,8 +136,8 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) {
}},
},
}},
},
})
}),
)

c.Request(routeType).Equals(&v2.DiscoveryResponse{
Resources: resources(t,
Expand Down Expand Up @@ -193,12 +182,8 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) {
})

// Proxy with SNI
rh.OnAdd(&projcontour.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: projcontour.HTTPProxySpec{
rh.OnAdd(fixture.NewProxy("simple").WithSpec(
projcontour.HTTPProxySpec{
VirtualHost: &projcontour.VirtualHost{
Fqdn: "hello.world",
TLS: &projcontour.TLS{SecretName: "foo"},
Expand All @@ -215,8 +200,8 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) {
}},
},
}},
},
})
}),
)

c.Request(routeType).Equals(&v2.DiscoveryResponse{
Resources: routeResources(t,
Expand Down
Loading

0 comments on commit bec00c2

Please sign in to comment.