File: domain_test.go

package info (click to toggle)
golang-github-akamai-akamaiopen-edgegrid-golang 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,408 kB
  • sloc: sh: 532; makefile: 3
file content (790 lines) | stat: -rw-r--r-- 46,172 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
package configgtm

import (
	"testing"

	"github.com/akamai/AkamaiOPEN-edgegrid-golang/jsonhooks-v1"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"gopkg.in/h2non/gock.v1"
)

func instantiateDomain() *Domain {

	domain := NewDomain(gtmTestDomain, "basic")
	domainData := []byte(`{
                                "cnameCoalescingEnabled" : false,
                                "defaultErrorPenalty" : 75,
                                "defaultHealthMax" : null,
                                "defaultHealthMultiplier" : null,
                                "defaultHealthThreshold" : null,
                                "defaultMaxUnreachablePenalty" : null,
                                "defaultSslClientCertificate" : null,
                                "defaultSslClientPrivateKey" : null,
                                "defaultTimeoutPenalty" : 25,
                                "defaultUnreachableThreshold" : null,
                                "emailNotificationList" : [ ],
                                "endUserMappingEnabled" : false,
                                "lastModified" : "2019-06-14T19:36:13.174+00:00",
                                "lastModifiedBy" : "operator",
                                "loadFeedback" : false,
                                "mapUpdateInterval" : 600,
                                "maxProperties" : 100,
                                "maxResources" : 9999,
                                "maxTestTimeout" : 60.0,
                                "maxTTL" : 3600,
                                "minPingableRegionFraction" : null,
                                "minTestInterval" : 0,
                                "minTTL" : 0,
                                "modificationComments" : "Add Property testproperty",
                                "name" : "gtmdomtest.akadns.net",
                                "pingInterval" : null,
                                "pingPacketSize" : null,
                                "roundRobinPrefix" : null,
                                "servermonitorLivenessCount" : null,
                                "servermonitorLoadCount" : null,
                                "servermonitorPool" : null,
                                "type" : "basic",
                                "status" : {
                                        "message" : "Change Pending",
                                        "changeId" : "df6c04e4-6327-4e0f-8872-bfe9fb2693d2",
                                        "propagationStatus" : "PENDING",
                                        "propagationStatusDate" : "2019-06-14T19:36:13.174+00:00",
                                        "passingValidation" : true,
                                        "links" : [ {
                                                                "rel" : "self",
                                                                "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/status/current"
                                        } ]
                                },
                                "loadImbalancePercentage" : null,
                                "domainVersionId" : null,
                                "resources" : [ ],
                                "properties" : [ {
                                        "backupCName" : null,
                                        "backupIp" : null,
                                        "balanceByDownloadScore" : false,
                                        "cname" : null,
                                        "comments" : null,
                                        "dynamicTTL" : 300,
                                        "failoverDelay" : null,
                                        "failbackDelay" : null,
                                        "ghostDemandReporting" : false,
                                        "handoutMode" : "normal",
                                        "handoutLimit" : 1,
                                        "healthMax" : null,
                                        "healthMultiplier" : null,
                                        "healthThreshold" : null,
                                        "lastModified" : "2019-06-14T19:36:13.174+00:00",
                                        "livenessTests" : [ ],
                                        "loadImbalancePercentage" : null,
                                        "mapName" : null,
                                        "maxUnreachablePenalty" : null,
                                        "minLiveFraction" : null,
                                        "mxRecords" : [ ],
                                        "name" : "testproperty",
                                        "scoreAggregationType" : "median",
                                        "stickinessBonusConstant" : null,
                                        "stickinessBonusPercentage" : null,
                                        "staticTTL" : null,
                                        "trafficTargets" : [ {
                                                "datacenterId" : 3131,
                                                "enabled" : true,
                                                "weight" : 100.0,
                                                "handoutCName" : null,
                                                "name" : null,
                                                "servers" : [ "1.2.3.4" ]
                                        } ],
                                        "type" : "performance",
                                        "unreachableThreshold" : null,
                                        "useComputedTargets" : false,
                                        "weightedHashBitsForIPv4" : null,
                                        "weightedHashBitsForIPv6" : null,
                                        "ipv6" : false,
                                        "links" : [ {
                                                "rel" : "self",
                                                "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/properties/testproperty"
                                        } ]
                                } ],
                                "datacenters" : [ {
                                        "datacenterId" : 3131,
                                        "nickname" : "testDC1",
                                        "scorePenalty" : 0,
                                        "city" : null,
                                        "stateOrProvince" : null,
                                        "country" : null,
                                        "latitude" : null,
                                        "longitude" : null,
                                        "cloneOf" : null,
                                        "virtual" : true,
                                        "defaultLoadObject" : null,
                                        "continent" : null,
                                        "servermonitorPool" : null,
                                        "servermonitorLivenessCount" : null,
                                        "servermonitorLoadCount" : null,
                                        "pingInterval" : null,
                                        "pingPacketSize" : null,
                                        "cloudServerTargeting" : false,
                                        "cloudServerHostHeaderOverride" : false,
                                        "links" : [ {
                                                "rel" : "self",
                                                "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/datacenters/3131"
                                        } ]
                                } ],
                                "geographicMaps" : [ ],
                                "cidrMaps" : [ ],
                                "asMaps" : [ ],
                                "links" : [ {
                                        "rel" : "self",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net"
                                }, {
                                        "rel" : "datacenters",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/datacenters"
                                }, {
                                        "rel" : "properties",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/properties"
                                }, {
                                        "rel" : "geographic-maps",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/geographic-maps"
                                }, {
                                        "rel" : "cidr-maps",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/cidr-maps"
                                }, {
                                        "rel" : "resources",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/resources"
                                }, {
                                        "rel" : "as-maps",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/as-maps"
                                } ]
                       }`)
	jsonhooks.Unmarshal(domainData, domain)

	return domain

}

