Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
Signed-off-by: Blake Pettersson <[email protected]>
  • Loading branch information
blakepettersson committed Jan 4, 2025
1 parent e05a6c1 commit cd2af52
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions reposerver/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func helmIndexRefsKey(repo string) string {
}

func ociTagsKey(repo string) string {
return fmt.Sprintf("oci-tags|%s", repo)
return "oci-tags|" + repo
}

// SetHelmIndex stores helm repository index.yaml content to cache
Expand All @@ -190,7 +190,7 @@ func (c *Cache) GetHelmIndex(repo string, indexData *[]byte) error {
func (c *Cache) SetOCITags(repo string, indexData []byte) error {
if indexData == nil {
// Logged as warning upstream
return fmt.Errorf("oci index data is nil, skipping cache")
return errors.New("oci index data is nil, skipping cache")
}
return c.cache.SetItem(
ociTagsKey(repo),
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixture/repos/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func PushChartToOCIRegistry(chartPathName, chartName, chartVersion string) {

// PushImageToOCIRegistry adds a helm chart to helm OCI registry
func PushImageToOCIRegistry(pathName, tag string) {
imagePath := fmt.Sprintf("./testdata/%s", pathName)
imagePath := "./testdata/" + pathName

errors.FailOnErr(fixture.Run(
imagePath,
Expand Down
26 changes: 13 additions & 13 deletions util/oci/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"compress/gzip"
"context"
"encoding/json"
"fmt"
"errors"
"io"
"math"
"os"
Expand Down Expand Up @@ -114,7 +114,7 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
manifestMaxExtractedSize: 10,
disableManifestMaxExtractedSize: false,
},
expectedError: fmt.Errorf("cannot extract contents of oci image with revision sha256:1b6dfd71e2b35c2f35dffc39007c2276f3c0e235cbae4c39cba74bd406174e22: could not decompress layer: error while iterating on tar reader: unexpected EOF"),
expectedError: errors.New("cannot extract contents of oci image with revision sha256:1b6dfd71e2b35c2f35dffc39007c2276f3c0e235cbae4c39cba74bd406174e22: could not decompress layer: error while iterating on tar reader: unexpected EOF"),
},
{
name: "extraction fails due to multiple layers",
Expand All @@ -130,7 +130,7 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
manifestMaxExtractedSize: 1000,
disableManifestMaxExtractedSize: false,
},
expectedError: fmt.Errorf("expected only a single oci layer, got 2"),
expectedError: errors.New("expected only a single oci layer, got 2"),
},
{
name: "extraction fails due to invalid media type",
Expand All @@ -145,7 +145,7 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
manifestMaxExtractedSize: 1000,
disableManifestMaxExtractedSize: false,
},
expectedError: fmt.Errorf("oci layer media type application/vnd.oci.image.layer.v1.tar+gzip is not in the list of allowed media types"),
expectedError: errors.New("oci layer media type application/vnd.oci.image.layer.v1.tar+gzip is not in the list of allowed media types"),
},
{
name: "extraction fails due to non-existent digest",
Expand All @@ -159,7 +159,7 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
manifestMaxExtractedSize: 1000,
disableManifestMaxExtractedSize: false,
},
expectedError: fmt.Errorf("error resolving oci repo from digest sha256:nonexistentdigest: not found"),
expectedError: errors.New("error resolving oci repo from digest sha256:nonexistentdigest: not found"),
},
{
name: "extraction with helm chart",
Expand Down Expand Up @@ -261,7 +261,7 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
c := newClientWithLock(fields.repoURL, fields.creds, globalLock, store, fields.tagsFunc, fields.allowedMediaTypes, WithImagePaths(cacheDir), WithManifestMaxExtractedSize(args.manifestMaxExtractedSize), WithDisableManifestMaxExtractedSize(args.disableManifestMaxExtractedSize))
_, _, err := c.Extract(context.Background(), sha, "non-existent-project")
require.Error(t, err)
require.EqualError(t, fmt.Errorf("error resolving oci repo from digest sha256:34a4a54b23e018edd08aadd78a126a0cedf1e70452daf0d6b36ea44253350a73: not found"), err.Error())
require.EqualError(t, errors.New("error resolving oci repo from digest sha256:34a4a54b23e018edd08aadd78a126a0cedf1e70452daf0d6b36ea44253350a73: not found"), err.Error())
},
},
},
Expand Down Expand Up @@ -351,7 +351,7 @@ func Test_nativeOCIClient_ResolveRevision(t *testing.T) {
name: "resolve digest directly",
revision: descriptor.Digest.String(),
fields: fields{repo: store, tagsFunc: func(context.Context, string) (tags []string, err error) {
return []string{}, fmt.Errorf("this should not be invoked")
return []string{}, errors.New("this should not be invoked")
}},
expectedDigest: descriptor.Digest.String(),
},
Expand All @@ -361,23 +361,23 @@ func Test_nativeOCIClient_ResolveRevision(t *testing.T) {
fields: fields{repo: store, tagsFunc: func(context.Context, string) (tags []string, err error) {
return []string{"1.0.0", "1.1.0", "1.2.0", "2.0.0"}, nil
}},
expectedError: fmt.Errorf("no version for constraints: constraint not found in 4 tags"),
expectedError: errors.New("no version for constraints: constraint not found in 4 tags"),
},
{
name: "error fetching tags",
revision: "^1.0.0",
fields: fields{repo: store, tagsFunc: func(context.Context, string) (tags []string, err error) {
return []string{}, fmt.Errorf("some random error")
return []string{}, errors.New("some random error")
}},
expectedError: fmt.Errorf("error fetching tags: failed to get tags: some random error"),
expectedError: errors.New("error fetching tags: failed to get tags: some random error"),
},
{
name: "error resolving digest",
revision: "sha256:abc123",
fields: fields{repo: store, tagsFunc: func(context.Context, string) (tags []string, err error) {
return []string{"1.0.0", "1.1.0", "1.2.0", "2.0.0"}, nil
}},
expectedError: fmt.Errorf("cannot get digest for revision sha256:abc123: not found"),
expectedError: errors.New("cannot get digest for revision sha256:abc123: not found"),
},
// new tests
{
Expand All @@ -402,15 +402,15 @@ func Test_nativeOCIClient_ResolveRevision(t *testing.T) {
fields: fields{repo: store, tagsFunc: func(context.Context, string) (tags []string, err error) {
return []string{"latest", "stable", "prod", "dev"}, nil
}},
expectedError: fmt.Errorf("no version for constraints: constraint not found in 4 tags"),
expectedError: errors.New("no version for constraints: constraint not found in 4 tags"),
},
{
name: "resolve with empty tag list",
revision: "^1.0.0",
fields: fields{repo: store, tagsFunc: func(context.Context, string) (tags []string, err error) {
return []string{}, nil
}},
expectedError: fmt.Errorf("no version for constraints: constraint not found in 0 tags"),
expectedError: errors.New("no version for constraints: constraint not found in 0 tags"),
},
}
for _, tt := range tests {
Expand Down

0 comments on commit cd2af52

Please sign in to comment.