Skip to content

Commit

Permalink
fix GetDiff to use executeRaw() internally. (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktrysmt authored Jan 21, 2020
1 parent 3ae508e commit 1ce7e77
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
.DEFAULT_GOAL := help

env: ## check env for e2e testing
ifndef BITBUCKET_TEST_USERNAME
$(error `BITBUCKET_TEST_USERNAME` is not set)
endif
ifndef BITBUCKET_TEST_PASSWORD
$(error `BITBUCKET_TEST_PASSWORD` is not set)
endif
ifndef BITBUCKET_TEST_OWNER
$(error `BITBUCKET_TEST_OWNER` is not set)
endif
ifndef BITBUCKET_TEST_REPOSLUG
$(error `BITBUCKET_TEST_REPOSLUG` is not set)
endif
ifndef BITBUCKET_TEST_USERNAME
$(error `BITBUCKET_TEST_USERNAME` is not set)
endif
ifndef BITBUCKET_TEST_PASSWORD
$(error `BITBUCKET_TEST_PASSWORD` is not set)
endif
ifndef BITBUCKET_TEST_OWNER
$(error `BITBUCKET_TEST_OWNER` is not set)
endif
ifndef BITBUCKET_TEST_REPOSLUG
$(error `BITBUCKET_TEST_REPOSLUG` is not set)
endif

test: env ## run go test all
go test -v ./tests

help: ## print this help
help: ## print this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: test help
2 changes: 1 addition & 1 deletion diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Diff struct {

func (d *Diff) GetDiff(do *DiffOptions) (interface{}, error) {
urlStr := d.c.requestUrl("/repositories/%s/%s/diff/%s", do.Owner, do.RepoSlug, do.Spec)
return d.c.execute("GET", urlStr, "")
return d.c.executeRaw("GET", urlStr, "diff")
}

func (d *Diff) GetPatch(do *DiffOptions) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ktrysmt/go-bitbucket
go 1.12

require (
github.com/golang/protobuf v1.0.0 // indirect
github.com/golang/protobuf v1.0.0
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/k0kubun/pp v2.3.0+incompatible
github.com/mattn/go-colorable v0.0.9 // indirect
Expand Down
42 changes: 42 additions & 0 deletions tests/diff_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package tests

import (
"os"
"testing"

"github.com/k0kubun/pp"
"github.com/ktrysmt/go-bitbucket"
)

func TestDiff(t *testing.T) {

user := os.Getenv("BITBUCKET_TEST_USERNAME")
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
owner := os.Getenv("BITBUCKET_TEST_OWNER")
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")

if user == "" {
t.Error("BITBUCKET_TEST_USERNAME is empty.")
}

if pass == "" {
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
}

c := bitbucket.NewBasicAuth(user, pass)

spec := "master..develop"

opt := &bitbucket.DiffOptions{
Owner: owner,
RepoSlug: repo,
Spec: spec,
}
res, _ := c.Repositories.Diff.GetDiff(opt)

pp.Println(res)

if res == nil {
t.Error("It could not get the raw response.")
}
}

0 comments on commit 1ce7e77

Please sign in to comment.