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/bitbucket/org_test.go

70 lines
1.5 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 bitbucket
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://api.bitbucket.org").
Get("/2.0/workspaces/atlassian").
Reply(200).
Type("application/json").
File("testdata/team.json")
client, _ := New("https://api.bitbucket.org")
got, _, err := client.Organizations.Find(context.Background(), "atlassian")
if err != nil {
t.Error(err)
}
want := new(scm.Organization)
raw, _ := ioutil.ReadFile("testdata/team.json.golden")
json.Unmarshal(raw, want)
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}
}
func TestOrganizationList(t *testing.T) {
defer gock.Off()
gock.New("https://api.bitbucket.org").
Get("/2.0/workspaces").
MatchParam("pagelen", "30").
MatchParam("page", "1").
Reply(200).
Type("application/json").
File("testdata/teams.json")
client, _ := New("https://api.bitbucket.org")
got, _, err := client.Organizations.List(context.Background(), scm.ListOptions{Size: 30, Page: 1})
if err != nil {
t.Error(err)
}
want := []*scm.Organization{}
raw, _ := ioutil.ReadFile("testdata/teams.json.golden")
json.Unmarshal(raw, &want)
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}
}