reference icon indicating copy to clipboard operation
reference copied to clipboard

When reference.Parse returns a digest only ref?

Open liubog2008 opened this issue 11 months ago • 5 comments

I cannot see the test case in https://github.com/distribution/reference/blob/v0.6.0/reference_test.go#L14

It seems all are Named.

liubog2008 avatar Dec 19 '24 10:12 liubog2008

Parse() returns Reference. Reference is an interface type whose underlying type may or may not have a digest based on the regexp match: https://github.com/distribution/reference/blob/ff14fafe2236e51c2894ac07d4bdfc778e96d682/reference.go#L217-L223

The underlying type returned by Parse is reference https://github.com/distribution/reference/blob/ff14fafe2236e51c2894ac07d4bdfc778e96d682/reference.go#L356

The reference type implements Canonical interface so you will need to do a type assertion on it to check whether it implements Canonical interface which has a Digest method: https://github.com/distribution/reference/blob/ff14fafe2236e51c2894ac07d4bdfc778e96d682/reference.go#L142

milosgajdos avatar Dec 19 '24 17:12 milosgajdos

If the ref implements the Canonical, it also implements the Named.

liubog2008 avatar Dec 24 '24 00:12 liubog2008

https://github.com/distribution/reference/blob/ff14fafe2236e51c2894ac07d4bdfc778e96d682/reference.go#L330-L336

It seems that Parse accepts a digest only ref, but I don't know what it looks like.

liubog2008 avatar Dec 24 '24 00:12 liubog2008

Let's circle back.

Can you please explain what it is you are trying to achieve? Provide some code if possible. It's hard to explain things when there is no clear question.

milosgajdos avatar Jan 01 '25 13:01 milosgajdos

I use the Parse to parse my ref, but cannot cover all cases in UT. I just want to know a valid input which may output a unnamed Reference

liubog2008 avatar Jan 03 '25 10:01 liubog2008