Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 committed Jan 18, 2024
1 parent a415f03 commit e689e50
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmd/oras/internal/option/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (

var (
errAnnotationConflict = errors.New("`--annotation` and `--annotation-file` cannot be both specified")
errAnnotationFormat = errors.New("missing key in `--annotation` flag")
errAnnotationFormat = errors.New("annotation value doesn't match the required format")
errAnnotationDuplication = errors.New("duplicate annotation key")
errPathValidation = errors.New("absolute file path detected. If it's intentional, use --disable-path-validation flag to skip this check")
)
Expand Down Expand Up @@ -112,10 +112,7 @@ func (opts *Packer) LoadManifestAnnotations() (annotations map[string]map[string
if len(opts.ManifestAnnotations) != 0 {
annotations = make(map[string]map[string]string)
if err = parseAnnotationFlags(opts.ManifestAnnotations, annotations); err != nil {
return nil, &oerrors.Error{
Err: errors.New("annotation value doesn't match the required format"),
Recommendation: `Please use the correct format in the flag: --annotation "key=value"`,
}
return nil, err
}
}
return
Expand All @@ -137,7 +134,10 @@ func parseAnnotationFlags(flags []string, annotations map[string]map[string]stri
for _, anno := range flags {
key, val, success := strings.Cut(anno, "=")
if !success {
return fmt.Errorf("%w: %s", errAnnotationFormat, anno)
return &oerrors.Error{
Err: fmt.Errorf("%w", errAnnotationFormat),
Recommendation: `Please use the correct format in the flag: --annotation "key=value"`,
}
}
if _, ok := manifestAnnotations[key]; ok {
return fmt.Errorf("%w: %v, ", errAnnotationDuplication, key)
Expand Down

0 comments on commit e689e50

Please sign in to comment.