From 4f37189b8811f2a44e9ca8d0c925440fd08230af Mon Sep 17 00:00:00 2001 From: Roi Martin Date: Fri, 24 Nov 2023 11:18:58 +0100 Subject: [PATCH] internal/urlutil: fix naming convention in tests --- internal/urlutil/urlutil_test.go | 78 ++++++++++++++++---------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/internal/urlutil/urlutil_test.go b/internal/urlutil/urlutil_test.go index 72652ad..2d1b705 100644 --- a/internal/urlutil/urlutil_test.go +++ b/internal/urlutil/urlutil_test.go @@ -67,7 +67,7 @@ func TestGet_file(t *testing.T) { } } -func TestGet_HTTP(t *testing.T) { +func TestGet_http(t *testing.T) { tests := []struct { name string handlerFunc func(http.ResponseWriter, *http.Request) @@ -115,7 +115,7 @@ func TestGet_HTTP(t *testing.T) { } } -func TestGetOCI(t *testing.T) { +func TestGet_oci(t *testing.T) { tests := []struct { name string file string @@ -174,43 +174,7 @@ func TestGetOCI(t *testing.T) { } } -func pushArtifact(reg, name, tag string) error { - fs, err := file.New("") - if err != nil { - return fmt.Errorf("create file store: %w", err) - } - defer fs.Close() - - desc, err := fs.Add(context.Background(), name, "application/vnd.test.file", "") - if err != nil { - return fmt.Errorf("add file: %w", err) - } - - opts := oras.PackManifestOptions{ - Layers: []ocispec.Descriptor{desc}, - } - descManifest, err := oras.PackManifest(context.Background(), fs, oras.PackManifestVersion1_1_RC4, "application/vnd.test.manifest", opts) - if err != nil { - return fmt.Errorf("pack manifest: %w", err) - } - - if err := fs.Tag(context.Background(), descManifest, tag); err != nil { - return fmt.Errorf("tag artifact: %w", err) - } - - repo, err := remote.NewRepository(reg + "/" + name) - if err != nil { - return fmt.Errorf("new repository: %w", err) - } - repo.PlainHTTP = true - - if _, err := oras.Copy(context.Background(), fs, tag, repo, tag, oras.DefaultCopyOptions); err != nil { - return fmt.Errorf("copy artifact: %w", err) - } - return nil -} - -func TestGet_invalid_URL(t *testing.T) { +func TestGet_invalid_url(t *testing.T) { tests := []struct { name string rawURL string @@ -261,3 +225,39 @@ func TestGet_invalid_URL(t *testing.T) { }) } } + +func pushArtifact(reg, name, tag string) error { + fs, err := file.New("") + if err != nil { + return fmt.Errorf("create file store: %w", err) + } + defer fs.Close() + + desc, err := fs.Add(context.Background(), name, "application/vnd.test.file", "") + if err != nil { + return fmt.Errorf("add file: %w", err) + } + + opts := oras.PackManifestOptions{ + Layers: []ocispec.Descriptor{desc}, + } + descManifest, err := oras.PackManifest(context.Background(), fs, oras.PackManifestVersion1_1_RC4, "application/vnd.test.manifest", opts) + if err != nil { + return fmt.Errorf("pack manifest: %w", err) + } + + if err := fs.Tag(context.Background(), descManifest, tag); err != nil { + return fmt.Errorf("tag artifact: %w", err) + } + + repo, err := remote.NewRepository(reg + "/" + name) + if err != nil { + return fmt.Errorf("new repository: %w", err) + } + repo.PlainHTTP = true + + if _, err := oras.Copy(context.Background(), fs, tag, repo, tag, oras.DefaultCopyOptions); err != nil { + return fmt.Errorf("copy artifact: %w", err) + } + return nil +}