From b3f8a616695c88a8b8e9d1608d379cd1c672f8a9 Mon Sep 17 00:00:00 2001 From: Itai Admi Date: Fri, 22 Mar 2024 18:41:02 +0200 Subject: [PATCH 1/2] Fix lakectl branch protection set 400 response --- cmd/lakectl/cmd/branch_protect.go | 9 ++++++--- .../lakectl_branch_protection_list.term.golden | 2 ++ esti/lakectl_test.go | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 esti/golden/lakectl_branch_protection_list.term.golden diff --git a/cmd/lakectl/cmd/branch_protect.go b/cmd/lakectl/cmd/branch_protect.go index 9005b57c3a3..2079011de74 100644 --- a/cmd/lakectl/cmd/branch_protect.go +++ b/cmd/lakectl/cmd/branch_protect.go @@ -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) }, } diff --git a/esti/golden/lakectl_branch_protection_list.term.golden b/esti/golden/lakectl_branch_protection_list.term.golden new file mode 100644 index 00000000000..a4dbeaa7d5f --- /dev/null +++ b/esti/golden/lakectl_branch_protection_list.term.golden @@ -0,0 +1,2 @@ +${BRANCH} + diff --git a/esti/lakectl_test.go b/esti/lakectl_test.go index 1ed9ca04627..af27dcd715a 100644 --- a/esti/lakectl_test.go +++ b/esti/lakectl_test.go @@ -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") + 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) +} From 3829459835a0ff2ce949aceede792ba3a90fbf98 Mon Sep 17 00:00:00 2001 From: Itai Admi Date: Sun, 24 Mar 2024 10:53:29 +0200 Subject: [PATCH 2/2] pr comments --- esti/lakectl_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esti/lakectl_test.go b/esti/lakectl_test.go index af27dcd715a..ece5cd72cd0 100644 --- a/esti/lakectl_test.go +++ b/esti/lakectl_test.go @@ -820,8 +820,8 @@ func TestLakectlBranchProtection(t *testing.T) { "STORAGE": storage, "BRANCH": mainBranch, } - r := strings.NewReplacer("{lakectl}", Lakectl(), "{repo}", repoName, "{storage}", storage, "{branch}", "main") - runCmd(t, r.Replace("{lakectl} repo create lakefs://{repo} {storage}"), false, false, nil) + RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+repoName+" "+storage, false, "lakectl_repo_create", vars) + 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) }