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

2898 lakectl annotate output has superfluous spaces and blank lines #3007

Conversation

itaidavid
Copy link
Contributor

lakectl annotate output:
Removed line break at the beginning of output line
Removed padding from commit message field

@itaidavid itaidavid added the include-changelog PR description should be included in next release changelog label Mar 3, 2022
@itaidavid itaidavid linked an issue Mar 3, 2022 that may be closed by this pull request
@@ -122,6 +122,7 @@ func sanitize(output string, vars map[string]string) string {
s = normalizeRandomObjectKey(s, vars["STORAGE"])
s = normalizeCommitID(s)
s = normalizeChecksum(s)
s = normalizeShortCommitID(s)
return strings.ReplaceAll(s, "\r\n", "\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

general note - if we do this one first, there is no need to keep the regexp patterns \r?\n compatible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nopcoder - not sure I understand this one. Can you please specify what is 'this' in '... this one first'?

Copy link
Contributor

Choose a reason for hiding this comment

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

replace new lines before running all the regexp patterns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

// create fresh repo with 'main' branch
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+repoName+" "+storage, false, "lakectl_repo_create", vars)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion to use the table driven format - it will structure the following code and will report each one as a test:

	tests := []struct {
		Name   string
		Cmd    string
		Golden string
		Vars   map[string]string
	}{
		{
			Name:   "log not found",
			Cmd:    "log lakefs://" + repoName + "/" + mainBranch,
			Golden: "lakectl_log_404",
			Vars:   map[string]string{"REPO": repoName, "STORAGE": storage, "BRANCH": mainBranch},
		},
	}
	for _, tt := range tests {
		t.Run(tt.Name, func(t *testing.T) {
			RunCmdAndVerifyFailureWithFile(t, Lakectl()+" "+tt.Cmd, false, tt.Golden, vars)
		})
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nopcoder - I like the idea, but I think it is too large of a change to be included with this bug fix.
How about I create an issue for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened #3021 to handle this

@@ -199,6 +201,11 @@ func normalizeCommitID(output string) string {
return string(s)
}

func normalizeShortCommitID(output string) string {
s := shortCommitIDRegExp.ReplaceAll([]byte(output), []byte("<COMMIT_ID_16>"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Relevant for other places, Go supply the 'string' variant - use: ReplaceAllString

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as for the previous one - Let's have it as a different PR, along with the refactoring to table-driven. Something like 'Lakectl Test Refactoring'. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

client := getClient()
pfx := api.PaginationPrefix(*pathURI.Path)
context := cmd.Context()
resp, err := client.ListObjectsWithResponse(context, pathURI.Repository, pathURI.Ref, &api.ListObjectsParams{Prefix: &pfx})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
const delimiter = "/"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Contributor Author

@itaidavid itaidavid Mar 9, 2022

Choose a reason for hiding this comment

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

Not really necessary, but it is also used the same way in other commands (lakectl fs)
I refactored it to be a const in common_helpers

@@ -29,23 +28,36 @@ var annotateCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
pathURI := MustParsePathURI("path", args[0])
recursive, _ := cmd.Flags().GetBool("recursive")
Copy link
Contributor

Choose a reason for hiding this comment

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

can make "recursive" const as being used for command registration (line 97) and value retrieval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will "break" the way we register other flags, including "recursive" in lakectl fs commands. If we change it in all places it interfere with the readability of the commands regsitration, so I think it is better to leave it like that.
@Jonathan-Rosenberg - WDYT?

Copy link
Contributor

@Jonathan-Rosenberg Jonathan-Rosenberg Mar 10, 2022

Choose a reason for hiding this comment

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

Interesting... I did see that we use string literals and not variables when defining flags and retrieving their values, but is it a good practice?
Anyway it's not a deal breaker so we can leave it that way.

Copy link
Contributor

@Jonathan-Rosenberg Jonathan-Rosenberg left a comment

Choose a reason for hiding this comment

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

Noice

itaidavid and others added 5 commits March 9, 2022 12:46
Co-authored-by: Idan Novogroder <43949240+idanovo@users.noreply.github.com>
Co-authored-by: talSofer <tal.sofer@treeverse.io>
Co-authored-by: shimi9276 <71839784+shimi9276@users.noreply.github.com>
Copy link
Contributor

@nopcoder nopcoder left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -32,6 +32,11 @@ var ErrInvalidValueInList = errors.New("empty string in list")

var accessKeyRegexp = regexp.MustCompile(`^AKIA[I|J][A-Z0-9]{14}Q$`)

// const values used by lakectl commands
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove this one - we are in common_helpers under lakectl

@@ -32,6 +32,11 @@ var ErrInvalidValueInList = errors.New("empty string in list")

var accessKeyRegexp = regexp.MustCompile(`^AKIA[I|J][A-Z0-9]{14}Q$`)

// const values used by lakectl commands
const (
Copy link
Contributor

Choose a reason for hiding this comment

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

general note - not actionable to this pr - but it looks like we have a lot of 'const' blocks here

@itaidavid itaidavid merged commit 2c8c7aa into master Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include-changelog PR description should be included in next release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: lakectl annotate output has superfluous spaces and blank lines
3 participants