Skip to content

Commit

Permalink
with sleeping
Browse files Browse the repository at this point in the history
  • Loading branch information
ItamarYuran committed Jan 15, 2025
1 parent 15212df commit 3d27ed3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
26 changes: 15 additions & 11 deletions esti/lakectl_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/treeverse/lakefs/pkg/block"
Expand Down Expand Up @@ -507,6 +508,8 @@ func TestLakectlLocal_commitProtectedBranch(t *testing.T) {
}
runCmd(t, Lakectl()+" repo create lakefs://"+vars["REPO"]+" "+vars["STORAGE"], false, false, vars)
runCmd(t, Lakectl()+" branch-protect add lakefs://"+vars["REPO"]+"/ '*'", false, false, vars)
// sleep in order to overcome branch-protect caching problem
time.Sleep(10 * time.Second)
// Cloning local dir
RunCmdAndVerifyContainsText(t, Lakectl()+" local clone lakefs://"+vars["REPO"]+"/"+vars["BRANCH"]+"/ "+vars["LOCAL_DIR"], false, "Successfully cloned lakefs://${REPO}/${REF}/ to ${LOCAL_DIR}.", vars)
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+vars["LOCAL_DIR"], false, "No diff found", vars)
Expand All @@ -515,7 +518,6 @@ func TestLakectlLocal_commitProtectedBranch(t *testing.T) {
require.NoError(t, err)
require.NoError(t, fd.Close())
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+vars["LOCAL_DIR"], false, "local ║ added ║ test.txt", vars)

// Try to commit local dir, expect failure
RunCmdAndVerifyFailureContainsText(t, Lakectl()+" local commit -m test "+vars["LOCAL_DIR"], false, "cannot write to protected branch", vars)
}
Expand All @@ -531,31 +533,33 @@ func TestLakectlLocal_RmCommitProtectedBranch(t *testing.T) {
require.NoError(t, err)
file := "ro_1k.0"

variables := map[string]string{
vars := map[string]string{
"REPO": repoName,
"STORAGE": storage,
"BRANCH": mainBranch,
"REF": mainBranch,
"LOCAL_DIR": dataDir,
"FILE_PATH": file,
}
runCmd(t, Lakectl()+" repo create lakefs://"+variables["REPO"]+" "+variables["STORAGE"], false, false, variables)
runCmd(t, Lakectl()+" repo create lakefs://"+vars["REPO"]+" "+vars["STORAGE"], false, false, vars)

// Cloning local dir
RunCmdAndVerifyContainsText(t, Lakectl()+" local clone lakefs://"+variables["REPO"]+"/"+variables["BRANCH"]+"/ "+variables["LOCAL_DIR"], false, "Successfully cloned lakefs://${REPO}/${REF}/ to ${LOCAL_DIR}.", variables)
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+variables["LOCAL_DIR"], false, "No diff found", variables)
RunCmdAndVerifyContainsText(t, Lakectl()+" local clone lakefs://"+vars["REPO"]+"/"+vars["BRANCH"]+"/ "+vars["LOCAL_DIR"], false, "Successfully cloned lakefs://${REPO}/${REF}/ to ${LOCAL_DIR}.", vars)
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+vars["LOCAL_DIR"], false, "No diff found", vars)

// locally add a file and commit
fd, err = os.Create(filepath.Join(variables["LOCAL_DIR"], variables["FILE_PATH"]))
fd, err = os.Create(filepath.Join(vars["LOCAL_DIR"], vars["FILE_PATH"]))
require.NoError(t, err)
require.NoError(t, fd.Close())
RunCmdAndVerifyContainsText(t, Lakectl()+" local commit "+variables["LOCAL_DIR"]+" -m test", false, "Commit for branch \""+variables["BRANCH"]+"\" completed.", variables)
runCmd(t, Lakectl()+" branch-protect add lakefs://"+variables["REPO"]+"/ '*'", false, false, variables)
RunCmdAndVerifyContainsText(t, Lakectl()+" local commit "+vars["LOCAL_DIR"]+" -m test", false, "Commit for branch \""+vars["BRANCH"]+"\" completed.", vars)
runCmd(t, Lakectl()+" branch-protect add lakefs://"+vars["REPO"]+"/ '*'", false, false, vars)
// sleep in order to overcome branch-protect caching problem
time.Sleep(10 * time.Second)

