Skip to content

Commit 474ee0b

Browse files
committed
Added UTs
1 parent be2ecb2 commit 474ee0b

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

scm/driver/azure/content_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestContentFind(t *testing.T) {
1717
gock.New("https:/dev.azure.com/").
1818
Get("/ORG/PROJ/_apis/git/repositories/REPOID/items").
1919
MatchParam("path", "README").
20+
MatchParam("versionDescriptor.version", "b1&b2").
2021
Reply(200).
2122
Type("application/json").
2223
File("testdata/content.json")
@@ -26,7 +27,7 @@ func TestContentFind(t *testing.T) {
2627
context.Background(),
2728
"REPOID",
2829
"README",
29-
"",
30+
"b1&b2",
3031
)
3132
if err != nil {
3233
t.Error(err)

scm/driver/github/content_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,35 @@ func TestContentFind(t *testing.T) {
4747
t.Log(diff)
4848
}
4949

50+
gock.New("https://api.github.com").
51+
Get("/repos/octocat/hello-world/contents/README").
52+
MatchParam("ref", "b1&b2").
53+
Reply(200).
54+
Type("application/json").
55+
SetHeaders(mockHeaders).
56+
File("testdata/content.json")
57+
58+
client = NewDefault()
59+
got, res, err = client.Contents.Find(
60+
context.Background(),
61+
"octocat/hello-world",
62+
"README",
63+
"b1&b2",
64+
)
65+
if err != nil {
66+
t.Error(err)
67+
return
68+
}
69+
70+
want = new(scm.Content)
71+
raw, _ = ioutil.ReadFile("testdata/content.json.golden")
72+
_ = json.Unmarshal(raw, want)
73+
74+
if diff := cmp.Diff(got, want); diff != "" {
75+
t.Errorf("Unexpected Results")
76+
t.Log(diff)
77+
}
78+
5079
t.Run("Request", testRequest(res))
5180
t.Run("Rate", testRate(res))
5281
}

scm/driver/gitlab/content_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,35 @@ func TestContentFind(t *testing.T) {
4848
t.Log(diff)
4949
}
5050

51+
gock.New("https://gitlab.com").
52+
Get("/api/v4/projects/diaspora/diaspora/repository/files/app/models/key.rb").
53+
MatchParam("ref", "b1&b2").
54+
Reply(200).
55+
Type("application/json").
56+
SetHeaders(mockHeaders).
57+
File("testdata/content.json")
58+
59+
client = NewDefault()
60+
got, res, err = client.Contents.Find(
61+
context.Background(),
62+
"diaspora/diaspora",
63+
"app/models/key.rb",
64+
"b1&b2",
65+
)
66+
if err != nil {
67+
t.Error(err)
68+
return
69+
}
70+
71+
want = new(scm.Content)
72+
raw, _ = ioutil.ReadFile("testdata/content.json.golden")
73+
json.Unmarshal(raw, want)
74+
75+
if diff := cmp.Diff(got, want); diff != "" {
76+
t.Errorf("Unexpected Results")
77+
t.Log(diff)
78+
}
79+
5180
t.Run("Request", testRequest(res))
5281
t.Run("Rate", testRate(res))
5382
}

scm/driver/stash/content_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ func TestContentFind(t *testing.T) {
4040
t.Errorf("Unexpected Results")
4141
t.Log(diff)
4242
}
43+
44+
gock.New("http://example.com:7990").
45+
Get("/rest/api/1.0/projects/PRJ/repos/my-repo/raw/README").
46+
MatchParam("at", "b1&b2").
47+
Reply(200).
48+
Type("text/plain").
49+
File("testdata/content.txt")
50+
51+
client, _ = New("http://example.com:7990")
52+
got, _, err = client.Contents.Find(context.Background(), "PRJ/my-repo", "README", "b1&b2")
53+
if err != nil {
54+
t.Error(err)
55+
}
56+
57+
want = new(scm.Content)
58+
raw, _ = ioutil.ReadFile("testdata/content.json.golden")
59+
_ = json.Unmarshal(raw, want)
60+
61+
if diff := cmp.Diff(got, want); diff != "" {
62+
t.Errorf("Unexpected Results")
63+
t.Log(diff)
64+
}
4365
}
4466

4567
func TestContentCreate(t *testing.T) {

0 commit comments

Comments
 (0)