Skip to content

Commit

Permalink
Fix TestHooksSuccess (#3265)
Browse files Browse the repository at this point in the history
* bug: Fix TestHookSuccess

* Update esti/hooks_test.go

Co-authored-by: Barak Amar <barak.amar@treeverse.io>

* Fixes

Co-authored-by: Barak Amar <barak.amar@treeverse.io>
  • Loading branch information
N-o-Z and nopcoder authored May 1, 2022
1 parent f92aa77 commit 3142834
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
47 changes: 35 additions & 12 deletions esti/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"text/template"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/stretchr/testify/require"
"github.com/treeverse/lakefs/pkg/api"
)
Expand Down Expand Up @@ -42,6 +43,28 @@ func TestHooksSuccess(t *testing.T) {
})
}

func waitForListRepositoryRunsLen(ctx context.Context, t *testing.T, repo, ref string, l int) *api.ActionRunList {
var runs *api.ActionRunList
bo := backoff.NewExponentialBackOff()
bo.MaxInterval = 5 * time.Second
bo.MaxElapsedTime = 30 * time.Second
listFunc := func() error {
runsResp, err := client.ListRepositoryRunsWithResponse(ctx, repo, &api.ListRepositoryRunsParams{
Commit: api.StringPtr(ref),
})
require.NoError(t, err)
runs = runsResp.JSON200
require.NotNil(t, runs)
if len(runs.Results) == l {
return nil
}
return fmt.Errorf("run results size: %d", len(runs.Results))
}
err := backoff.Retry(listFunc, bo)
require.NoError(t, err)
return runs
}

func testCommitMerge(t *testing.T, ctx context.Context, repo string) {
const branch = "feature-1"

Expand Down Expand Up @@ -158,18 +181,18 @@ func testCommitMerge(t *testing.T, ctx context.Context, repo string) {
}, postMergeEvent)

t.Log("List repository runs", mergeRef)
runsResp, err := client.ListRepositoryRunsWithResponse(ctx, repo, &api.ListRepositoryRunsParams{
Commit: api.StringPtr(mergeRef),
})
require.NoError(t, err)
require.Equal(t, http.StatusOK, runsResp.StatusCode())
runs := runsResp.JSON200
require.Len(t, runs.Results, 1)
run := runs.Results[0]
require.Equal(t, mergeRef, run.CommitId)
require.Equal(t, "pre-merge", run.EventType)
require.Equal(t, "completed", run.Status)
require.Equal(t, "main", run.Branch)
runs := waitForListRepositoryRunsLen(ctx, t, repo, mergeRef, 2)
eventType := map[string]bool{
"pre-merge": true,
"post-merge": true,
}
for _, run := range runs.Results {
require.Equal(t, mergeRef, run.CommitId)
require.True(t, eventType[run.EventType])
eventType[run.EventType] = false
require.Equal(t, "completed", run.Status)
require.Equal(t, "main", run.Branch)
}
}

func testCreateDeleteBranch(t *testing.T, ctx context.Context, repo string) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

require golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
require golang.org/x/time v0.0.0-20220224211638-0e9765cccd65

require (
4d63.com/gochecknoglobals v0.0.0-20201008074935-acfc0b28355a // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
Expand Down Expand Up @@ -1822,6 +1821,7 @@ golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211013171255-e13a2654a71e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211101193420-4a448f8816b3 h1:VrJZAjbekhoRn7n5FBujY31gboH+iB3pdLxn3gE9FjU=
golang.org/x/net v0.0.0-20211101193420-4a448f8816b3/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180227000427-d7d64896b5ff/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down Expand Up @@ -1965,6 +1965,7 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210818153620-00dd8d7831e7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211102061401-a2f17f7b995c h1:QOfDMdrf/UwlVR0UBq2Mpr58UzNtvgJRXA4BgPfFACs=
golang.org/x/sys v0.0.0-20211102061401-a2f17f7b995c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand Down Expand Up @@ -2102,7 +2103,6 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
Expand Down

0 comments on commit 3142834

Please sign in to comment.