// Verify GetListDomains. Sould pass, e.g. no API errors and non nil list.
func TestListDomains(t *testing.T) {

	defer gock.Off()

	mock := gock.New("https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/config-gtm/v1/domains")
	mock.
		Get("/config-gtm/v1/domains").
		HeaderPresent("Authorization").
		Reply(200).
		SetHeader("Content-Type", "application/vnd.config-gtm.v1.3+json;charset=UTF-8").
		BodyString(`{
                        "items" : [ {
                                "name" : "gtmdomtest.akadns.net",
                                "status" : "Change Pending",
                                "acgId" : "1-3CV382",
                                "lastModified" : "2019-06-06T19:07:20.000+00:00",
                                "lastModifiedBy" : "operator",
                                "changeId" : "c3e1b771-2500-40c9-a7da-6c3cdbce1936",
                                "activationState" : "PENDING",
                                "modificationComments" : "mock test",
                                "links" : [ {
                                        "rel" : "self",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net"
                                } ]
                        } ]
                   }`)

	Init(config)

	domainsList, err := ListDomains()
	assert.NoError(t, err)
	assert.NotEqual(t, domainsList, nil)
	assert.Equal(t, "gtmdomtest.akadns.net", domainsList[0].Name)

}

// Verify GetDomain. Name hardcoded. Should pass, e.g. no API errors and domain returned
func TestGetDomain(t *testing.T) {

	defer gock.Off()

	mock := gock.New("https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/config-gtm/v1/domains/" + gtmTestDomain)
	mock.
		Get("/config-gtm/v1/domains/"+gtmTestDomain).
		HeaderPresent("Authorization").
		Reply(200).
		SetHeader("Content-Type", "application/vnd.config-gtm.v1.3+json;charset=UTF-8").
		BodyString(`{
                          "cidrMaps": [], 
                          "datacenters": [
                              {
                                  "city": "Snæfellsjökull", 
                                  "cloneOf": null, 
                                  "cloudServerTargeting": false, 
                                  "continent": "EU", 
                                  "country": "IS", 
                                  "datacenterId": 3132, 
                                  "defaultLoadObject": {
                                       "loadObject": null, 
                                       "loadObjectPort": 0, 
                                       "loadServers": null
                                   }, 
                                   "latitude": 64.808, 
                                   "links": [
                                       {
                                            "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/datacenters/3132", 
                                            "rel": "self"
                                       }
                                    ], 
                                    "longitude": -23.776, 
                                    "nickname": "property_test_dc2", 
                                    "stateOrProvince": null, 
                                    "virtual": true
                              }, 
                              {
                                    "city": "Philadelphia", 
                                    "cloneOf": null, 
                                    "cloudServerTargeting": true, 
                                    "continent": "NA", 
                                    "country": "US", 
                                    "datacenterId": 3133, 
                                    "defaultLoadObject": {
                                         "loadObject": null, 
                                         "loadObjectPort": 0, 
                                         "loadServers": null
                                    }, 
                                    "latitude": 39.95, 
                                    "links": [
                                        {
                                             "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/datacenters/3133", 
                                             "rel": "self"
                                        }
                                     ], 
                                     "longitude": -75.167, 
                                     "nickname": "property_test_dc3", 
                                     "stateOrProvince": null, 
                                     "virtual": true
                              }, 
                              {
                                     "city": "Downpat", 
                                     "cloneOf": null, 
                                     "cloudServerTargeting": false, 
                                     "continent": "EU", 
                                     "country": "GB", 
                                     "datacenterId": 3131, 
                                     "defaultLoadObject": {
                                           "loadObject": null, 
                                           "loadObjectPort": 0, 
                                           "loadServers": null
                                     }, 
                                     "latitude": 54.367, 
                                     "links": [
                                         {
                                              "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/datacenters/3131", 
                                              "rel": "self"
                                         }
                                     ], 
                                     "longitude": -5.582, 
                                     "nickname": "property_test_dc1", 
                                     "stateOrProvince": "ha", 
                                     "virtual": true
                              }
                          ], 
                          "defaultErrorPenalty": 75, 
                          "defaultSslClientCertificate": null, 
                          "defaultSslClientPrivateKey": null, 
                          "defaultTimeoutPenalty": 25, 
                          "emailNotificationList": [], 
                          "geographicMaps": [], 
                          "lastModified": "2019-04-25T14:53:12.000+00:00", 
                          "lastModifiedBy": "operator", 
                          "links": [
                              {
                                   "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net", 
                                   "rel": "self"
                              }, 
                              {
                                   "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/datacenters", 
                                   "rel": "datacenters"
                              }, 
                              {
                                   "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/properties", 
                                   "rel": "properties"
                              }, 
                              {
                                   "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/geographic-maps", 
                                   "rel": "geographic-maps"
                              }, 
                              {
                                   "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/cidr-maps", 
                                   "rel": "cidr-maps"
                              }, 
                              {
                                   "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/resources", 
                                   "rel": "resources"
                              }
                          ], 
                          "loadFeedback": false, 
                          "loadImbalancePercentage": 10.0, 
                          "modificationComments": "Edit Property test_property", 
                          "name": "gtmdomtest.akadns.net", 
                          "properties": [
                               {
                                    "backupCName": null, 
                                    "backupIp": null, 
                                    "balanceByDownloadScore": false, 
                                    "cname": "www.boo.wow", 
                                    "comments": null, 
                                    "dynamicTTL": 300, 
                                    "failbackDelay": 0, 
                                    "failoverDelay": 0, 
                                    "handoutMode": "normal", 
                                    "healthMax": null, 
                                    "healthMultiplier": null, 
                                    "healthThreshold": null, 
                                    "ipv6": false, 
                                    "lastModified": "2019-04-25T14:53:12.000+00:00", 
                                    "links": [
                                         {
                                              "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/properties/test_property", 
                                              "rel": "self"
                                         }
                                    ], 
                                    "livenessTests": [
                                         {
                                               "disableNonstandardPortWarning": false, 
                                               "hostHeader": null, 
                                               "httpError3xx": true, 
                                               "httpError4xx": true, 
                                               "httpError5xx": true, 
                                               "name": "health check", 
                                               "requestString": null, 
                                               "responseString": null, 
                                               "sslClientCertificate": null, 
                                               "sslClientPrivateKey": null, 
                                               "testInterval": 60, 
                                               "testObject": "/status", 
                                               "testObjectPassword": null, 
                                               "testObjectPort": 80, 
                                               "testObjectProtocol": "HTTP", 
                                               "testObjectUsername": null, 
                                               "testTimeout": 25.0
                                         }
                                    ], 
                                    "loadImbalancePercentage": 10.0, 
                                    "mapName": null, 
                                    "maxUnreachablePenalty": null, 
                                    "mxRecords": [], 
                                    "name": "test_property", 
                                    "scoreAggregationType": "mean", 
                                    "staticTTL": 600, 
                                    "stickinessBonusConstant": null, 
                                    "stickinessBonusPercentage": 50, 
                                    "trafficTargets": [
                                         {
                                              "datacenterId": 3131, 
                                              "enabled": true, 
                                              "handoutCName": null, 
                                              "name": null, 
                                              "servers": [
                                                   "1.2.3.4", 
                                                   "1.2.3.5"
                                              ], 
                                              "weight": 50.0
                                         }, 
                                         {
                                              "datacenterId": 3132, 
                                              "enabled": true, 
                                              "handoutCName": "www.google.com", 
                                              "name": null, 
                                              "servers": [], 
                                              "weight": 25.0
                                         }, 
                                         {
                                              "datacenterId": 3133, 
                                              "enabled": true, 
                                              "handoutCName": "www.comcast.com", 
                                              "name": null, 
                                              "servers": [
                                                    "www.comcast.com"
                                              ], 
                                              "weight": 25.0
                                         }
                                    ], 
                                    "type": "weighted-round-robin", 
                                    "unreachableThreshold": null, 
                                    "useComputedTargets": false
                               }
                          ], 
                          "resources": [], 
                          "status": {
                               "changeId": "40e36abd-bfb2-4635-9fca-62175cf17007", 
                               "links": [
                                     {
                                          "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/status/current", 
                                          "rel": "self"
                                     }
                               ], 
                               "message": "Current configuration has been propagated to all GTM nameservers", 
                               "passingValidation": true, 
                               "propagationStatus": "COMPLETE", 
                               "propagationStatusDate": "2019-04-25T14:54:00.000+00:00"
                          }, 
                          "type": "weighted"
                }`)

	Init(config)

	testDomain, err := GetDomain(gtmTestDomain)

	assert.NoError(t, err)
	assert.Equal(t, gtmTestDomain, testDomain.Name)

}