// Try delete file from local dir and then commit
require.NoError(t, os.Remove(filepath.Join(variables["LOCAL_DIR"], variables["FILE_PATH"])))
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+variables["LOCAL_DIR"], false, "local ║ removed ║ "+variables["FILE_PATH"], variables)
RunCmdAndVerifyFailureContainsText(t, Lakectl()+" local commit -m test "+variables["LOCAL_DIR"], false, "cannot write to protected branch", variables)
require.NoError(t, os.Remove(filepath.Join(vars["LOCAL_DIR"], vars["FILE_PATH"])))
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+vars["LOCAL_DIR"], false, "local ║ removed ║ "+vars["FILE_PATH"], vars)
RunCmdAndVerifyFailureContainsText(t, Lakectl()+" local commit -m test "+vars["LOCAL_DIR"], false, "cannot write to protected branch", vars)
}

func TestLakectlLocal_commit(t *testing.T) {
Expand Down
23 changes: 12 additions & 11 deletions esti/lakectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,29 +738,30 @@ func TestLakectlFsUpload_protectedBranch(t *testing.T) {
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+vars["REPO"]+" "+vars["STORAGE"], false, "lakectl_repo_create", vars)
runCmd(t, Lakectl()+" branch-protect add lakefs://"+vars["REPO"]+"/ '*'", false, false, vars)
RunCmdAndVerifyContainsText(t, Lakectl()+" branch-protect list lakefs://"+vars["REPO"]+"/ ", false, "*", vars)

// sleep in order to overcome branch-protect caching problem
time.Sleep(10 * time.Second)
vars["FILE_PATH"] = "ro_1k.0"
RunCmdAndVerifyFailure(t, Lakectl()+" fs upload lakefs://"+vars["REPO"]+"/"+vars["BRANCH"]+"/"+vars["FILE_PATH"]+" -s files/ro_1k", false, "cannot write to protected branch\n403 Forbidden\n", vars)
}

func TestLakectlFsRm_protectedBranch(t *testing.T) {
repoName := generateUniqueRepositoryName()
storage := generateUniqueStorageNamespace(repoName)
variables := map[string]string{
vars := map[string]string{
"REPO": repoName,
"STORAGE": storage,
"BRANCH": mainBranch,
}

RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+variables["REPO"]+" "+variables["STORAGE"], false, "lakectl_repo_create", variables)
variables["FILE_PATH"] = "ro_1k.0"
runCmd(t, Lakectl()+" fs upload lakefs://"+variables["REPO"]+"/"+variables["BRANCH"]+"/"+variables["FILE_PATH"]+" -s files/ro_1k", false, false, variables)
runCmd(t, Lakectl()+" commit lakefs://"+variables["REPO"]+"/"+variables["BRANCH"]+" --allow-empty-message -m \" \"", false, false, variables)
runCmd(t, Lakectl()+" branch-protect add lakefs://"+variables["REPO"]+"/ '*'", false, false, variables)
RunCmdAndVerifyContainsText(t, Lakectl()+" branch-protect list lakefs://"+variables["REPO"]+"/ ", false, "*", variables)
variables["FILE_PATH2"] = "ro_2k.0"
RunCmdAndVerifyFailure(t, Lakectl()+" fs upload lakefs://"+variables["REPO"]+"/"+variables["BRANCH"]+"/"+variables["FILE_PATH2"]+" -s files/ro_1k", false, "cannot write to protected branch\n403 Forbidden\n", variables)
RunCmdAndVerifyFailure(t, Lakectl()+" fs rm lakefs://"+variables["REPO"]+"/"+variables["BRANCH"]+"/"+variables["FILE_PATH"], false, "cannot write to protected branch\n403 Forbidden\n", variables)
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+vars["REPO"]+" "+vars["STORAGE"], false, "lakectl_repo_create", vars)
vars["FILE_PATH"] = "ro_1k.0"
runCmd(t, Lakectl()+" fs upload lakefs://"+vars["REPO"]+"/"+vars["BRANCH"]+"/"+vars["FILE_PATH"]+" -s files/ro_1k", false, false, vars)
runCmd(t, Lakectl()+" commit lakefs://"+vars["REPO"]+"/"+vars["BRANCH"]+" --allow-empty-message -m \" \"", false, false, vars)
runCmd(t, Lakectl()+" branch-protect add lakefs://"+vars["REPO"]+"/ '*'", false, false, vars)
// sleep in order to overcome branch-protect caching problem
time.Sleep(10 * time.Second)
RunCmdAndVerifyContainsText(t, Lakectl()+" branch-protect list lakefs://"+vars["REPO"]+"/ ", false, "*", vars)
RunCmdAndVerifyFailure(t, Lakectl()+" fs rm lakefs://"+vars["REPO"]+"/"+vars["BRANCH"]+"/"+vars["FILE_PATH"], false, "cannot write to protected branch\n403 Forbidden\n", vars)
}

func TestLakectlFsPresign(t *testing.T) {
Expand Down

0 comments on commit 3d27ed3

Please sign in to comment.