From a3d01052c92bec15e0bc22da1ffc9df72488b94d Mon Sep 17 00:00:00 2001 From: Case Wylie Date: Mon, 7 Aug 2023 10:52:59 -0400 Subject: [PATCH 1/8] refactor DoHostnamesMatch Signed-off-by: Case Wylie --- src/internal/agent/hooks/flux.go | 4 +-- src/pkg/utils/network.go | 18 ---------- src/pkg/utils/network/network.go | 23 +++++++++++++ src/pkg/utils/network/network_test.go | 47 +++++++++++++++++++++++++++ src/pkg/utils/network_test.go | 27 ++------------- 5 files changed, 75 insertions(+), 44 deletions(-) create mode 100644 src/pkg/utils/network/network.go create mode 100644 src/pkg/utils/network/network_test.go diff --git a/src/internal/agent/hooks/flux.go b/src/internal/agent/hooks/flux.go index 98981b2ef6..23a49f66d0 100644 --- a/src/internal/agent/hooks/flux.go +++ b/src/internal/agent/hooks/flux.go @@ -14,7 +14,7 @@ import ( "github.com/defenseunicorns/zarf/src/internal/agent/state" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" - "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/pkg/utils/network" "github.com/defenseunicorns/zarf/src/types" v1 "k8s.io/api/admission/v1" ) @@ -71,7 +71,7 @@ func mutateGitRepo(r *v1.AdmissionRequest) (result *operations.Result, err error // NOTE: We mutate on updates IF AND ONLY IF the hostname in the request is different than the hostname in the zarfState // NOTE: We are checking if the hostname is different before because we do not want to potentially mutate a URL that has already been mutated. if isUpdate { - isPatched, err = utils.DoHostnamesMatch(zarfState.GitServer.Address, src.Spec.URL) + isPatched, err = network.DoHostnamesMatch(message.Debugf, zarfState.GitServer.Address, src.Spec.URL) if err != nil { return nil, fmt.Errorf(lang.AgentErrHostnameMatch, err) } diff --git a/src/pkg/utils/network.go b/src/pkg/utils/network.go index eb96967375..f1dc7a2cbd 100644 --- a/src/pkg/utils/network.go +++ b/src/pkg/utils/network.go @@ -42,24 +42,6 @@ func IsOCIURL(source string) bool { return err == nil && parsedURL.Scheme == "oci" } -// DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same. -func DoHostnamesMatch(url1 string, url2 string) (bool, error) { - parsedURL1, err := url.Parse(url1) - if err != nil { - message.Debugf("unable to parse the url (%s)", url1) - - return false, err - } - parsedURL2, err := url.Parse(url2) - if err != nil { - message.Debugf("unable to parse the url (%s)", url2) - - return false, err - } - - return parsedURL1.Hostname() == parsedURL2.Hostname(), nil -} - // Fetch fetches the response body from a given URL. func Fetch(url string) io.ReadCloser { // Get the data diff --git a/src/pkg/utils/network/network.go b/src/pkg/utils/network/network.go new file mode 100644 index 0000000000..9d31626274 --- /dev/null +++ b/src/pkg/utils/network/network.go @@ -0,0 +1,23 @@ +package network + +import ( + "net/url" + + "github.com/defenseunicorns/zarf/src/pkg/transform" +) + +// DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same. +func DoHostnamesMatch(logger transform.Log, url1 string, url2 string) (bool, error) { + parsedURL1, err := url.Parse(url1) + if err != nil { + logger("unable to parse the url (%s)", url1) + return false, err + } + parsedURL2, err := url.Parse(url2) + if err != nil { + logger("unable to parse the url (%s)", url2) + return false, err + } + + return parsedURL1.Hostname() == parsedURL2.Hostname(), nil +} diff --git a/src/pkg/utils/network/network_test.go b/src/pkg/utils/network/network_test.go new file mode 100644 index 0000000000..4520c5427e --- /dev/null +++ b/src/pkg/utils/network/network_test.go @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package utils provides generic utility functions. +package network + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +type TestNetworkSuite struct { + suite.Suite + *require.Assertions +} + +func (suite *TestNetworkSuite) SetupSuite() { + suite.Assertions = require.New(suite.T()) +} +func (suite *TestNetworkSuite) Test_0_DoHostnamesMatch() { + dummyLogger := func(content string, args ...any) {} + + b, err := DoHostnamesMatch(dummyLogger, "https://zarf.dev", "https://zarf.dev") + suite.NoError(err) + suite.True(b) + b, err = DoHostnamesMatch(dummyLogger, "https://zarf.dev", "https://docs.zarf.dev") + suite.NoError(err) + suite.False(b) + b, err = DoHostnamesMatch(dummyLogger, "https://zarf.dev", "https://zarf.dev/docs") + suite.NoError(err) + suite.True(b) + b, err = DoHostnamesMatch(dummyLogger, "https://zarf.dev", "https://user:pass@zarf.dev") + suite.NoError(err) + suite.True(b) + b, err = DoHostnamesMatch(dummyLogger, "https://zarf.dev", "") + suite.NoError(err) + suite.False(b) + b, err = DoHostnamesMatch(dummyLogger, "", "https://zarf.dev") + suite.NoError(err) + suite.False(b) +} + +func TestNetwork(t *testing.T) { + suite.Run(t, new(TestNetworkSuite)) +} diff --git a/src/pkg/utils/network_test.go b/src/pkg/utils/network_test.go index 3cd5923590..71a5e5715d 100644 --- a/src/pkg/utils/network_test.go +++ b/src/pkg/utils/network_test.go @@ -71,35 +71,14 @@ func (suite *TestNetworkSuite) Test_1_IsOCIURL() { } } -func (suite *TestNetworkSuite) Test_2_DoHostnamesMatch() { - b, err := DoHostnamesMatch("https://zarf.dev", "https://zarf.dev") - suite.NoError(err) - suite.True(b) - b, err = DoHostnamesMatch("https://zarf.dev", "https://docs.zarf.dev") - suite.NoError(err) - suite.False(b) - b, err = DoHostnamesMatch("https://zarf.dev", "https://zarf.dev/docs") - suite.NoError(err) - suite.True(b) - b, err = DoHostnamesMatch("https://zarf.dev", "https://user:pass@zarf.dev") - suite.NoError(err) - suite.True(b) - b, err = DoHostnamesMatch("https://zarf.dev", "") - suite.NoError(err) - suite.False(b) - b, err = DoHostnamesMatch("", "https://zarf.dev") - suite.NoError(err) - suite.False(b) -} - -func (suite *TestNetworkSuite) Test_3_Fetch() { +func (suite *TestNetworkSuite) Test_2_Fetch() { readme := "https://raw.githubusercontent.com/defenseunicorns/zarf/main/README.md" body := Fetch(readme) defer body.Close() suite.NotNil(body) } -func (suite *TestNetworkSuite) Test_4_parseChecksum() { +func (suite *TestNetworkSuite) Test_3_parseChecksum() { // zarf prepare sha256sum .adr-dir adr := "https://raw.githubusercontent.com/defenseunicorns/zarf/main/.adr-dir" sum := "930f4d5a191812e57b39bd60fca789ace07ec5acd36d63e1047604c8bdf998a3" @@ -128,7 +107,7 @@ func (suite *TestNetworkSuite) Test_4_parseChecksum() { suite.Equal(sum, checksum) } -func (suite *TestNetworkSuite) Test_5_DownloadToFile() { +func (suite *TestNetworkSuite) Test_4_DownloadToFile() { readme := "https://raw.githubusercontent.com/defenseunicorns/zarf/main/README.md" tmp := suite.T().TempDir() path := filepath.Join(tmp, "README.md") From 24107fda687e1551bf255f36fddc878bc2b058ea Mon Sep 17 00:00:00 2001 From: Case Wylie Date: Mon, 7 Aug 2023 12:24:13 -0400 Subject: [PATCH 2/8] Update src/pkg/utils/network/network.go Co-authored-by: Lucas Rodriguez --- src/pkg/utils/network/network.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pkg/utils/network/network.go b/src/pkg/utils/network/network.go index 9d31626274..65f713fabd 100644 --- a/src/pkg/utils/network/network.go +++ b/src/pkg/utils/network/network.go @@ -7,16 +7,14 @@ import ( ) // DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same. -func DoHostnamesMatch(logger transform.Log, url1 string, url2 string) (bool, error) { +func DoHostnamesMatch(url1 string, url2 string) (bool, error) { parsedURL1, err := url.Parse(url1) if err != nil { - logger("unable to parse the url (%s)", url1) - return false, err + return false, fmt.Errorf("unable to parse the url (%s): %w", url1, err) } parsedURL2, err := url.Parse(url2) if err != nil { - logger("unable to parse the url (%s)", url2) - return false, err + return false, fmt.Errorf("unable to parse the url (%s): %w", url2, err) } return parsedURL1.Hostname() == parsedURL2.Hostname(), nil From 1f5cfd05c6fa859e64a35b37c28839f70be3d64b Mon Sep 17 00:00:00 2001 From: Case Wylie Date: Mon, 7 Aug 2023 12:27:24 -0400 Subject: [PATCH 3/8] remove log from DoHostnamesMatch Signed-off-by: Case Wylie --- src/internal/agent/hooks/flux.go | 2 +- src/pkg/utils/network/network.go | 3 +-- src/pkg/utils/network/network_test.go | 13 ++++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/internal/agent/hooks/flux.go b/src/internal/agent/hooks/flux.go index 23a49f66d0..615a0214ef 100644 --- a/src/internal/agent/hooks/flux.go +++ b/src/internal/agent/hooks/flux.go @@ -71,7 +71,7 @@ func mutateGitRepo(r *v1.AdmissionRequest) (result *operations.Result, err error // NOTE: We mutate on updates IF AND ONLY IF the hostname in the request is different than the hostname in the zarfState // NOTE: We are checking if the hostname is different before because we do not want to potentially mutate a URL that has already been mutated. if isUpdate { - isPatched, err = network.DoHostnamesMatch(message.Debugf, zarfState.GitServer.Address, src.Spec.URL) + isPatched, err = network.DoHostnamesMatch(zarfState.GitServer.Address, src.Spec.URL) if err != nil { return nil, fmt.Errorf(lang.AgentErrHostnameMatch, err) } diff --git a/src/pkg/utils/network/network.go b/src/pkg/utils/network/network.go index 65f713fabd..1ab484d238 100644 --- a/src/pkg/utils/network/network.go +++ b/src/pkg/utils/network/network.go @@ -1,9 +1,8 @@ package network import ( + "fmt" "net/url" - - "github.com/defenseunicorns/zarf/src/pkg/transform" ) // DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same. diff --git a/src/pkg/utils/network/network_test.go b/src/pkg/utils/network/network_test.go index 4520c5427e..617563c9d3 100644 --- a/src/pkg/utils/network/network_test.go +++ b/src/pkg/utils/network/network_test.go @@ -20,24 +20,23 @@ func (suite *TestNetworkSuite) SetupSuite() { suite.Assertions = require.New(suite.T()) } func (suite *TestNetworkSuite) Test_0_DoHostnamesMatch() { - dummyLogger := func(content string, args ...any) {} - b, err := DoHostnamesMatch(dummyLogger, "https://zarf.dev", "https://zarf.dev") + b, err := DoHostnamesMatch("https://zarf.dev", "https://zarf.dev") suite.NoError(err) suite.True(b) - b, err = DoHostnamesMatch(dummyLogger, "https://zarf.dev", "https://docs.zarf.dev") + b, err = DoHostnamesMatch("https://zarf.dev", "https://docs.zarf.dev") suite.NoError(err) suite.False(b) - b, err = DoHostnamesMatch(dummyLogger, "https://zarf.dev", "https://zarf.dev/docs") + b, err = DoHostnamesMatch("https://zarf.dev", "https://zarf.dev/docs") suite.NoError(err) suite.True(b) - b, err = DoHostnamesMatch(dummyLogger, "https://zarf.dev", "https://user:pass@zarf.dev") + b, err = DoHostnamesMatch("https://zarf.dev", "https://user:pass@zarf.dev") suite.NoError(err) suite.True(b) - b, err = DoHostnamesMatch(dummyLogger, "https://zarf.dev", "") + b, err = DoHostnamesMatch("https://zarf.dev", "") suite.NoError(err) suite.False(b) - b, err = DoHostnamesMatch(dummyLogger, "", "https://zarf.dev") + b, err = DoHostnamesMatch("", "https://zarf.dev") suite.NoError(err) suite.False(b) } From ed5524853c6fdf926c397510ac17d65291482967 Mon Sep 17 00:00:00 2001 From: Case Wylie Date: Mon, 7 Aug 2023 15:39:36 -0400 Subject: [PATCH 4/8] bring into helpers package Signed-off-by: Case Wylie --- src/cmd/package.go | 10 +-- src/internal/agent/hooks/flux.go | 4 +- src/internal/packager/validate/validate.go | 3 +- src/pkg/oci/common.go | 3 +- src/pkg/oci/utils.go | 3 +- src/pkg/packager/compose.go | 5 +- src/pkg/packager/create.go | 16 ++-- src/pkg/packager/deploy.go | 2 +- src/pkg/packager/inspect.go | 3 +- src/pkg/packager/network.go | 3 +- src/pkg/packager/prepare.go | 5 +- src/pkg/packager/remove.go | 4 +- src/pkg/utils/helpers/url.go | 42 ++++++++++ src/pkg/utils/helpers/url_test.go | 95 ++++++++++++++++++++++ src/pkg/utils/io.go | 2 +- src/pkg/utils/network.go | 16 +--- src/pkg/utils/network/network.go | 20 ----- src/pkg/utils/network/network_test.go | 46 ----------- src/pkg/utils/network_test.go | 54 +----------- 19 files changed, 176 insertions(+), 160 deletions(-) create mode 100644 src/pkg/utils/helpers/url.go create mode 100644 src/pkg/utils/helpers/url_test.go delete mode 100644 src/pkg/utils/network/network.go delete mode 100644 src/pkg/utils/network/network_test.go diff --git a/src/cmd/package.go b/src/cmd/package.go index 9976fef180..c5b9123865 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -12,7 +12,7 @@ import ( "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/pterm/pterm" "oras.land/oras-go/v2/registry" @@ -20,7 +20,7 @@ import ( "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/cluster" "github.com/defenseunicorns/zarf/src/pkg/packager" - "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/spf13/cobra" ) @@ -185,10 +185,10 @@ var packagePublishCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { pkgConfig.PublishOpts.PackagePath = choosePackage(args) - if !utils.IsOCIURL(args[1]) { + if !helpers.IsOCIURL(args[1]) { message.Fatal(nil, lang.CmdPackageRegistryPrefixErr) } - parts := strings.Split(strings.TrimPrefix(args[1], utils.OCIURLPrefix), "/") + parts := strings.Split(strings.TrimPrefix(args[1], helpers.OCIURLPrefix), "/") ref := registry.Reference{ Registry: parts[0], Repository: strings.Join(parts[1:], "/"), @@ -217,7 +217,7 @@ var packagePullCmd = &cobra.Command{ Example: lang.CmdPackagePullExample, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - if !utils.IsOCIURL(args[0]) { + if !helpers.IsOCIURL(args[0]) { message.Fatal(nil, lang.CmdPackageRegistryPrefixErr) } diff --git a/src/internal/agent/hooks/flux.go b/src/internal/agent/hooks/flux.go index 615a0214ef..a246dfe650 100644 --- a/src/internal/agent/hooks/flux.go +++ b/src/internal/agent/hooks/flux.go @@ -14,7 +14,7 @@ import ( "github.com/defenseunicorns/zarf/src/internal/agent/state" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" - "github.com/defenseunicorns/zarf/src/pkg/utils/network" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" v1 "k8s.io/api/admission/v1" ) @@ -71,7 +71,7 @@ func mutateGitRepo(r *v1.AdmissionRequest) (result *operations.Result, err error // NOTE: We mutate on updates IF AND ONLY IF the hostname in the request is different than the hostname in the zarfState // NOTE: We are checking if the hostname is different before because we do not want to potentially mutate a URL that has already been mutated. if isUpdate { - isPatched, err = network.DoHostnamesMatch(zarfState.GitServer.Address, src.Spec.URL) + isPatched, err = helpers.DoHostnamesMatch(zarfState.GitServer.Address, src.Spec.URL) if err != nil { return nil, fmt.Errorf(lang.AgentErrHostnameMatch, err) } diff --git a/src/internal/packager/validate/validate.go b/src/internal/packager/validate/validate.go index 4af8c2d1f4..2cf0d621b3 100644 --- a/src/internal/packager/validate/validate.go +++ b/src/internal/packager/validate/validate.go @@ -14,6 +14,7 @@ import ( "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ) @@ -92,7 +93,7 @@ func ImportPackage(composedComponent *types.ZarfComponent) error { if path != "" { return fmt.Errorf(lang.PkgValidateErrImportOptions, composedComponent.Name) } - ok := utils.IsOCIURL(url) + ok := helpers.IsOCIURL(url) if !ok { return fmt.Errorf(lang.PkgValidateErrImportURLInvalid, composedComponent.Import.URL) } diff --git a/src/pkg/oci/common.go b/src/pkg/oci/common.go index a61d09a8b6..20c25b60c1 100644 --- a/src/pkg/oci/common.go +++ b/src/pkg/oci/common.go @@ -13,6 +13,7 @@ import ( zarfconfig "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/docker/cli/cli/config" "github.com/docker/cli/cli/config/configfile" "oras.land/oras-go/v2" @@ -41,7 +42,7 @@ type OrasRemote struct { // // Registry auth is handled by the Docker CLI's credential store and checked before returning the client func NewOrasRemote(url string) (*OrasRemote, error) { - ref, err := registry.ParseReference(strings.TrimPrefix(url, utils.OCIURLPrefix)) + ref, err := registry.ParseReference(strings.TrimPrefix(url, helpers.OCIURLPrefix)) if err != nil { return nil, fmt.Errorf("failed to parse OCI reference: %w", err) } diff --git a/src/pkg/oci/utils.go b/src/pkg/oci/utils.go index dcde4fd252..7df3b42073 100644 --- a/src/pkg/oci/utils.go +++ b/src/pkg/oci/utils.go @@ -14,6 +14,7 @@ import ( config "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" goyaml "github.com/goccy/go-yaml" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -27,7 +28,7 @@ import ( // // appending the provided suffix to the version func ReferenceFromMetadata(registryLocation string, metadata *types.ZarfMetadata, suffix string) (*registry.Reference, error) { - registryLocation = strings.TrimPrefix(registryLocation, utils.OCIURLPrefix) + registryLocation = strings.TrimPrefix(registryLocation, helpers.OCIURLPrefix) ver := metadata.Version if len(ver) == 0 { diff --git a/src/pkg/packager/compose.go b/src/pkg/packager/compose.go index 880f6a99c7..c9d3d433b6 100644 --- a/src/pkg/packager/compose.go +++ b/src/pkg/packager/compose.go @@ -16,6 +16,7 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/oci" "github.com/defenseunicorns/zarf/src/pkg/packager/deprecated" "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/mholt/archiver/v3" ) @@ -97,7 +98,7 @@ func (p *Packager) getChildComponent(parent types.ZarfComponent, pathAncestry st // Save all the OCI imported components into our build data p.cfg.Pkg.Build.OCIImportedComponents[parent.Import.URL] = childComponentName - skelURL := strings.TrimPrefix(parent.Import.URL, utils.OCIURLPrefix) + skelURL := strings.TrimPrefix(parent.Import.URL, helpers.OCIURLPrefix) cachePath = filepath.Join(config.GetAbsCachePath(), "oci", skelURL) err = os.MkdirAll(cachePath, 0755) if err != nil { @@ -401,7 +402,7 @@ func (p *Packager) getComposedFilePath(prefix string, path string) string { message.Debugf("packager.getComposedFilePath(%s, %s)", prefix, path) // Return original if it is a remote file. - if utils.IsURL(path) { + if helpers.IsURL(path) { return path } diff --git a/src/pkg/packager/create.go b/src/pkg/packager/create.go index ef138461d3..38c0362f8d 100755 --- a/src/pkg/packager/create.go +++ b/src/pkg/packager/create.go @@ -41,7 +41,7 @@ func (p *Packager) Create(baseDir string) error { return fmt.Errorf("unable to read the zarf.yaml file: %s", err.Error()) } - if utils.IsOCIURL(p.cfg.CreateOpts.Output) { + if helpers.IsOCIURL(p.cfg.CreateOpts.Output) { ref, err := oci.ReferenceFromMetadata(p.cfg.CreateOpts.Output, &p.cfg.Pkg.Metadata, p.arch) if err != nil { return err @@ -224,7 +224,7 @@ func (p *Packager) Create(baseDir string) error { } } - if utils.IsOCIURL(p.cfg.CreateOpts.Output) { + if helpers.IsOCIURL(p.cfg.CreateOpts.Output) { err := p.remote.PublishPackage(&p.cfg.Pkg, p.tmp.Base, config.CommonOptions.OCIConcurrency) if err != nil { return fmt.Errorf("unable to publish package: %w", err) @@ -352,7 +352,7 @@ func (p *Packager) addComponent(index int, component types.ZarfComponent, isSkel rel := fmt.Sprintf("%s-%d", helm.StandardName(types.ValuesFolder, chart), valuesIdx) dst := filepath.Join(componentPath.Base, rel) - if utils.IsURL(path) { + if helpers.IsURL(path) { if isSkeleton { continue } @@ -376,7 +376,7 @@ func (p *Packager) addComponent(index int, component types.ZarfComponent, isSkel rel := filepath.Join(types.FilesFolder, strconv.Itoa(filesIdx), filepath.Base(file.Target)) dst := filepath.Join(componentPath.Base, rel) - if utils.IsURL(file.Source) { + if helpers.IsURL(file.Source) { if isSkeleton { continue } @@ -416,7 +416,7 @@ func (p *Packager) addComponent(index int, component types.ZarfComponent, isSkel rel := filepath.Join(types.DataInjectionsFolder, strconv.Itoa(dataIdx), filepath.Base(data.Target.Path)) dst := filepath.Join(componentPath.Base, rel) - if utils.IsURL(data.Source) { + if helpers.IsURL(data.Source) { if isSkeleton { continue } @@ -455,7 +455,7 @@ func (p *Packager) addComponent(index int, component types.ZarfComponent, isSkel // Copy manifests without any processing. spinner.Updatef("Copying manifest %s", path) - if utils.IsURL(path) { + if helpers.IsURL(path) { if isSkeleton { continue } @@ -566,7 +566,7 @@ func (p *Packager) loadDifferentialData() error { defer os.RemoveAll(tmpDir) // Load the package spec of the package we're using as a 'reference' for the differential build - if utils.IsOCIURL(p.cfg.CreateOpts.DifferentialData.DifferentialPackagePath) { + if helpers.IsOCIURL(p.cfg.CreateOpts.DifferentialData.DifferentialPackagePath) { err := p.SetOCIRemote(p.cfg.CreateOpts.DifferentialData.DifferentialPackagePath) if err != nil { return err @@ -622,7 +622,7 @@ func (p *Packager) removeDifferentialComponentsFromPackage() error { for idx, component := range p.cfg.Pkg.Components { // if the component is imported from an OCI package and everything is the same, don't include this package - if utils.IsOCIURL(component.Import.URL) { + if helpers.IsOCIURL(component.Import.URL) { if _, alsoExists := p.cfg.CreateOpts.DifferentialData.DifferentialOCIComponents[component.Import.URL]; alsoExists { // If the component spec is not empty, we will still include it in the differential package diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 9443e92eb0..10f7882300 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -41,7 +41,7 @@ var ( func (p *Packager) Deploy() error { message.Debug("packager.Deploy()") - if utils.IsOCIURL(p.cfg.DeployOpts.PackagePath) { + if helpers.IsOCIURL(p.cfg.DeployOpts.PackagePath) { err := p.SetOCIRemote(p.cfg.DeployOpts.PackagePath) if err != nil { return err diff --git a/src/pkg/packager/inspect.go b/src/pkg/packager/inspect.go index 10a4ca4f09..c9f9572289 100644 --- a/src/pkg/packager/inspect.go +++ b/src/pkg/packager/inspect.go @@ -11,6 +11,7 @@ import ( "github.com/defenseunicorns/zarf/src/internal/packager/sbom" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/mholt/archiver/v3" ) @@ -24,7 +25,7 @@ func (p *Packager) Inspect(includeSBOM bool, outputSBOM string, inspectPublicKey } // Handle OCI packages that have been published to a registry - if utils.IsOCIURL(p.cfg.DeployOpts.PackagePath) { + if helpers.IsOCIURL(p.cfg.DeployOpts.PackagePath) { message.Debugf("Pulling layers %v from %s", partialPaths, p.cfg.DeployOpts.PackagePath) diff --git a/src/pkg/packager/network.go b/src/pkg/packager/network.go index 016136b750..94efde8cb3 100644 --- a/src/pkg/packager/network.go +++ b/src/pkg/packager/network.go @@ -16,6 +16,7 @@ import ( "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -33,7 +34,7 @@ func (p *Packager) handlePackagePath() (partialPaths []string, err error) { } // Handle case where deploying remote package stored in an OCI registry - if utils.IsOCIURL(opts.PackagePath) { + if helpers.IsOCIURL(opts.PackagePath) { p.cfg.DeployOpts.PackagePath = p.tmp.Base requestedComponents := getRequestedComponentList(p.cfg.DeployOpts.Components) layersToPull := []ocispec.Descriptor{} diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 3f9426d954..ba4cfa7a90 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -19,6 +19,7 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/google/go-containerregistry/pkg/crane" v1 "k8s.io/api/apps/v1" @@ -131,7 +132,7 @@ func (p *Packager) FindImages(baseDir, repoHelmChartPath string, kubeVersionOver for idx, path := range chart.ValuesFiles { dst := helm.StandardName(componentPath.Values, chart) + "-" + strconv.Itoa(idx) - if utils.IsURL(path) { + if helpers.IsURL(path) { if err := utils.DownloadToFile(path, dst, component.CosignKeyPath); err != nil { return nil, fmt.Errorf(lang.ErrDownloading, path, err.Error()) } @@ -195,7 +196,7 @@ func (p *Packager) FindImages(baseDir, repoHelmChartPath string, kubeVersionOver } // Get all manifest files for idx, f := range manifest.Files { - if utils.IsURL(f) { + if helpers.IsURL(f) { mname := fmt.Sprintf("manifest-%s-%d.yaml", manifest.Name, idx) destination := filepath.Join(componentPath.Manifests, mname) if err := utils.DownloadToFile(f, destination, component.CosignKeyPath); err != nil { diff --git a/src/pkg/packager/remove.go b/src/pkg/packager/remove.go index a45fc3fb71..aed41c7ee9 100644 --- a/src/pkg/packager/remove.go +++ b/src/pkg/packager/remove.go @@ -39,7 +39,7 @@ func (p *Packager) Remove(packageName string) (err error) { } // If the user input is a path to a oci, pull the package - if utils.IsOCIURL(packageName) { + if helpers.IsOCIURL(packageName) { err := p.SetOCIRemote(packageName) if err != nil { message.Fatalf(err, "Unable to set OCI remote: %s", err.Error()) @@ -52,7 +52,7 @@ func (p *Packager) Remove(packageName string) (err error) { } // If this came from a real package, read the package config and reset the packageName - if ZarfPackagePattern.MatchString(packageName) || ZarfInitPattern.MatchString(packageName) || utils.IsOCIURL(packageName) { + if ZarfPackagePattern.MatchString(packageName) || ZarfInitPattern.MatchString(packageName) || helpers.IsOCIURL(packageName) { if err := p.readYaml(p.tmp.ZarfYaml); err != nil { return err } diff --git a/src/pkg/utils/helpers/url.go b/src/pkg/utils/helpers/url.go new file mode 100644 index 0000000000..1b7278484b --- /dev/null +++ b/src/pkg/utils/helpers/url.go @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package helpers provides generic helper functions with no external imports +package helpers + +import ( + "fmt" + "net/url" +) + +// Nonstandard URL schemes or prefixes +const ( + OCIURLScheme = "oci" + OCIURLPrefix = "oci://" +) + +// IsURL is a helper function to check if a URL is valid. +func IsURL(source string) bool { + parsedURL, err := url.Parse(source) + return err == nil && parsedURL.Scheme != "" && parsedURL.Host != "" +} + +// IsOCIURL returns true if the given URL is an OCI URL. +func IsOCIURL(source string) bool { + parsedURL, err := url.Parse(source) + return err == nil && parsedURL.Scheme == "oci" +} + +// DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same. +func DoHostnamesMatch(url1 string, url2 string) (bool, error) { + parsedURL1, err := url.Parse(url1) + if err != nil { + return false, fmt.Errorf("unable to parse the url (%s): %w", url1, err) + } + parsedURL2, err := url.Parse(url2) + if err != nil { + return false, fmt.Errorf("unable to parse the url (%s): %w", url2, err) + } + + return parsedURL1.Hostname() == parsedURL2.Hostname(), nil +} diff --git a/src/pkg/utils/helpers/url_test.go b/src/pkg/utils/helpers/url_test.go new file mode 100644 index 0000000000..ee76405238 --- /dev/null +++ b/src/pkg/utils/helpers/url_test.go @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package helpers provides generic helper functions with no external imports +package helpers + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +type TestNetworkSuite struct { + suite.Suite + *require.Assertions + urls testURLs +} + +type testURLs struct { + good []string + oci []string + paths []string +} + +func (suite *TestNetworkSuite) SetupSuite() { + suite.Assertions = require.New(suite.T()) + suite.urls.good = []string{ + "https://zarf.dev", + "https://docs.zarf.dev", + "https://zarf.dev/docs", + "https://defenseunicorns.com", + "https://google.com", + "https://user:pass@hello.world?foo=bar", + "https://zarf.dev?foo=bar&bar=baz", + } + suite.urls.oci = []string{ + "oci://zarf.dev", + "oci://defenseunicorns.com", + "oci://google.com", + } + suite.urls.paths = []string{ + "./hello.txt", + "../hello.txt", + "/tmp/hello.txt", + } +} + +func (suite *TestNetworkSuite) Test_0_IsURL() { + all := append(suite.urls.good, suite.urls.oci...) + for _, url := range all { + suite.True(IsURL(url), "Expected %s to be a valid URL", url) + } + for _, url := range suite.urls.paths { + suite.False(IsURL(url), "Expected %s to be an invalid URL", url) + } +} + +func (suite *TestNetworkSuite) Test_1_IsOCIURL() { + for _, url := range suite.urls.good { + suite.False(IsOCIURL(url), "Expected %s to be an invalid OCI URL", url) + } + for _, url := range suite.urls.oci { + suite.True(IsOCIURL(url), "Expected %s to be a valid OCI URL", url) + } + for _, url := range suite.urls.paths { + suite.False(IsOCIURL(url), "Expected %s to be an invalid OCI URL", url) + } +} + +func (suite *TestNetworkSuite) Test_2_DoHostnamesMatch() { + + b, err := DoHostnamesMatch("https://zarf.dev", "https://zarf.dev") + suite.NoError(err) + suite.True(b) + b, err = DoHostnamesMatch("https://zarf.dev", "https://docs.zarf.dev") + suite.NoError(err) + suite.False(b) + b, err = DoHostnamesMatch("https://zarf.dev", "https://zarf.dev/docs") + suite.NoError(err) + suite.True(b) + b, err = DoHostnamesMatch("https://zarf.dev", "https://user:pass@zarf.dev") + suite.NoError(err) + suite.True(b) + b, err = DoHostnamesMatch("https://zarf.dev", "") + suite.NoError(err) + suite.False(b) + b, err = DoHostnamesMatch("", "https://zarf.dev") + suite.NoError(err) + suite.False(b) +} + +func TestNetwork(t *testing.T) { + suite.Run(t, new(TestNetworkSuite)) +} diff --git a/src/pkg/utils/io.go b/src/pkg/utils/io.go index 43c57539ca..58a76f6ecf 100755 --- a/src/pkg/utils/io.go +++ b/src/pkg/utils/io.go @@ -35,7 +35,7 @@ func GetCryptoHashFromFile(path string, hashName crypto.Hash) (string, error) { var data io.ReadCloser var err error - if IsURL(path) { + if helpers.IsURL(path) { // Handle download from URL message.Warn("This is a remote source. If a published checksum is available you should use that rather than calculating it directly from the remote link.") data = Fetch(path) diff --git a/src/pkg/utils/network.go b/src/pkg/utils/network.go index f1dc7a2cbd..89d6b47a68 100644 --- a/src/pkg/utils/network.go +++ b/src/pkg/utils/network.go @@ -24,24 +24,10 @@ import ( // Nonstandard URL schemes or prefixes const ( - OCIURLScheme = "oci" - OCIURLPrefix = "oci://" - SGETURLScheme = "sget" SGETURLPrefix = "sget://" + SGETURLScheme = "sget" ) -// IsURL is a helper function to check if a URL is valid. -func IsURL(source string) bool { - parsedURL, err := url.Parse(source) - return err == nil && parsedURL.Scheme != "" && parsedURL.Host != "" -} - -// IsOCIURL returns true if the given URL is an OCI URL. -func IsOCIURL(source string) bool { - parsedURL, err := url.Parse(source) - return err == nil && parsedURL.Scheme == "oci" -} - // Fetch fetches the response body from a given URL. func Fetch(url string) io.ReadCloser { // Get the data diff --git a/src/pkg/utils/network/network.go b/src/pkg/utils/network/network.go deleted file mode 100644 index 1ab484d238..0000000000 --- a/src/pkg/utils/network/network.go +++ /dev/null @@ -1,20 +0,0 @@ -package network - -import ( - "fmt" - "net/url" -) - -// DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same. -func DoHostnamesMatch(url1 string, url2 string) (bool, error) { - parsedURL1, err := url.Parse(url1) - if err != nil { - return false, fmt.Errorf("unable to parse the url (%s): %w", url1, err) - } - parsedURL2, err := url.Parse(url2) - if err != nil { - return false, fmt.Errorf("unable to parse the url (%s): %w", url2, err) - } - - return parsedURL1.Hostname() == parsedURL2.Hostname(), nil -} diff --git a/src/pkg/utils/network/network_test.go b/src/pkg/utils/network/network_test.go deleted file mode 100644 index 617563c9d3..0000000000 --- a/src/pkg/utils/network/network_test.go +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package utils provides generic utility functions. -package network - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" -) - -type TestNetworkSuite struct { - suite.Suite - *require.Assertions -} - -func (suite *TestNetworkSuite) SetupSuite() { - suite.Assertions = require.New(suite.T()) -} -func (suite *TestNetworkSuite) Test_0_DoHostnamesMatch() { - - b, err := DoHostnamesMatch("https://zarf.dev", "https://zarf.dev") - suite.NoError(err) - suite.True(b) - b, err = DoHostnamesMatch("https://zarf.dev", "https://docs.zarf.dev") - suite.NoError(err) - suite.False(b) - b, err = DoHostnamesMatch("https://zarf.dev", "https://zarf.dev/docs") - suite.NoError(err) - suite.True(b) - b, err = DoHostnamesMatch("https://zarf.dev", "https://user:pass@zarf.dev") - suite.NoError(err) - suite.True(b) - b, err = DoHostnamesMatch("https://zarf.dev", "") - suite.NoError(err) - suite.False(b) - b, err = DoHostnamesMatch("", "https://zarf.dev") - suite.NoError(err) - suite.False(b) -} - -func TestNetwork(t *testing.T) { - suite.Run(t, new(TestNetworkSuite)) -} diff --git a/src/pkg/utils/network_test.go b/src/pkg/utils/network_test.go index 71a5e5715d..9ca1bfa8d4 100644 --- a/src/pkg/utils/network_test.go +++ b/src/pkg/utils/network_test.go @@ -17,68 +17,20 @@ import ( type TestNetworkSuite struct { suite.Suite *require.Assertions - urls testURLs -} - -type testURLs struct { - good []string - oci []string - paths []string } func (suite *TestNetworkSuite) SetupSuite() { suite.Assertions = require.New(suite.T()) - suite.urls.good = []string{ - "https://zarf.dev", - "https://docs.zarf.dev", - "https://zarf.dev/docs", - "https://defenseunicorns.com", - "https://google.com", - "https://user:pass@hello.world?foo=bar", - "https://zarf.dev?foo=bar&bar=baz", - } - suite.urls.oci = []string{ - "oci://zarf.dev", - "oci://defenseunicorns.com", - "oci://google.com", - } - suite.urls.paths = []string{ - "./hello.txt", - "../hello.txt", - "/tmp/hello.txt", - } -} - -func (suite *TestNetworkSuite) Test_0_IsURL() { - all := append(suite.urls.good, suite.urls.oci...) - for _, url := range all { - suite.True(IsURL(url), "Expected %s to be a valid URL", url) - } - for _, url := range suite.urls.paths { - suite.False(IsURL(url), "Expected %s to be an invalid URL", url) - } -} - -func (suite *TestNetworkSuite) Test_1_IsOCIURL() { - for _, url := range suite.urls.good { - suite.False(IsOCIURL(url), "Expected %s to be an invalid OCI URL", url) - } - for _, url := range suite.urls.oci { - suite.True(IsOCIURL(url), "Expected %s to be a valid OCI URL", url) - } - for _, url := range suite.urls.paths { - suite.False(IsOCIURL(url), "Expected %s to be an invalid OCI URL", url) - } } -func (suite *TestNetworkSuite) Test_2_Fetch() { +func (suite *TestNetworkSuite) Test_0_Fetch() { readme := "https://raw.githubusercontent.com/defenseunicorns/zarf/main/README.md" body := Fetch(readme) defer body.Close() suite.NotNil(body) } -func (suite *TestNetworkSuite) Test_3_parseChecksum() { +func (suite *TestNetworkSuite) Test_1_parseChecksum() { // zarf prepare sha256sum .adr-dir adr := "https://raw.githubusercontent.com/defenseunicorns/zarf/main/.adr-dir" sum := "930f4d5a191812e57b39bd60fca789ace07ec5acd36d63e1047604c8bdf998a3" @@ -107,7 +59,7 @@ func (suite *TestNetworkSuite) Test_3_parseChecksum() { suite.Equal(sum, checksum) } -func (suite *TestNetworkSuite) Test_4_DownloadToFile() { +func (suite *TestNetworkSuite) Test_2_DownloadToFile() { readme := "https://raw.githubusercontent.com/defenseunicorns/zarf/main/README.md" tmp := suite.T().TempDir() path := filepath.Join(tmp, "README.md") From bb7211dc1d1bf2fb67695cdb0a963c00a66e9024 Mon Sep 17 00:00:00 2001 From: Case Wylie Date: Mon, 7 Aug 2023 15:47:41 -0400 Subject: [PATCH 5/8] update e2e test Signed-off-by: Case Wylie --- src/test/e2e/51_oci_compose_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/e2e/51_oci_compose_test.go b/src/test/e2e/51_oci_compose_test.go index 62a02ffe26..be2d9e655e 100644 --- a/src/test/e2e/51_oci_compose_test.go +++ b/src/test/e2e/51_oci_compose_test.go @@ -16,6 +16,7 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" "github.com/defenseunicorns/zarf/src/pkg/utils/exec" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -225,7 +226,7 @@ func (suite *SkeletonSuite) verifyComponentPaths(unpackedPath string, components } for filesIdx, file := range component.Files { - if isSkeleton && utils.IsURL(file.Source) { + if isSkeleton && helpers.IsURL(file.Source) { continue } else if isSkeleton { suite.FileExists(filepath.Join(base, file.Source)) @@ -236,7 +237,7 @@ func (suite *SkeletonSuite) verifyComponentPaths(unpackedPath string, components } for dataIdx, data := range component.DataInjections { - if isSkeleton && utils.IsURL(data.Source) { + if isSkeleton && helpers.IsURL(data.Source) { continue } else if isSkeleton { suite.DirOrFileExists(filepath.Join(base, data.Source)) @@ -251,7 +252,7 @@ func (suite *SkeletonSuite) verifyComponentPaths(unpackedPath string, components suite.Nil(manifest.Kustomizations) } for filesIdx, path := range manifest.Files { - if isSkeleton && utils.IsURL(path) { + if isSkeleton && helpers.IsURL(path) { continue } else if isSkeleton { suite.FileExists(filepath.Join(base, path)) From 4390ca762e2c92cecfa7fee63f22636ba57a9cff Mon Sep 17 00:00:00 2001 From: Case Wylie Date: Tue, 8 Aug 2023 11:21:41 -0400 Subject: [PATCH 6/8] Update src/pkg/utils/helpers/url_test.go Co-authored-by: Wayne Starr --- src/pkg/utils/helpers/url_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/utils/helpers/url_test.go b/src/pkg/utils/helpers/url_test.go index ee76405238..786b8c1ae8 100644 --- a/src/pkg/utils/helpers/url_test.go +++ b/src/pkg/utils/helpers/url_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/suite" ) -type TestNetworkSuite struct { +type TestURLSuite struct { suite.Suite *require.Assertions urls testURLs From 8aee64bb05714094075bfdfa144b8a7bac948f7e Mon Sep 17 00:00:00 2001 From: Case Wylie Date: Tue, 8 Aug 2023 11:21:50 -0400 Subject: [PATCH 7/8] Update src/pkg/utils/helpers/url_test.go Co-authored-by: Wayne Starr --- src/pkg/utils/helpers/url_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/utils/helpers/url_test.go b/src/pkg/utils/helpers/url_test.go index 786b8c1ae8..78eb250f8a 100644 --- a/src/pkg/utils/helpers/url_test.go +++ b/src/pkg/utils/helpers/url_test.go @@ -90,6 +90,6 @@ func (suite *TestNetworkSuite) Test_2_DoHostnamesMatch() { suite.False(b) } -func TestNetwork(t *testing.T) { +func TestURL(t *testing.T) { suite.Run(t, new(TestNetworkSuite)) } From 63315ab74823f786a91742ebae8448ea21ee930f Mon Sep 17 00:00:00 2001 From: Case Wylie Date: Tue, 8 Aug 2023 12:50:25 -0400 Subject: [PATCH 8/8] fix unit test Signed-off-by: Case Wylie --- src/pkg/utils/helpers/url_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pkg/utils/helpers/url_test.go b/src/pkg/utils/helpers/url_test.go index 78eb250f8a..b5955d1a2d 100644 --- a/src/pkg/utils/helpers/url_test.go +++ b/src/pkg/utils/helpers/url_test.go @@ -23,7 +23,7 @@ type testURLs struct { paths []string } -func (suite *TestNetworkSuite) SetupSuite() { +func (suite *TestURLSuite) SetupSuite() { suite.Assertions = require.New(suite.T()) suite.urls.good = []string{ "https://zarf.dev", @@ -46,7 +46,7 @@ func (suite *TestNetworkSuite) SetupSuite() { } } -func (suite *TestNetworkSuite) Test_0_IsURL() { +func (suite *TestURLSuite) Test_0_IsURL() { all := append(suite.urls.good, suite.urls.oci...) for _, url := range all { suite.True(IsURL(url), "Expected %s to be a valid URL", url) @@ -56,7 +56,7 @@ func (suite *TestNetworkSuite) Test_0_IsURL() { } } -func (suite *TestNetworkSuite) Test_1_IsOCIURL() { +func (suite *TestURLSuite) Test_1_IsOCIURL() { for _, url := range suite.urls.good { suite.False(IsOCIURL(url), "Expected %s to be an invalid OCI URL", url) } @@ -68,7 +68,7 @@ func (suite *TestNetworkSuite) Test_1_IsOCIURL() { } } -func (suite *TestNetworkSuite) Test_2_DoHostnamesMatch() { +func (suite *TestURLSuite) Test_2_DoHostnamesMatch() { b, err := DoHostnamesMatch("https://zarf.dev", "https://zarf.dev") suite.NoError(err) @@ -91,5 +91,5 @@ func (suite *TestNetworkSuite) Test_2_DoHostnamesMatch() { } func TestURL(t *testing.T) { - suite.Run(t, new(TestNetworkSuite)) + suite.Run(t, new(TestURLSuite)) }