You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-scm/scm/driver/gitee/org_test.go

109 lines
2.4 KiB
Go

// Copyright 2017 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gitee
import (
"context"
"encoding/json"
"io/ioutil"
"testing"
"git.awesome-for.me/liuzhiguo/go-scm/scm"
"github.com/google/go-cmp/cmp"
"github.com/h2non/gock"
)
func TestOrganizationFind(t *testing.T) {
defer gock.Off()
gock.New("https://gitee.com/api/v5").
Get("/orgs/kit101-personal").
Reply(200).
Type("application/json").
SetHeaders(mockHeaders).
File("testdata/org.json")
client := NewDefault()
got, res, err := client.Organizations.Find(context.Background(), "kit101-personal")
if err != nil {
t.Error(err)
return
}
want := new(scm.Organization)
raw, _ := ioutil.ReadFile("testdata/org.json.golden")
json.Unmarshal(raw, want)
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}
t.Run("Request", testRequest(res))
}
func TestOrganizationFindMembership(t *testing.T) {
defer gock.Off()
gock.New("https://gitee.com/api/v5").
Get("/orgs/kit101-personal/memberships/kit101").
Reply(200).
Type("application/json").
SetHeaders(mockHeaders).
File("testdata/membership.json")
client := NewDefault()
got, res, err := client.Organizations.FindMembership(context.Background(), "kit101-personal", "kit101")
if err != nil {
t.Error(err)
return
}
want := new(scm.Membership)
raw, _ := ioutil.ReadFile("testdata/membership.json.golden")
json.Unmarshal(raw, want)
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}
t.Run("Request", testRequest(res))
}
func TestOrganizationList(t *testing.T) {
defer gock.Off()
gock.New("https://gitee.com/api/v5").
Get("/user/orgs").
MatchParam("page", "1").
MatchParam("per_page", "3").
Reply(200).
Type("application/json").
SetHeaders(mockHeaders).
SetHeaders(mockPageHeaders).
File("testdata/orgs.json")
client := NewDefault()
got, res, err := client.Organizations.List(context.Background(), scm.ListOptions{Size: 3, Page: 1})
if err != nil {
t.Error(err)
return
}
want := []*scm.Organization{}
raw, _ := ioutil.ReadFile("testdata/orgs.json.golden")
json.Unmarshal(raw, &want)
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}
t.Run("Request", testRequest(res))
t.Run("Page", testPage(res))
}