Skip to content

Commit

Permalink
testing the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ItamarYuran committed Jan 8, 2025
1 parent cce44f3 commit 36d9215
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions esti/lakectl_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,111 @@ func TestLakectlLocal_pull(t *testing.T) {
}
}

func TestLakectlLocal_commitProtetedBranch(t *testing.T) {
tmpDir := t.TempDir()
fd, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)
require.NoError(t, fd.Close())
repoName := generateUniqueRepositoryName()
storage := generateUniqueStorageNamespace(repoName)
vars := map[string]string{
"REPO": repoName,
"STORAGE": storage,
"BRANCH": mainBranch,
"REF": mainBranch,
"PREFIX": "",
}

runCmd(t, Lakectl()+" repo create lakefs://"+repoName+" "+storage, false, false, vars)
runCmd(t, Lakectl()+" log lakefs://"+repoName+"/"+mainBranch, false, false, vars)
runCmd(t, Lakectl()+" branch-protect add lakefs://"+repoName+"/ "+mainBranch, false, false, vars)
prefix := "images"
objects := []string{
"ro_1k.1",
"ro_1k.2",
"ro_1k.3",
prefix + "/1.png",
prefix + "/2.png",
prefix + "/3.png",
prefix + "/subdir/1.png",
prefix + "/subdir/2.png",
prefix + "/subdir/3.png",
}

tests := []struct {
name string
prefix string
presign bool
}{
{
name: "root",
prefix: "",
presign: false,
},
{
name: "root-presign",
prefix: "",
presign: true,
},
{
name: prefix,
prefix: prefix,
presign: false,
},
{
name: prefix + "-presign",
prefix: prefix,
presign: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.presign {
// Skip due to bug on Azure https://github.com/treeverse/lakeFS/issues/6426
requireBlockstoreType(t, block.BlockstoreTypeS3, block.BlockstoreTypeGS)
}
dataDir, err := os.MkdirTemp(tmpDir, "")
require.NoError(t, err)
deleted := prefix + "/subdir/deleted.png"

localCreateTestData(t, vars, append(objects, deleted))

runCmd(t, Lakectl()+" branch create lakefs://"+repoName+"/"+tt.name+" --source lakefs://"+repoName+"/"+mainBranch, false, false, vars)

vars["LOCAL_DIR"] = dataDir
vars["PREFIX"] = ""
vars["BRANCH"] = tt.name
vars["REF"] = tt.name
presign := fmt.Sprintf(" --pre-sign=%v ", tt.presign)
RunCmdAndVerifyContainsText(t, Lakectl()+" local clone lakefs://"+repoName+"/"+vars["BRANCH"]+"/"+vars["PREFIX"]+presign+dataDir, false, "Successfully cloned lakefs://${REPO}/${REF}/${PREFIX} to ${LOCAL_DIR}.", vars)

RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+dataDir, false, "No diff found", vars)

// Modify local folder - add and remove files
require.NoError(t, os.MkdirAll(filepath.Join(dataDir, "subdir"), os.ModePerm))
require.NoError(t, os.MkdirAll(filepath.Join(dataDir, "subdir-a"), os.ModePerm))
fd, err = os.Create(filepath.Join(dataDir, "subdir", "test.txt"))
require.NoError(t, err)
fd, err = os.Create(filepath.Join(dataDir, "subdir-a", "test.txt"))
require.NoError(t, err)
fd, err = os.Create(filepath.Join(dataDir, "test.txt"))
require.NoError(t, err)
require.NoError(t, fd.Close())
require.NoError(t, os.Remove(filepath.Join(dataDir, deleted)))

RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+dataDir, false, "local ║ added ║ test.txt", vars)
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+dataDir, false, "local ║ added ║ subdir/test.txt", vars)
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+dataDir, false, "local ║ added ║ subdir-a/test.txt", vars)

// Commit changes to branch
RunCmdAndVerifyContainsText(t, Lakectl()+" local commit -m test"+presign+dataDir, false, "cannot write to protected branch", vars)

// Check no diff after commit
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+dataDir, false, "No diff found", vars)
})
}

}
func TestLakectlLocal_commit(t *testing.T) {
tmpDir := t.TempDir()
fd, err := os.CreateTemp(tmpDir, "")
Expand Down

0 comments on commit 36d9215

Please sign in to comment.