This repository was archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvideolibrary_test.go
More file actions
94 lines (81 loc) · 2.67 KB
/
videolibrary_test.go
File metadata and controls
94 lines (81 loc) · 2.67 KB
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
//go:build integrationtest
// +build integrationtest
package bunny_test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
bunny "github.com/simplesurance/bunny-go"
)
func TestVideoLibraryCRUD(t *testing.T) {
clt := newClient(t)
vlName := randomResourceName("videolibrary")
vlRegion := "NY"
vlAddopts := bunny.VideoLibraryAddOptions{
Name: &vlName,
ReplicationRegions: []string{vlRegion},
}
listVlBefore, err := clt.VideoLibrary.List(context.Background(), nil)
require.NoError(t, err, "video library list failed before add")
vl := createVideoLibrary(t, clt, &vlAddopts)
// get the newly created video library
getVl, err := clt.VideoLibrary.Get(context.Background(), *vl.ID, &bunny.VideoLibraryGetOpts{false})
require.NoError(t, err, "video library get failed after adding")
assert.NotNil(t, getVl.ID)
assert.Nil(t, getVl.APIAccessKey)
assert.Equal(
t,
vlRegion,
getVl.ReplicationRegions[0],
"video library replication region should be set correctly",
)
// update the video library
newName := vlName + "-updated"
setTrue := true
setFalse := false
updateOpts := bunny.VideoLibraryUpdateOptions{
Name: &newName,
PlayerTokenAuthenticationEnabled: &setTrue,
AllowDirectPlay: &setFalse,
}
_, updateErr := clt.VideoLibrary.Update(context.Background(), *vl.ID, &updateOpts)
assert.Nil(t, updateErr)
// get the updated video library and validate updated properties
getUpdatedVl, err := clt.VideoLibrary.Get(context.Background(), *vl.ID, &bunny.VideoLibraryGetOpts{true})
assert.NotNil(t, getUpdatedVl.ID)
assert.NotNil(t, getUpdatedVl.APIAccessKey)
assert.Equal(
t,
newName,
*getUpdatedVl.Name,
"video library Name should be updated correctly",
)
assert.Equal(
t,
true,
*getUpdatedVl.PlayerTokenAuthenticationEnabled,
"video library PlayerTokenAuthenticationEnabled should be updated correctly",
)
assert.Equal(
t,
false,
*getUpdatedVl.AllowDirectPlay,
"video library AllowDirectPlay should be updated correctly",
)
// check the total number of video libraries is the expected amount
listVlAfter, err := clt.VideoLibrary.List(context.Background(), nil)
require.NoError(t, err, "video library list failed after add")
assert.Nil(t, listVlAfter.Items[0].APIAccessKey)
assert.Equal(
t,
*listVlBefore.TotalItems + 1,
*listVlAfter.TotalItems,
"video libraries total items should increase by exactly 1",
)
// check that listing video libraries and requesting keys works
listVlWithKeys, err := clt.VideoLibrary.List(context.Background(), &bunny.VideoLibraryListOpts{
VideoLibraryGetOpts: bunny.VideoLibraryGetOpts{true},
})
assert.NotNil(t, listVlWithKeys.Items[0].APIAccessKey)
}