@@ -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"
@@ -32,7 +33,7 @@ func (a *testAllocator) GenerateHostname(*api.Route, *api.RouterShard) string {
32
33
return a .Hostname
33
34
}
34
35
35
- func newStorage (t * testing.T , allocator * testAllocator ) (* REST , * etcdtesting.EtcdTestServer ) {
36
+ func newStorage (t * testing.T , allocator routetypes. RouteAllocator ) (* REST , * etcdtesting.EtcdTestServer ) {
36
37
etcdStorage , server := registrytest .NewEtcdStorage (t , "" )
37
38
storage , _ , err := NewREST (restoptions .NewSimpleGetter (etcdStorage ), allocator )
38
39
if err != nil {
@@ -56,7 +57,7 @@ func validRoute() *api.Route {
56
57
}
57
58
58
59
func TestCreate (t * testing.T ) {
59
- storage , server := newStorage (t , & testAllocator {} )
60
+ storage , server := newStorage (t , nil )
60
61
defer server .Terminate (t )
61
62
test := registrytest .New (t , storage .Etcd )
62
63
test .TestCreate (
@@ -114,6 +115,51 @@ func TestUpdate(t *testing.T) {
114
115
},
115
116
)
116
117
}
118
+
119
+ func TestUpdateWithAllocation (t * testing.T ) {
120
+ allocator := & testAllocator {Hostname : "bar" }
121
+ storage , server := newStorage (t , allocator )
122
+ defer server .Terminate (t )
123
+
124
+ // create a route with a populated host
125
+ originalRoute := validRoute ()
126
+ originalRoute .Spec .Host = "foo"
127
+ created , err := storage .Create (kapi .NewDefaultContext (), originalRoute )
128
+ if err != nil {
129
+ t .Fatalf ("error creating valid route to test allocations: %v" , err )
130
+ }
131
+
132
+ createdRoute := created .(* api.Route )
133
+ if createdRoute .Spec .Host != "foo" {
134
+ t .Fatalf ("unexpected host on createdRoute: %#v" , createdRoute )
135
+ }
136
+ if _ , ok := createdRoute .Annotations [route .HostGeneratedAnnotationKey ]; ok {
137
+ t .Fatalf ("created route should not have the generated host annotation" )
138
+ }
139
+
140
+ // update the route to set the host to empty
141
+ createdRoute .Spec .Host = ""
142
+ updated , _ , err := storage .Update (kapi .NewDefaultContext (), createdRoute )
143
+ if err != nil {
144
+ t .Fatalf ("error updating route to test allocations: %v" , err )
145
+ }
146
+
147
+ // route should now have the allocated host of bar and the generated host annotation
148
+ updatedRoute := updated .(* api.Route )
149
+ if updatedRoute == nil {
150
+ t .Fatalf ("expected updatedRoute to not be nil" )
151
+ }
152
+ if updatedRoute .Spec .Host != "bar" {
153
+ t .Fatalf ("unexpected route: %#v" , updatedRoute )
154
+ }
155
+ if v , ok := updatedRoute .Annotations [route .HostGeneratedAnnotationKey ]; ! ok || v != "true" {
156
+ t .Fatalf ("unexpected route: %#v" , updatedRoute )
157
+ }
158
+ if ! allocator .Allocate || ! allocator .Generate {
159
+ t .Fatalf ("unexpected allocator: %#v" , allocator )
160
+ }
161
+ }
162
+
117
163
func TestList (t * testing.T ) {
118
164
storage , server := newStorage (t , nil )
119
165
defer server .Terminate (t )
0 commit comments