Added tests for created OCI annotation time format

Signed-off-by: Andrew Block <andy.block@gmail.com>
pull/12177/head
Andrew Block 1 year ago
parent c4870d990c
commit d72b42da61
No known key found for this signature in database
GPG Key ID: 02DFE631AEF35EBC

@ -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 {

@ -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])
}
}

Loading…
Cancel
Save