File: zone_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 (76 lines) | stat: -rw-r--r-- 2,367 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
package dnsv2

import (
	"fmt"
	"github.com/akamai/AkamaiOPEN-edgegrid-golang/jsonhooks-v1"
	"github.com/stretchr/testify/assert"
	"gopkg.in/h2non/gock.v1"
	"testing"
)

func TestZone_JSON(t *testing.T) {
	responseBody := []byte(`{
    "zone": "example.com",
    "type": "PRIMARY",
    "comment": "This is a test zone",
    "signAndServe": false
}`)

	zonecreate := ZoneCreate{Zone: "example.com", Type: "PRIMARY", Masters: []string{""}, Comment: "This is a test zone", SignAndServe: false}
	zone := NewZone(zonecreate)
	err := jsonhooks.Unmarshal(responseBody, zone)
	assert.NoError(t, err)
	assert.Equal(t, zone.Zone, "example.com")
	assert.Equal(t, zone.Type, "PRIMARY")
	assert.Equal(t, zone.Comment, "This is a test zone")
	assert.Equal(t, zone.SignAndServe, false)
}

func TestGetZoneNames(t *testing.T) {

	dnsTestZone := "testzone.com"

	defer gock.Off()

	mock := gock.New(fmt.Sprintf("https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/config-dns/v2/zones/%s/names", dnsTestZone))
	mock.
		Get(fmt.Sprintf("/config-dns/v2/zones/%s/names", dnsTestZone)).
		HeaderPresent("Authorization").
		Reply(200).
		SetHeader("Content-Type", "application/json;charset=UTF-8").
		BodyString(fmt.Sprintf(`{
                        "names":["test1.testzone.com","test2.testzone.com"]
                }`))

	Init(config)
	nameList, err := GetZoneNames(dnsTestZone)
	assert.NoError(t, err)
	assert.Equal(t, assert.IsType(t, &ZoneNamesResponse{}, nameList), true)
	assert.Equal(t, len(nameList.Names), 2)

}

func TestGetZoneNameTypes(t *testing.T) {

	dnsTestZone := "testzone.com"
	dnsTestRecordName := "test.testzone.com"

	defer gock.Off()

	mock := gock.New(fmt.Sprintf("https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/config-dns/v2/zones/%s/names/%s/types", dnsTestZone, dnsTestRecordName))
	mock.
		Get(fmt.Sprintf("/config-dns/v2/zones/%s/names/%s/types", dnsTestZone, dnsTestRecordName)).
		HeaderPresent("Authorization").
		Reply(200).
		SetHeader("Content-Type", "application/json;charset=UTF-8").
		BodyString(fmt.Sprintf(`{
                        "types":["CNAME", "AKAMAICDN"]
                }`))

	Init(config)
	typeList, err := GetZoneNameTypes(dnsTestRecordName, dnsTestZone)
	assert.NoError(t, err)
	assert.Equal(t, assert.IsType(t, &ZoneNameTypesResponse{}, typeList), true)
	assert.Equal(t, len(typeList.Types), 2)

}