Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lakectl branch protection set 400 response #7590

Merged
merged 2 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cmd/lakectl/cmd/branch_protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ var branchProtectAddCmd = &cobra.Command{
rules = append(rules, apigen.BranchProtectionRule{
Pattern: args[1],
})
setResp, err := client.SetBranchProtectionRulesWithResponse(cmd.Context(), u.Repository, &apigen.SetBranchProtectionRulesParams{
IfMatch: swag.String(resp.HTTPResponse.Header.Get("ETag")),
}, rules)
params := &apigen.SetBranchProtectionRulesParams{}
etag := swag.String(resp.HTTPResponse.Header.Get("ETag"))
if etag != nil && *etag != "" {
params.IfMatch = etag
}
setResp, err := client.SetBranchProtectionRulesWithResponse(cmd.Context(), u.Repository, params, rules)
DieOnErrorOrUnexpectedStatusCode(setResp, err, http.StatusNoContent)
},
}
Expand Down
2 changes: 2 additions & 0 deletions esti/golden/lakectl_branch_protection_list.term.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
${BRANCH}

14 changes: 14 additions & 0 deletions esti/lakectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,17 @@ func TestLakectlUsage(t *testing.T) {
runCmd(t, r.Replace("{lakectl} repo list"), false, false, nil)
RunCmdAndVerifyFailureWithFile(t, r.Replace("{lakectl} usage summary"), false, "lakectl_usage_summary", vars)
}

func TestLakectlBranchProtection(t *testing.T) {
repoName := generateUniqueRepositoryName()
storage := generateUniqueStorageNamespace(repoName)
vars := map[string]string{
"REPO": repoName,
"STORAGE": storage,
"BRANCH": mainBranch,
}
r := strings.NewReplacer("{lakectl}", Lakectl(), "{repo}", repoName, "{storage}", storage, "{branch}", "main")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be consistent with how we create the lakectl command

runCmd(t, r.Replace("{lakectl} repo create lakefs://{repo} {storage}"), false, false, nil)
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" branch-protect add lakefs://"+repoName+" "+mainBranch, false, "lakectl_empty", vars)
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" branch-protect list lakefs://"+repoName, false, "lakectl_branch_protection_list.term", vars)
}
Loading