diff --git a/pkg/registry/util.go b/pkg/registry/util.go index 822124cc4fc..8baf0852a6d 100644 --- a/pkg/registry/util.go +++ b/pkg/registry/util.go @@ -25,6 +25,8 @@ import ( "strings" "time" + helmtime "helm.sh/helm/v3/pkg/time" + "github.com/Masterminds/semver/v3" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" @@ -197,7 +199,7 @@ func generateChartOCIAnnotations(meta *chart.Metadata, test bool) map[string]str chartOCIAnnotations = addToMap(chartOCIAnnotations, ocispec.AnnotationURL, meta.Home) if !test { - chartOCIAnnotations = addToMap(chartOCIAnnotations, ocispec.AnnotationCreated, time.Now().UTC().Format(time.RFC3339)) + chartOCIAnnotations = addToMap(chartOCIAnnotations, ocispec.AnnotationCreated, helmtime.Now().UTC().Format(time.RFC3339)) } if len(meta.Sources) > 0 { diff --git a/pkg/registry/util_test.go b/pkg/registry/util_test.go index fe5eb93ce3c..fdf09360b26 100644 --- a/pkg/registry/util_test.go +++ b/pkg/registry/util_test.go @@ -19,8 +19,12 @@ package registry // import "helm.sh/helm/v3/pkg/registry" import ( "reflect" "testing" + "time" + + ocispec "github.com/opencontainers/image-spec/specs-go/v1" "helm.sh/helm/v3/pkg/chart" + helmtime "helm.sh/helm/v3/pkg/time" ) func TestGenerateOCIChartAnnotations(t *testing.T) { @@ -214,3 +218,23 @@ func TestGenerateOCIAnnotations(t *testing.T) { } } + +func TestGenerateOCICreatedAnnotations(t *testing.T) { + chart := &chart.Metadata{ + Name: "oci", + Version: "0.0.1", + } + + result := generateOCIAnnotations(chart, false) + + // Check that created annotation exists + if _, ok := result[ocispec.AnnotationCreated]; !ok { + t.Errorf("%s annotation not created", ocispec.AnnotationCreated) + } + + // Verify value of created artifact in RFC3339 format + if _, err := helmtime.Parse(time.RFC3339, result[ocispec.AnnotationCreated]); err != nil { + t.Errorf("%s annotation with value '%s' not in RFC3339 format", ocispec.AnnotationCreated, result[ocispec.AnnotationCreated]) + } + +}