forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_blobs_test.go
103 lines (82 loc) · 2.3 KB
/
git_blobs_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
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2014 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestGitService_GetBlob(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/git/blobs/s", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
fmt.Fprint(w, `{
"sha": "s",
"content": "blob content"
}`)
})
blob, _, err := client.Git.GetBlob(context.Background(), "o", "r", "s")
if err != nil {
t.Errorf("Git.GetBlob returned error: %v", err)
}
want := Blob{
SHA: String("s"),
Content: String("blob content"),
}
if !reflect.DeepEqual(*blob, want) {
t.Errorf("Blob.Get returned %+v, want %+v", *blob, want)
}
}
func TestGitService_GetBlob_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, _, err := client.Git.GetBlob(context.Background(), "%", "%", "%")
testURLParseError(t, err)
}
func TestGitService_CreateBlob(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &Blob{
SHA: String("s"),
Content: String("blob content"),
Encoding: String("utf-8"),
Size: Int(12),
}
mux.HandleFunc("/repos/o/r/git/blobs", func(w http.ResponseWriter, r *http.Request) {
v := new(Blob)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
want := input
if !reflect.DeepEqual(v, want) {
t.Errorf("Git.CreateBlob request body: %+v, want %+v", v, want)
}
fmt.Fprint(w, `{
"sha": "s",
"content": "blob content",
"encoding": "utf-8",
"size": 12
}`)
})
blob, _, err := client.Git.CreateBlob(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Git.CreateBlob returned error: %v", err)
}
want := input
if !reflect.DeepEqual(*blob, *want) {
t.Errorf("Git.CreateBlob returned %+v, want %+v", *blob, *want)
}
}
func TestGitService_CreateBlob_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, _, err := client.Git.CreateBlob(context.Background(), "%", "%", &Blob{})
testURLParseError(t, err)
}