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

lakectl support create repository with sample data #8628

Merged
merged 5 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 12 additions & 5 deletions cmd/lakectl/cmd/repo_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
const (
DefaultBranch = "main"

SampleDataFlag = "sample-data"

repoCreateCmdArgs = 2
)

Expand All @@ -25,29 +27,34 @@ var repoCreateCmd = &cobra.Command{
clt := getClient()
u := MustParseRepoURI("repository URI", args[0])
fmt.Println("Repository:", u)
defaultBranch, err := cmd.Flags().GetString("default-branch")
if err != nil {
DieErr(err)
}
defaultBranch := Must(cmd.Flags().GetString("default-branch"))
sampleData := Must(cmd.Flags().GetBool(SampleDataFlag))

resp, err := clt.CreateRepositoryWithResponse(cmd.Context(),
&apigen.CreateRepositoryParams{},
apigen.CreateRepositoryJSONRequestBody{
Name: u.Repository,
StorageNamespace: args[1],
DefaultBranch: &defaultBranch,
SampleData: &sampleData,
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated)
if resp.JSON201 == nil {
Die("Bad response from server", 1)
}
repo := resp.JSON201
fmt.Printf("Repository '%s' created:\nstorage namespace: %s\ndefault branch: %s\ntimestamp: %d\n", repo.Id, repo.StorageNamespace, repo.DefaultBranch, repo.CreationDate)
fmt.Printf("Repository '%s' created:\nstorage namespace: %s\ndefault branch: %s\ntimestamp: %d\n",
repo.Id, repo.StorageNamespace, repo.DefaultBranch, repo.CreationDate)
if sampleData {
fmt.Printf("sample data included\n")
}
},
}

//nolint:gochecknoinits
func init() {
repoCreateCmd.Flags().StringP("default-branch", "d", DefaultBranch, "the default branch of this repository")
repoCreateCmd.Flags().Bool(SampleDataFlag, false, "create sample data in the repository")

repoCmd.AddCommand(repoCreateCmd)
}
1 change: 1 addition & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,7 @@ lakectl repo create lakefs://my-repo s3://my-bucket
```
-d, --default-branch string the default branch of this repository (default "main")
-h, --help help for create
--sample-data create sample data in the repository
```


Expand Down
2 changes: 1 addition & 1 deletion esti/golden/lakectl_repo_create.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Repository: lakefs://${REPO}
Repository '${REPO}' created:
storage namespace: ${STORAGE}
default branch: ${BRANCH}
timestamp: <TIMESTAMP>
timestamp: <TIMESTAMP>
6 changes: 6 additions & 0 deletions esti/golden/lakectl_repo_create_sample.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Repository: lakefs://${REPO}
Repository '${REPO}' created:
storage namespace: ${STORAGE}
default branch: ${BRANCH}
timestamp: <TIMESTAMP>
sample data included
15 changes: 11 additions & 4 deletions esti/lakectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ func TestLakectlBasicRepoActions(t *testing.T) {

// Trying to delete again
RunCmdAndVerifyFailureWithFile(t, Lakectl()+" repo delete lakefs://"+repoName2+" -y", false, "lakectl_repo_delete_not_found", vars)

// Create repository with sample data
repoName3 := generateUniqueRepositoryName()
storage3 := generateUniqueStorageNamespace(repoName3)
vars = map[string]string{
"REPO": repoName3,
"STORAGE": storage3,
"BRANCH": mainBranch,
}
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+repoName3+" "+storage3+" --sample-data", false, "lakectl_repo_create_sample", vars)
Copy link
Contributor

@yonipeleg33 yonipeleg33 Feb 8, 2025

Choose a reason for hiding this comment

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

Nit: There's a command builder for lakectl tests, you can use it.
Here's an example

Copy link
Contributor Author

@nopcoder nopcoder Feb 8, 2025

Choose a reason for hiding this comment

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

  • The builder doesn't give any additional value as I see, it doesn't quote args or provide additional functionality above contact. If you still think we should replace all test run of lakectl with the builder style. Lets discuss and address in a different PR.
  • Keeping the current usage match the rest of the tests in this function.
  • Wish to replace lakectl tests (not in this PR) with something more simple like https://bitfieldconsulting.com/posts/test-scripts. It may not match all the current requirements of the current lakectl_test but I think it will make running it outside esti and modify/add more test easy.

}

func TestLakectlPreSignUpload(t *testing.T) {
Expand Down Expand Up @@ -428,7 +438,6 @@ func TestLakectlLogNoMergesWithCommitsAndMerges(t *testing.T) {

// log the commits without merges
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" log lakefs://"+repoName+"/"+mainBranch+" --no-merges", false, "lakectl_log_no_merges", vars)

}

func TestLakectlLogNoMergesAndAmount(t *testing.T) {
Expand Down Expand Up @@ -480,8 +489,8 @@ func TestLakectlLogNoMergesAndAmount(t *testing.T) {

// log the commits without merges
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" log lakefs://"+repoName+"/"+mainBranch+" --no-merges --amount=2", false, "lakectl_log_no_merges_amount", vars)

}

func TestLakectlAnnotate(t *testing.T) {
repoName := generateUniqueRepositoryName()
storage := generateUniqueStorageNamespace(repoName)
Expand Down Expand Up @@ -577,7 +586,6 @@ func TestLakectlAuthUsers(t *testing.T) {

// testing without user email for now, since it is a pain to config esti with a mail
func TestLakectlIdentity(t *testing.T) {

userId := "mike"
vars := map[string]string{
"ID": userId,
Expand Down Expand Up @@ -690,7 +698,6 @@ func TestLakectlFsUpload(t *testing.T) {
t.Run("single_file_with_recursive", func(t *testing.T) {
vars["FILE_PATH"] = "data/ro/ro_1k.0"
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" fs upload --recursive -s files/ro_1k lakefs://"+repoName+"/"+mainBranch+"/"+vars["FILE_PATH"]+" -s files/ro_1k", false, "lakectl_fs_upload", vars)

})
t.Run("dir", func(t *testing.T) {
vars["FILE_PATH"] = "data/ro/"
Expand Down
2 changes: 1 addition & 1 deletion esti/lakectl_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
)

var (
reTimestamp = regexp.MustCompile(`timestamp: \d+\n`)
reTimestamp = regexp.MustCompile(`timestamp: \d+`)
reTime = regexp.MustCompile(`\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-+]\d{4} \w{1,4}`)
reCommitID = regexp.MustCompile(`[\d|a-f]{64}`)
reShortCommitID = regexp.MustCompile(`[\d|a-f]{16}`)
Expand Down
Loading