Skip to content
This repository has been archived by the owner on Sep 19, 2018. It is now read-only.

Commit

Permalink
fix and extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alkar committed Nov 24, 2017
1 parent c88790d commit 1065300
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
30 changes: 30 additions & 0 deletions ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,36 @@ var (
},
}

privateIngressHostE2 = &v1beta1.Ingress{
ObjectMeta: v1.ObjectMeta{
Name: "ingressHostE2",
Namespace: v1.NamespaceDefault,
Labels: map[string]string{
testTargetLabelName: testPrivateTarget,
},
},
Spec: v1beta1.IngressSpec{
Rules: []v1beta1.IngressRule{
{Host: "e.example.com"},
},
},
}

privateIngressHostE2Fixed = &v1beta1.Ingress{
ObjectMeta: v1.ObjectMeta{
Name: "ingressHostE2",
Namespace: v1.NamespaceDefault,
Labels: map[string]string{
testTargetLabelName: testPrivateTarget,
},
},
Spec: v1beta1.IngressSpec{
Rules: []v1beta1.IngressRule{
{Host: "e2.example.com"},
},
},
}

ingressNoLabels = &v1beta1.Ingress{
ObjectMeta: v1.ObjectMeta{
Name: "ingressNoLabels",
Expand Down
49 changes: 46 additions & 3 deletions registrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ type mockEvent struct {
new *v1beta1.Ingress
}

type mockStore struct {
items []interface{}
}

func (m *mockStore) Add(obj interface{}) error { return nil }
func (m *mockStore) Update(obj interface{}) error { return nil }
func (m *mockStore) Delete(obj interface{}) error { return nil }
func (m *mockStore) List() []interface{} { return m.items }
func (m *mockStore) ListKeys() []string { return nil }
func (m *mockStore) Get(obj interface{}) (item interface{}, exists bool, err error) {
return nil, false, nil
}
func (m *mockStore) GetByKey(key string) (item interface{}, exists bool, err error) {
return nil, false, nil
}
func (m *mockStore) Replace([]interface{}, string) error { return nil }
func (m *mockStore) Resync() error { return nil }

func TestRegistratorHandler(t *testing.T) {
privateSelector, _ := labels.Parse(fmt.Sprintf("%s=%s", testTargetLabelName, testPrivateTarget))
publicSelector, _ := labels.Parse(fmt.Sprintf("%s=%s", testTargetLabelName, testPublicTarget))
Expand All @@ -183,6 +201,7 @@ func TestRegistratorHandler(t *testing.T) {
updateQueue: make(chan cnameChange, 16),
ingressWatcher: &ingressWatcher{
stopChannel: make(chan struct{}),
store: &mockStore{},
},
options: registratorOptions{
Targets: []string{testPrivateTarget, testPublicTarget},
Expand All @@ -192,14 +211,16 @@ func TestRegistratorHandler(t *testing.T) {
}

testCases := []struct {
domain string
events []mockEvent
data map[string]string
domain string
events []mockEvent
data map[string]string
storeIngresses []interface{}
}{
{
"",
[]mockEvent{},
map[string]string{},
nil,
},
{
"example.com.",
Expand All @@ -210,6 +231,7 @@ func TestRegistratorHandler(t *testing.T) {
"a.example.com": testPrivateTarget,
"b.example.com": testPrivateTarget,
},
nil,
},
{
"example.com.",
Expand All @@ -218,6 +240,7 @@ func TestRegistratorHandler(t *testing.T) {
{watch.Deleted, privateIngressHostsAB, nil},
},
map[string]string{},
nil,
},
{
"example.com.",
Expand All @@ -228,6 +251,7 @@ func TestRegistratorHandler(t *testing.T) {
map[string]string{
"c.example.com": testPublicTarget,
},
nil,
},
{
"example.com.",
Expand All @@ -239,13 +263,15 @@ func TestRegistratorHandler(t *testing.T) {
map[string]string{
"c.example.com": testPublicTarget,
},
nil,
},
{
"an.example.com.",
[]mockEvent{
{watch.Added, nil, privateIngressHostsAB},
},
map[string]string{},
nil,
},
{
"example.com.",
Expand All @@ -255,6 +281,7 @@ func TestRegistratorHandler(t *testing.T) {
map[string]string{
"e.example.com": testPrivateTarget,
},
nil,
},
{
"example.com.",
Expand All @@ -265,6 +292,7 @@ func TestRegistratorHandler(t *testing.T) {
map[string]string{
"e.example.com": testPrivateTarget,
},
nil,
},
{
"example.com.",
Expand All @@ -273,6 +301,7 @@ func TestRegistratorHandler(t *testing.T) {
{watch.Added, nil, publicIngressHostEDup},
},
map[string]string{},
nil,
},
{
"example.com.",
Expand All @@ -284,11 +313,25 @@ func TestRegistratorHandler(t *testing.T) {
map[string]string{
"e.example.com": testPublicTarget,
},
nil,
},
{
"example.com.",
[]mockEvent{
{watch.Added, nil, privateIngressHostE2},
{watch.Modified, privateIngressHostE2, privateIngressHostE2Fixed},
},
map[string]string{
"e.example.com": testPrivateTarget,
"e2.example.com": testPrivateTarget,
},
[]interface{}{privateIngressHostE},
},
}

for i, test := range testCases {
r.ingressWatcher.stopChannel = make(chan struct{})
r.ingressWatcher.store = &mockStore{items: test.storeIngresses}
mdz.domain = test.domain
mdz.zoneData = map[string]string{}
r.updateQueue = make(chan cnameChange, 16)
Expand Down

0 comments on commit 1065300

Please sign in to comment.