// Verify failed case for GetDomain. Should pass, e.g. no API errors and domain not found
func TestGetBadDomain(t *testing.T) {

	baddomainname := "baddomainname.me"
	defer gock.Off()

	mock := gock.New("https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/config-gtm/v1/domains/" + baddomainname)
	mock.
		Get("/config-gtm/v1/domains/"+baddomainname).
		HeaderPresent("Authorization").
		Reply(404).
		SetHeader("Content-Type", "application/vnd.config-gtm.v1.3+json;charset=UTF-8").
		BodyString(`{
                }`)

	Init(config)

	_, err := GetDomain(baddomainname)
	assert.Error(t, err)

}

// Test Create domain. Name is hardcoded so this will effectively be an update. What happens to existing?
func TestCreateDomain(t *testing.T) {

	defer gock.Off()

	mock := gock.New("https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/config-gtm/v1/domains/")
	mock.
		Post("/config-gtm/v1/domains/").
		HeaderPresent("Authorization").
		Reply(200).
		SetHeader("Content-Type", "application/vnd.config-gtm.v1.3+json;charset=UTF-8").
		BodyString(`{
                        "resource" : {
                                "cnameCoalescingEnabled" : false,
                                "defaultErrorPenalty" : 75,
                                "defaultHealthMax" : null,
                                "defaultHealthMultiplier" : null,
                                "defaultHealthThreshold" : null,
                                "defaultMaxUnreachablePenalty" : null,
                                "defaultSslClientCertificate" : null,
                                "defaultSslClientPrivateKey" : null,
                                "defaultTimeoutPenalty" : 25,
                                "defaultUnreachableThreshold" : null,
                                "emailNotificationList" : [ ],
                                "endUserMappingEnabled" : false,
                                "lastModified" : "2019-06-24T18:48:57.787+00:00",
                                "lastModifiedBy" : "operator",
                                "loadFeedback" : false,
                                "mapUpdateInterval" : 0,
                                "maxProperties" : 0,
                                "maxResources" : 512,
                                "maxTestTimeout" : 0.0,
                                "maxTTL" : 0,
                                "minPingableRegionFraction" : null,
                                "minTestInterval" : 0,
                                "minTTL" : 0,
                                "modificationComments" : null,
                                "name" : "gtmdomtest.akadns.net",
                                "pingInterval" : null,
                                "pingPacketSize" : null,
                                "roundRobinPrefix" : null,
                                "servermonitorLivenessCount" : null,
                                "servermonitorLoadCount" : null,
                                "servermonitorPool" : null,
                                "type" : "basic",
                                "status" : {
                                        "message" : "Change Pending",
                                        "changeId" : "539872cc-6ba6-4429-acd5-90bab7fb5e9d",
                                        "propagationStatus" : "PENDING",
                                        "propagationStatusDate" : "2019-06-24T18:48:57.787+00:00",
                                        "passingValidation" : true,
                                        "links" : [ {
                                                "rel" : "self",
                                                "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/status/current"
                                        } ]
                                },
                                "loadImbalancePercentage" : null,
                                "domainVersionId" : null,
                                "resources" : [ ],
                                "properties" : [ ],
                                "datacenters" : [ ],
                                "geographicMaps" : [ ],
                                "cidrMaps" : [ ],
                                "asMaps" : [ ],
                                "links" : [ {
                                        "rel" : "self",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net"
                                    }, {
                                        "rel" : "datacenters",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/datacenters"
                                    }, {
                                        "rel" : "properties",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/properties"
                                    }, {
                                        "rel" : "geographic-maps",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/geographic-maps"
                                    }, {
                                        "rel" : "cidr-maps",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/cidr-maps"
                                    }, {
                                        "rel" : "resources",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/resources"
                                    }, {
                                        "rel" : "as-maps",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/as-maps"
                                    } ]
                                },
                        "status" : {
                                "message" : "Change Pending",
                                "changeId" : "539872cc-6ba6-4429-acd5-90bab7fb5e9d",
                                "propagationStatus" : "PENDING",
                                "propagationStatusDate" : "2019-06-24T18:48:57.787+00:00",
                                "passingValidation" : true,
                                "links" : [ {
                                        "rel" : "self",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/status/current"
                                } ]
                        }
                }`)

	Init(config)

	testDomain := NewDomain(gtmTestDomain, "basic")
	qArgs := make(map[string]string)

	statResponse, err := testDomain.Create(qArgs)
	require.NoError(t, err)
	assert.Equal(t, gtmTestDomain, statResponse.Resource.Name)

}

