diff --git a/pkg/validate/sources.go b/pkg/validate/sources.go deleted file mode 100644 index 8e8d37055e..0000000000 --- a/pkg/validate/sources.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package validate - -import ( - "context" - "fmt" - "net/url" - - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" -) - -// SourcesRef implements RuntimeRef interface to add validations for `build.spec.sources` slice. -type SourcesRef struct { - Build *build.Build // build instance for analysis -} - -// ValidatePath executes the validation routine, inspecting the `build.spec.sources` path, which -// contains a slice of BuildSource. -func (s *SourcesRef) ValidatePath(_ context.Context) error { - for _, source := range s.Build.Spec.Sources { - if err := s.validateSourceEntry(source); err != nil { - return err - } - } - return nil -} - -// validateSourceEntry inspect informed entry, probes all required attributes. -func (s *SourcesRef) validateSourceEntry(source build.BuildSource) error { - if source.Name == "" { - return fmt.Errorf("name must be informed") - } - if source.URL == "" { - return fmt.Errorf("URL must be informed") - } - if _, err := url.ParseRequestURI(source.URL); err != nil { - return err - } - return nil -} - -// NewSourcesRef instantiate a new SourcesRef passing the build object pointer along. -func NewSourcesRef(b *build.Build) *SourcesRef { - return &SourcesRef{Build: b} -} diff --git a/pkg/validate/sources_test.go b/pkg/validate/sources_test.go deleted file mode 100644 index ab68bb3efb..0000000000 --- a/pkg/validate/sources_test.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package validate_test - -import ( - "context" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - "github.com/shipwright-io/build/pkg/validate" -) - -var _ = Describe("SourcesRef", func() { - Context("ValidatePath", func() { - It("should successfully validate an empty sources slice", func() { - srcRef := validate.NewSourcesRef(&build.Build{}) - - Expect(srcRef.ValidatePath(context.TODO())).To(BeNil()) - }) - - It("should successfully validate a build with a valid URL", func() { - srcRef := validate.NewSourcesRef(&build.Build{ - Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: "name", URL: "https://github.com/shipwright-io/build"}, - }, - }, - }) - - Expect(srcRef.ValidatePath(context.TODO())).To(BeNil()) - }) - - It("should fail to validate if the name is not informed", func() { - srcRef := validate.NewSourcesRef(&build.Build{ - Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: ""}, - }, - }, - }) - - Expect(srcRef.ValidatePath(context.TODO())).To(HaveOccurred()) - }) - - It("should fail to validate if the URL is not informed", func() { - srcRef := validate.NewSourcesRef(&build.Build{ - Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: "name", URL: ""}, - }, - }, - }) - - Expect(srcRef.ValidatePath(context.TODO())).To(HaveOccurred()) - }) - - It("should fail to validate a build with an invalid URL", func() { - srcRef := validate.NewSourcesRef(&build.Build{ - Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: "name", URL: "invalid URL"}, - }, - }, - }) - - Expect(srcRef.ValidatePath(context.TODO())).To(HaveOccurred()) - }) - }) -})