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

feat: support deleting a manifest from a remote registry #506

Merged
merged 19 commits into from
Sep 14, 2022

Conversation

yuehaoliang
Copy link
Contributor

Resolve #473

Signed-off-by: Haoliang Yue yuehaoliang@microsoft.com

Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2022

Codecov Report

Merging #506 (0937ff2) into main (551aca4) will increase coverage by 0.96%.
The diff coverage is 100.00%.

❗ Current head 0937ff2 differs from pull request most recent head e6e930b. Consider uploading reports for the commit e6e930b to get more accurate results

@@            Coverage Diff             @@
##             main     #506      +/-   ##
==========================================
+ Coverage   71.37%   72.33%   +0.96%     
==========================================
  Files          12       13       +1     
  Lines         489      506      +17     
==========================================
+ Hits          349      366      +17     
  Misses        112      112              
  Partials       28       28              
Impacted Files Coverage Δ
cmd/oras/internal/option/confirmation.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
cmd/oras/internal/util/util.go Outdated Show resolved Hide resolved
cmd/oras/internal/util/util.go Outdated Show resolved Hide resolved
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
cmd/oras/manifest/delete.go Outdated Show resolved Hide resolved
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
@shizhMSFT shizhMSFT added this to the v0.15.0 milestone Sep 8, 2022
cmd/oras/manifest/delete.go Outdated Show resolved Hide resolved
cmd/oras/manifest/delete.go Show resolved Hide resolved
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
fs.BoolVarP(&opts.Confirmed, "yes", "y", false, "do not prompt for confirmation")
}

func (opts *Confirmation) AskForConfirmation(message string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest having io.Writer passed in for better unit tests.

Suggested change
func (opts *Confirmation) AskForConfirmation(message string) (bool, error) {
func (opts *Confirmation) AskForConfirmation(w io.Writer, prompt string) (bool, error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggest having io.Writer passed in for better unit tests.

I found a different approach to test a func with fmt.Scanln() in its body. Details are shown below, not sure which way makes more sense.

cmd/oras/internal/option/confirmation.go Outdated Show resolved Hide resolved
fmt.Print(message)

var response string
if _, err := scanln(&response); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Try fmt.Fscanln

Copy link
Contributor Author

@yuehaoliang yuehaoliang Sep 14, 2022

Choose a reason for hiding this comment

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

I wrote in this way because in the unit test, I can easily override the scanln() func.

var scanln func(a ...any) (n int, err error) = fmt.Scanln
func AskForConfirmation() {
	var response string
	scanln(&response)
}

Then, in the unit test, I can do things like.

TestConfirmation_AskForConfirmation(t *testing.T) {
	reset := func(input string) {
		scanln = func(a ...any) (n int, err error) {
			*a[0].(*string) = input
			return len([]byte(input)), nil
		}
	}
	reset("yes")
	// test for user input "yes"
	reset("no")
	// test for user input "no"
}

Compare to introducing w io.Writer to the func, it is a different way that I found to handle fmt.Scanln(). I think it's good, does it make sense to you? @shizhMSFT

Copy link
Contributor

Choose a reason for hiding this comment

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

The way of doing var scanln is too hacky. Since it is just for unit test, it does not worth it.

Copy link
Contributor Author

@yuehaoliang yuehaoliang Sep 14, 2022

Choose a reason for hiding this comment

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

The way of doing var scanln is too hacky. Since it is just for unit test, it does not worth it.

No problem, will change to use w io.Writer and fmt.Fscanln().

cmd/oras/internal/option/confirmation.go Outdated Show resolved Hide resolved
cmd/oras/manifest/delete.go Outdated Show resolved Hide resolved
cmd/oras/manifest/delete.go Outdated Show resolved Hide resolved
Example - Delete a manifest by digest '99e4703fbf30916f549cd6bfa9cdbab614b5392fbe64fdee971359a77073cdf9' from repository 'locahost:5000/hello':
oras manifest delete localhost:5000/hello@sha:99e4703fbf30916f549cd6bfa9cdbab614b5392fbe64fdee971359a77073cdf9
`,
Args: cobra.ExactArgs(1),
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Can we delete multiple manifests at the same time?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@yuehaoliang-microsoft Please create an issue for this question, and only address it in another PR after being well discussed.

Copy link
Contributor Author

@yuehaoliang yuehaoliang Sep 14, 2022

Choose a reason for hiding this comment

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

@yuehaoliang-microsoft Please create an issue for this question, and only address it in another PR after being well discussed.

Created issue #560 to follow up deleting multiple manifest in a single command.

cmd/oras/manifest/delete.go Outdated Show resolved Hide resolved
cmd/oras/manifest/delete.go Outdated Show resolved Hide resolved
cmd/oras/manifest/delete.go Outdated Show resolved Hide resolved
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

cmd/oras/internal/option/confirmation.go Show resolved Hide resolved
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@shizhMSFT shizhMSFT merged commit 5632951 into oras-project:main Sep 14, 2022
TerryHowe pushed a commit to TerryHowe/oras that referenced this pull request Feb 2, 2023
…t#506)

Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Command to delete a manifest from a remote registry
4 participants