@@ -29,7 +29,6 @@ import (
2929 "time"
3030
3131 "github.com/AbsaOSS/external-dns-infoblox-webhook/cmd/webhook/init/configuration"
32- "github.com/AbsaOSS/external-dns-infoblox-webhook/pkg/webhook"
3332 log "github.com/sirupsen/logrus"
3433 "sigs.k8s.io/external-dns/endpoint"
3534 "sigs.k8s.io/external-dns/plan"
@@ -58,15 +57,16 @@ var mockProvider *MockProvider
5857func TestMain (m * testing.M ) {
5958 mockProvider = & MockProvider {}
6059
61- srv := Init (configuration .Init (), webhook .New (mockProvider ))
62- go ShutdownGracefully (srv )
60+ go func () {
61+ srv := NewServer ()
62+ srv .StartHealth (configuration .Init ())
63+ srv .Start (configuration .Init (), mockProvider )
64+
65+ }()
6366
6467 time .Sleep (300 * time .Millisecond )
6568
6669 m .Run ()
67- if err := srv .Shutdown (context .TODO ()); err != nil {
68- panic (err )
69- }
7070}
7171
7272func TestRecords (t * testing.T ) {
@@ -94,30 +94,6 @@ func TestRecords(t *testing.T) {
9494 },
9595 expectedBody : "[{\" dnsName\" :\" test.example.com\" ,\" targets\" :[\" \" ],\" recordType\" :\" A\" ,\" recordTTL\" :3600,\" labels\" :{\" label1\" :\" value1\" }}]" ,
9696 },
97- {
98- name : "no accept header" ,
99- method : http .MethodGet ,
100- headers : map [string ]string {},
101- path : "/records" ,
102- body : "" ,
103- expectedStatusCode : http .StatusNotAcceptable ,
104- expectedResponseHeaders : map [string ]string {
105- "Content-Type" : "text/plain" ,
106- },
107- expectedBody : "client must provide an accept header" ,
108- },
109- {
110- name : "wrong accept header" ,
111- method : http .MethodGet ,
112- headers : map [string ]string {"Accept" : "invalid" },
113- path : "/records" ,
114- body : "" ,
115- expectedStatusCode : http .StatusUnsupportedMediaType ,
116- expectedResponseHeaders : map [string ]string {
117- "Content-Type" : "text/plain" ,
118- },
119- expectedBody : "Client must provide a valid versioned media type in the accept header: Unsupported media type version: 'invalid'. Supported media types are: 'application/external.dns.webhook+json;version=1'" ,
120- },
12197 {
12298 name : "backend error" ,
12399 hasError : fmt .Errorf ("backend error" ),
@@ -238,46 +214,6 @@ func TestApplyChanges(t *testing.T) {
238214 },
239215 },
240216 },
241- {
242- name : "no content type header" ,
243- method : http .MethodPost ,
244- path : "/records" ,
245- body : "" ,
246- expectedStatusCode : http .StatusNotAcceptable ,
247- expectedResponseHeaders : map [string ]string {
248- "Content-Type" : "text/plain" ,
249- },
250- expectedBody : "client must provide a content type" ,
251- },
252- {
253- name : "wrong content type header" ,
254- method : http .MethodPost ,
255- headers : map [string ]string {
256- "Content-Type" : "invalid" ,
257- },
258- path : "/records" ,
259- body : "" ,
260- expectedStatusCode : http .StatusUnsupportedMediaType ,
261- expectedResponseHeaders : map [string ]string {
262- "Content-Type" : "text/plain" ,
263- },
264- expectedBody : "Client must provide a valid versioned media type in the content type: Unsupported media type version: 'invalid'. Supported media types are: 'application/external.dns.webhook+json;version=1'" ,
265- },
266- {
267- name : "invalid json" ,
268- method : http .MethodPost ,
269- headers : map [string ]string {
270- "Content-Type" : "application/external.dns.webhook+json;version=1" ,
271- "Accept" : "application/external.dns.webhook+json;version=1" ,
272- },
273- path : "/records" ,
274- body : "invalid" ,
275- expectedStatusCode : http .StatusBadRequest ,
276- expectedResponseHeaders : map [string ]string {
277- "Content-Type" : "text/plain" ,
278- },
279- expectedBody : "error decoding changes: invalid character 'i' looking for beginning of value" ,
280- },
281217 {
282218 name : "backend error" ,
283219 hasError : fmt .Errorf ("backend error" ),
@@ -361,78 +297,18 @@ func TestAdjustEndpoints(t *testing.T) {
361297 },
362298 },
363299 },
364- {
365- name : "no content type header" ,
366- method : http .MethodPost ,
367- headers : map [string ]string {
368- "Accept" : "application/external.dns.webhook+json;version=1" ,
369- },
370- path : "/adjustendpoints" ,
371- body : "" ,
372- expectedStatusCode : http .StatusNotAcceptable ,
373- expectedResponseHeaders : map [string ]string {
374- "Content-Type" : "text/plain" ,
375- },
376- expectedBody : "client must provide a content type" ,
377- },
378- {
379- name : "wrong content type header" ,
380- method : http .MethodPost ,
381- headers : map [string ]string {
382- "Content-Type" : "invalid" ,
383- "Accept" : "application/external.dns.webhook+json;version=1" ,
384- },
385- path : "/adjustendpoints" ,
386- body : "" ,
387- expectedStatusCode : http .StatusUnsupportedMediaType ,
388- expectedResponseHeaders : map [string ]string {
389- "Content-Type" : "text/plain" ,
390- },
391- expectedBody : "Client must provide a valid versioned media type in the content type: Unsupported media type version: 'invalid'. Supported media types are: 'application/external.dns.webhook+json;version=1'" ,
392- },
393- {
394- name : "no accept header" ,
395- method : http .MethodPost ,
396- headers : map [string ]string {
397- "Content-Type" : "application/external.dns.webhook+json;version=1" ,
398- },
399- path : "/adjustendpoints" ,
400- body : "" ,
401- expectedStatusCode : http .StatusNotAcceptable ,
402- expectedResponseHeaders : map [string ]string {
403- "Content-Type" : "text/plain" ,
404- },
405- expectedBody : "client must provide an accept header" ,
406- },
407- {
408- name : "wrong accept header" ,
409- method : http .MethodPost ,
410- headers : map [string ]string {
411- "Content-Type" : "application/external.dns.webhook+json;version=1" ,
412- "Accept" : "invalid" ,
413- },
414- path : "/adjustendpoints" ,
415- body : "" ,
416- expectedStatusCode : http .StatusUnsupportedMediaType ,
417- expectedResponseHeaders : map [string ]string {
418- "Content-Type" : "text/plain" ,
419- },
420- expectedBody : "Client must provide a valid versioned media type in the accept header: Unsupported media type version: 'invalid'. Supported media types are: 'application/external.dns.webhook+json;version=1'" ,
421- },
422300 {
423301 name : "invalid json" ,
424302 method : http .MethodPost ,
425303 headers : map [string ]string {
426304 "Content-Type" : "application/external.dns.webhook+json;version=1" ,
427305 "Accept" : "application/external.dns.webhook+json;version=1" ,
428306 },
429- path : "/adjustendpoints" ,
430- body : "invalid" ,
431- expectedStatusCode : http .StatusBadRequest ,
432- expectedResponseHeaders : map [string ]string {
433- "Content-Type" : "text/plain" ,
434- },
435- expectedBody : "failed to decode request body: invalid character 'i' looking for beginning of value" ,
307+ path : "/adjustendpoints" ,
308+ body : "invalid" ,
309+ expectedStatusCode : http .StatusBadRequest ,
310+ expectedResponseHeaders : map [string ]string {},
311+ expectedBody : "" ,
436312 },
437313 }
438314
@@ -460,23 +336,11 @@ func TestNegotiate(t *testing.T) {
460336 headers : map [string ]string {},
461337 path : "/" ,
462338 body : "" ,
463- expectedStatusCode : http .StatusNotAcceptable ,
464- expectedResponseHeaders : map [string ]string {
465- "Content-Type" : "text/plain" ,
466- },
467- expectedBody : "client must provide an accept header" ,
468- },
469- {
470- name : "wrong accept header" ,
471- method : http .MethodGet ,
472- headers : map [string ]string {"Accept" : "invalid" },
473- path : "/" ,
474- body : "" ,
475- expectedStatusCode : http .StatusUnsupportedMediaType ,
339+ expectedStatusCode : http .StatusOK ,
476340 expectedResponseHeaders : map [string ]string {
477- "Content-Type" : "text/plain " ,
341+ "Content-Type" : "application/external.dns.webhook+json;version=1 " ,
478342 },
479- expectedBody : "Client must provide a valid versioned media type in the accept header: Unsupported media type version: 'invalid'. Supported media types are: 'application/external.dns.webhook+json;version=1' " ,
343+ expectedBody : "{} " ,
480344 },
481345 }
482346
0 commit comments