forked from simplesurance/bunny-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pullzone_hostname_test.go
50 lines (37 loc) · 1.57 KB
/
pullzone_hostname_test.go
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
//go:build integrationtest
// +build integrationtest
package bunny_test
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
bunny "github.com/simplesurance/bunny-go"
)
func TestPullZoneAddRemoveHostname(t *testing.T) {
clt := newClient(t)
pzAddopts := bunny.PullZoneAddOptions{
Name: randomPullZoneName(),
OriginURL: "http://bunny.net",
}
pz := createPullZone(t, clt, &pzAddopts)
hostname := "testhostname-" + uuid.New().String() + ".bunny.net"
err := clt.PullZone.AddCustomHostname(context.Background(), *pz.ID, &bunny.AddCustomHostnameOptions{Hostname: &hostname})
require.NoError(t, err, "add hostname to pull zone failed")
getPz, err := clt.PullZone.Get(context.Background(), *pz.ID)
require.NoError(t, err, "pull zone get failed after adding hostname")
require.True(t, containsHostname(getPz.Hostnames, hostname), "hostname not returned by get after adding it")
err = clt.PullZone.RemoveCustomHostname(context.Background(), *pz.ID, &bunny.RemoveCustomHostnameOptions{Hostname: &hostname})
require.NoError(t, err, "removing hostname from pull zone failed")
getPz, err = clt.PullZone.Get(context.Background(), *pz.ID)
require.NoError(t, err, "pull zone get failed after removing hostname")
require.False(t, containsHostname(getPz.Hostnames, hostname), "pull zone hostnames list is not empty after removing hostname")
}
func containsHostname(hostnames []*bunny.Hostname, hostname string) bool {
for _, elem := range hostnames {
if elem.Value != nil && *elem.Value == hostname {
return true
}
}
return false
}