forked from ionos-enterprise/ionos-enterprise-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot_test.go
92 lines (78 loc) · 2.14 KB
/
snapshot_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
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
package profitbricks
import (
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/suite"
)
type SnapshotSuite struct {
ClientBaseSuite
}
func TestSnapshot(t *testing.T) {
suite.Run(t, new(SnapshotSuite))
}
func (s *SnapshotSuite) Test_Delete() {
mRsp := makeJsonResponse(http.StatusAccepted, nil)
mRsp.Header.Set("location", "status")
httpmock.RegisterResponder(http.MethodDelete, "=~/snapshots/111", httpmock.ResponderFromResponse(mRsp))
rsp, err := s.c.DeleteSnapshot("111")
s.NoError(err)
s.Equal("status", rsp.Get("location"))
}
type ListSnapshotSuite struct {
ClientBaseSuite
}
func TestListSnapshots(t *testing.T) {
suite.Run(t, new(ListSnapshotSuite))
}
func (s *ListSnapshotSuite) SetupTest() {
s.ClientBaseSuite.SetupTest()
rsp := loadTestData(s.T(), "list_snapshots.json")
mResp := makeJsonResponse(http.StatusOK, rsp)
httpmock.RegisterResponder(http.MethodGet, `=~/snapshots`, httpmock.ResponderFromResponse(mResp))
}
func (s *ListSnapshotSuite) Test_WithSelector_NoSelector() {
snapshots, err := s.c.ListSnapshotsWithSelector(nil)
s.Error(err)
s.Nil(snapshots)
}
func (s *ListSnapshotSuite) Test_WithSelector_Exact_Match() {
snapshots, err := s.c.ListSnapshotsWithSelector(
SelectExactSnapshot(
SnapshotByState(StateAvailable),
SnapshotByName("test-snapshot-02"),
),
)
s.NoError(err)
s.Len(snapshots, 1)
}
func (s *ListSnapshotSuite) Test_WithSelector_Exact_NoMatch() {
snapshots, err := s.c.ListSnapshotsWithSelector(
SelectExactSnapshot(
SnapshotByState(StateAvailable),
SnapshotByName("test-snapshot-03"),
),
)
s.NoError(err)
s.Len(snapshots, 0)
}
func (s *ListSnapshotSuite) Test_WithSelector_Any_Match() {
snapshots, err := s.c.ListSnapshotsWithSelector(
SelectAnySnapshot(
SnapshotByDescription("some description"),
SnapshotByName("test-snapshot-02"),
),
)
s.NoError(err)
s.Len(snapshots, 1)
}
func (s *ListSnapshotSuite) Test_WithSelector_Any_NoMatch() {
snapshots, err := s.c.ListSnapshotsWithSelector(
SelectAnySnapshot(
SnapshotByDescription("my custom description"),
SnapshotByName("test-snapshot-04"),
),
)
s.NoError(err)
s.Len(snapshots, 0)
}