forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_import_export_test.go
92 lines (78 loc) · 2.12 KB
/
group_import_export_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 gitlab
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"reflect"
"testing"
)
func TestGroupScheduleExport(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/groups/1/export",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"message": "202 Accepted"}`)
})
_, err := client.GroupImportExport.ScheduleExport(1)
if err != nil {
t.Errorf("GroupImportExport.ScheduleExport returned error: %v", err)
}
}
func TestGroupExportDownload(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
content := []byte("fake content")
mux.HandleFunc("/api/v4/groups/1/export/download",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
w.Write(content)
})
export, _, err := client.GroupImportExport.ExportDownload(1)
if err != nil {
t.Errorf("GroupImportExport.ExportDownload returned error: %v", err)
}
data, err := ioutil.ReadAll(export)
if err != nil {
t.Errorf("Error reading export: %v", err)
}
want := []byte("fake content")
if !reflect.DeepEqual(want, data) {
t.Errorf("GroupImportExport.GroupExportDownload returned %+v, want %+v", data, want)
}
}
func TestGroupImport(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
content := []byte("temporary file's content")
tmpfile, err := ioutil.TempFile("", "example.*.tar.gz")
if err != nil {
tmpfile.Close()
log.Fatal(err)
}
if _, err := tmpfile.Write(content); err != nil {
tmpfile.Close()
log.Fatal(err)
}
if err := tmpfile.Close(); err != nil {
log.Fatal(err)
}
defer os.Remove(tmpfile.Name()) // clean up
mux.HandleFunc("/api/v4/groups/import",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"message": "202 Accepted"}`)
})
opt := &GroupImportFileOptions{
Name: String("test"),
Path: String("path"),
File: String(tmpfile.Name()),
ParentID: Int(1),
}
_, err = client.GroupImportExport.ImportFile(opt)
if err != nil {
t.Errorf("GroupImportExport.ImportFile returned error: %v", err)
}
}