Skip to content

Commit

Permalink
Add test for refs diff (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
itaiad200 authored Dec 7, 2020
1 parent 5ee62e0 commit d19107d
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion api/api_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"testing"
"time"

"github.com/treeverse/lakefs/api/gen/client/refs"

"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
Expand Down Expand Up @@ -612,7 +614,7 @@ func TestHandler_CreateBranchHandler(t *testing.T) {
clt := client.Default
clt.SetTransport(&handlerTransport{Handler: handler})

t.Run("create branch success", func(t *testing.T) {
t.Run("create branch and diff refs success", func(t *testing.T) {
ctx := context.Background()
_, err := deps.cataloger.CreateRepository(ctx, "repo1", "s3://foo1", "master")
testutil.Must(t, err)
Expand All @@ -631,6 +633,36 @@ func TestHandler_CreateBranchHandler(t *testing.T) {
if len(reference) == 0 {
t.Fatalf("branch %s creation got no reference", newBranchName)
}
path := "some/path"
buf := new(bytes.Buffer)
buf.WriteString("hello world!")
_, err = clt.Objects.UploadObject(&objects.UploadObjectParams{
Branch: newBranchName,
Content: runtime.NamedReader("content", buf),
Path: path,
Repository: "repo1",
}, bauth)
if err != nil {
t.Fatalf("unexpected error uploading object: %s", err)
}
if _, err := deps.cataloger.Commit(ctx, "repo1", "master2", "commit 1", "some_user", nil); err != nil {
t.Fatalf("failed to commit 'repo1': %s", err)
}
resp2, err := clt.Refs.DiffRefs(&refs.DiffRefsParams{
LeftRef: newBranchName,
RightRef: "master",
Repository: "repo1",
}, bauth)
if err != nil {
t.Fatalf("unexpected error diffing refs: %s", err)
}
results := resp2.GetPayload().Results
if len(results) != 1 {
t.Fatalf("unexpected length of results: %d", len(results))
}
if results[0].Path != path {
t.Fatalf("wrong result: %s", results[0].Path)
}
})

t.Run("create branch missing commit", func(t *testing.T) {
Expand Down

0 comments on commit d19107d

Please sign in to comment.