-
Notifications
You must be signed in to change notification settings - Fork 3
/
backups_test.go
83 lines (67 loc) · 2.26 KB
/
backups_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
package solus
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBackup_IsFinished(t *testing.T) {
testCases := map[BackupStatus]bool{
BackupStatusPending: false,
BackupStatusInProgress: false,
BackupStatusFailed: true,
BackupStatusCreated: true,
}
for status, expected := range testCases {
status := status
expected := expected
t.Run(string(status), func(t *testing.T) {
require.Equal(t, expected, Backup{Status: status}.IsFinished())
})
}
}
func TestBackupsService_Get(t *testing.T) {
s := startTestServer(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/backups/10", r.URL.Path)
assert.Equal(t, http.MethodGet, r.Method)
writeResponse(t, w, http.StatusOK, fakeBackup)
})
defer s.Close()
actual, err := createTestClient(t, s.URL).Backups.Get(context.Background(), 10)
require.NoError(t, err)
require.Equal(t, fakeBackup, actual)
}
func TestBackupsService_Delete(t *testing.T) {
s := startTestServer(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/backups/10", r.URL.Path)
assert.Equal(t, http.MethodDelete, r.Method)
w.WriteHeader(http.StatusNoContent)
})
defer s.Close()
err := createTestClient(t, s.URL).Backups.Delete(context.Background(), 10)
require.NoError(t, err)
}
func TestBackupsService_Restore(t *testing.T) {
t.Run("positive", func(t *testing.T) {
s := startTestServer(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/backups/10/restore", r.URL.Path)
assert.Equal(t, http.MethodPost, r.Method)
writeResponse(t, w, http.StatusOK, fakeTask)
})
defer s.Close()
actual, err := createTestClient(t, s.URL).Backups.Restore(context.Background(), 10)
require.NoError(t, err)
require.Equal(t, fakeTask, actual)
})
t.Run("negative", func(t *testing.T) {
s := startTestServer(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/backups/10/restore", r.URL.Path)
assert.Equal(t, http.MethodPost, r.Method)
writeResponse(t, w, http.StatusNotFound, fakeTask)
})
defer s.Close()
_, err := createTestClient(t, s.URL).Backups.Restore(context.Background(), 10)
assert.EqualError(t, err, "HTTP POST backups/10/restore returns 404 status code")
})
}