@@ -10,6 +10,7 @@ import (
10
10
"k8s.io/kubernetes/pkg/runtime"
11
11
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
12
12
13
+ routetypes "github.com/openshift/origin/pkg/route"
13
14
"github.com/openshift/origin/pkg/route/api"
14
15
_ "github.com/openshift/origin/pkg/route/api/install"
15
16
"github.com/openshift/origin/pkg/route/registry/route"
@@ -31,7 +32,7 @@ func (a *testAllocator) GenerateHostname(*api.Route, *api.RouterShard) string {
31
32
return a .Hostname
32
33
}
33
34
34
- func newStorage (t * testing.T , allocator * testAllocator ) (* REST , * etcdtesting.EtcdTestServer ) {
35
+ func newStorage (t * testing.T , allocator routetypes. RouteAllocator ) (* REST , * etcdtesting.EtcdTestServer ) {
35
36
etcdStorage , server := registrytest .NewEtcdStorage (t , "" )
36
37
storage , _ := NewREST (etcdStorage , allocator )
37
38
return storage , server
@@ -52,7 +53,7 @@ func validRoute() *api.Route {
52
53
}
53
54
54
55
func TestCreate (t * testing.T ) {
55
- storage , server := newStorage (t , & testAllocator {} )
56
+ storage , server := newStorage (t , nil )
56
57
defer server .Terminate (t )
57
58
test := registrytest .New (t , storage .Etcd )
58
59
test .TestCreate (
@@ -110,6 +111,51 @@ func TestUpdate(t *testing.T) {
110
111
},
111
112
)
112
113
}
114
+
115
+ func TestUpdateWithAllocation (t * testing.T ) {
116
+ allocator := & testAllocator {Hostname : "bar" }
117
+ storage , server := newStorage (t , allocator )
118
+ defer server .Terminate (t )
119
+
120
+ // create a route with a populated host
121
+ originalRoute := validRoute ()
122
+ originalRoute .Spec .Host = "foo"
123
+ created , err := storage .Create (kapi .NewDefaultContext (), originalRoute )
124
+ if err != nil {
125
+ t .Fatalf ("error creating valid route to test allocations: %v" , err )
126
+ }
127
+
128
+ createdRoute := created .(* api.Route )
129
+ if createdRoute .Spec .Host != "foo" {
130
+ t .Fatalf ("unexpected host on createdRoute: %#v" , createdRoute )
131
+ }
132
+ if _ , ok := createdRoute .Annotations [route .HostGeneratedAnnotationKey ]; ok {
133
+ t .Fatalf ("created route should not have the generated host annotation" )
134
+ }
135
+
136
+ // update the route to set the host to empty
137
+ createdRoute .Spec .Host = ""
138
+ updated , _ , err := storage .Update (kapi .NewDefaultContext (), createdRoute )
139
+ if err != nil {
140
+ t .Fatalf ("error updating route to test allocations: %v" , err )
141
+ }
142
+
143
+ // route should now have the allocated host of bar and the generated host annotation
144
+ updatedRoute := updated .(* api.Route )
145
+ if updatedRoute == nil {
146
+ t .Fatalf ("expected updatedRoute to not be nil" )
147
+ }
148
+ if updatedRoute .Spec .Host != "bar" {
149
+ t .Fatalf ("unexpected route: %#v" , updatedRoute )
150
+ }
151
+ if v , ok := updatedRoute .Annotations [route .HostGeneratedAnnotationKey ]; ! ok || v != "true" {
152
+ t .Fatalf ("unexpected route: %#v" , updatedRoute )
153
+ }
154
+ if ! allocator .Allocate || ! allocator .Generate {
155
+ t .Fatalf ("unexpected allocator: %#v" , allocator )
156
+ }
157
+ }
158
+
113
159
func TestList (t * testing.T ) {
114
160
storage , server := newStorage (t , nil )
115
161
defer server .Terminate (t )
0 commit comments