Skip to content

Commit

Permalink
Added tests for created OCI annotation time format
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Block <andy.block@gmail.com>
  • Loading branch information
sabre1041 committed Jul 4, 2023
1 parent c4870d9 commit d72b42d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/registry/util.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions pkg/registry/util_test.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -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])
}

}

0 comments on commit d72b42d

Please sign in to comment.