func TestUpdateDomain(t *testing.T) {

	defer gock.Off()

	mock := gock.New("https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/config-gtm/v1/domains/" + gtmTestDomain)
	mock.
		Put("/config-gtm/v1/domains/"+gtmTestDomain).
		HeaderPresent("Authorization").
		Reply(200).
		SetHeader("Content-Type", "application/vnd.config-gtm.v1.3+json;charset=UTF-8").
		BodyString(`{
                        "resource" : {
                                "cnameCoalescingEnabled" : false,
                                "defaultErrorPenalty" : 75,
                                "defaultHealthMax" : null,
                                "defaultHealthMultiplier" : null,
                                "defaultHealthThreshold" : null,
                                "defaultMaxUnreachablePenalty" : null,
                                "defaultSslClientCertificate" : null,
                                "defaultSslClientPrivateKey" : null,
                                "defaultTimeoutPenalty" : 25,
                                "defaultUnreachableThreshold" : null,
                                "emailNotificationList" : [ ],
                                "endUserMappingEnabled" : false,
                                "lastModified" : "2019-06-14T19:36:13.174+00:00",
                                "lastModifiedBy" : "operator",
                                "loadFeedback" : false,
                                "mapUpdateInterval" : 600,
                                "maxProperties" : 100,
                                "maxResources" : 9999,
                                "maxTestTimeout" : 60.0,
                                "maxTTL" : 3600,
                                "minPingableRegionFraction" : null,
                                "minTestInterval" : 0,
                                "minTTL" : 0,
                                "modificationComments" : "Add Property testproperty",
                                "name" : "gtmdomtest.akadns.net",
                                "pingInterval" : null,
                                "pingPacketSize" : null,
                                "roundRobinPrefix" : null,
                                "servermonitorLivenessCount" : null,
                                "servermonitorLoadCount" : null,
                                "servermonitorPool" : null,
                                "type" : "basic",
                                "status" : {
                                        "message" : "Change Pending",
                                        "changeId" : "df6c04e4-6327-4e0f-8872-bfe9fb2693d2",
                                        "propagationStatus" : "PENDING",
                                        "propagationStatusDate" : "2019-06-14T19:36:13.174+00:00",
                                        "passingValidation" : true,
                                        "links" : [ {
                                                                "rel" : "self",
                                                                "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/status/current"
                                        } ]
                                },
                                "loadImbalancePercentage" : null,
                                "domainVersionId" : null,
                                "resources" : [ ],
                                "properties" : [ {
                                        "backupCName" : null,
                                        "backupIp" : null,
                                        "balanceByDownloadScore" : false,
                                        "cname" : null,
                                        "comments" : null,
                                        "dynamicTTL" : 300,
                                        "failoverDelay" : null,
                                        "failbackDelay" : null,
                                        "ghostDemandReporting" : false,
                                        "handoutMode" : "normal",
                                        "handoutLimit" : 1,
                                        "healthMax" : null,
                                        "healthMultiplier" : null,
                                        "healthThreshold" : null,
                                        "lastModified" : "2019-06-14T19:36:13.174+00:00",
                                        "livenessTests" : [ ],
                                        "loadImbalancePercentage" : null,
                                        "mapName" : null,
                                        "maxUnreachablePenalty" : null,
                                        "minLiveFraction" : null,
                                        "mxRecords" : [ ],
                                        "name" : "testproperty",
                                        "scoreAggregationType" : "median",
                                        "stickinessBonusConstant" : null,
                                        "stickinessBonusPercentage" : null,
                                        "staticTTL" : null,
                                        "trafficTargets" : [ {
                                                "datacenterId" : 3131,
                                                "enabled" : true,
                                                "weight" : 100.0,
                                                "handoutCName" : null,
                                                "name" : null,
                                                "servers" : [ "1.2.3.4" ]
                                        } ],
                                        "type" : "performance",
                                        "unreachableThreshold" : null,
                                        "useComputedTargets" : false,
                                        "weightedHashBitsForIPv4" : null,
                                        "weightedHashBitsForIPv6" : null,
                                        "ipv6" : false,
                                        "links" : [ {
                                                "rel" : "self",
                                                "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/properties/testproperty"
                                        } ]
                                } ],
                                "datacenters" : [ {
                                        "datacenterId" : 3131,
                                        "nickname" : "testDC1",
                                        "scorePenalty" : 0,
                                        "city" : null,
                                        "stateOrProvince" : null,
                                        "country" : null,
                                        "latitude" : null,
                                        "longitude" : null,
                                        "cloneOf" : null,
                                        "virtual" : true,
                                        "defaultLoadObject" : null,
                                        "continent" : null,
                                        "servermonitorPool" : null,
                                        "servermonitorLivenessCount" : null,
                                        "servermonitorLoadCount" : null,
                                        "pingInterval" : null,
                                        "pingPacketSize" : null,
                                        "cloudServerTargeting" : false,
                                        "cloudServerHostHeaderOverride" : false,
                                        "links" : [ {
                                                "rel" : "self",
                                                "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/datacenters/3131"
                                        } ]
                                } ],
                                "geographicMaps" : [ ],
                                "cidrMaps" : [ ],
                                "asMaps" : [ ],
                                "links" : [ {
                                        "rel" : "self",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net"
                                }, {
                                        "rel" : "datacenters",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/datacenters"
                                }, {
                                        "rel" : "properties",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/properties"
                                }, {
                                        "rel" : "geographic-maps",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/geographic-maps"
                                }, {
                                        "rel" : "cidr-maps",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/cidr-maps"
                                }, {
                                        "rel" : "resources",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/resources"
                                }, {
                                        "rel" : "as-maps",
                                        "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/as-maps"
                                } ]
                        },
                        "status" : {
                                      "message" : "Change Pending",
                                      "changeId" : "df6c04e4-6327-4e0f-8872-bfe9fb2693d2",
                                      "propagationStatus" : "PENDING",
                                      "propagationStatusDate" : "2019-06-14T19:36:13.174+00:00",
                                      "passingValidation" : true,
                                      "links" : [ {
                                              "rel" : "self",
                                              "href" : "https://akaa-32qkzqewderdchot-d3uwbyqc4pqi2c5l.luna-dev.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/status/current"
                                      } ]
                        }            
                }`)

	Init(config)

	testDomain := instantiateDomain()
	//testDomain.MaxResources = 9999
	qArgs := make(map[string]string)
	statResp, err := testDomain.Update(qArgs)
	require.NoError(t, err)
	assert.Equal(t, statResp.ChangeId, "df6c04e4-6327-4e0f-8872-bfe9fb2693d2")

}

/* Future. Presently no domain Delete endpoint.
func TestDeleteDomain(t *testing.T) {

        defer gock.Off()

        mock := gock.New("https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/config-gtm/v1/domains/"+gtmTestDomain)
        mock.
                Delete("/config-gtm/v1/domains/"+gtmTestDomain).
                HeaderPresent("Authorization").
                Reply(200).
                SetHeader("Content-Type", "application/vnd.config-gtm.v1.3+json;charset=UTF-8").
                BodyString(`{
                        "resource" : null,
                        "status" : {
                               "changeId": "40e36abd-bfb2-4635-9fca-62175cf17007",
                               "links": [
                                     {
                                          "href": "https://akab-ymtebc45gco3ypzj-apz4yxpek55y7fyv.luna.akamaiapis.net/config-gtm/v1/domains/gtmdomtest.akadns.net/status/current",
                                          "rel": "self"
                                     }
                               ],
                               "message": "Change Pending",
                               "passingValidation": true,
                               "propagationStatus": "PENDING",
                               "propagationStatusDate": "2019-04-25T14:54:00.000+00:00"
                          },
                }`)

        Init(config)

        getDomain := instantiateDomain()

        _, err := getDomain.Delete()
        assert.NoError(t, err)

}
*/