Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix lint issues in main #783

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions cmd/check_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
"errors"
"fmt"
"strings"

Expand All @@ -29,7 +28,7 @@ func checkContainerCmd() *cobra.Command {
Args: checkContainerPositionalArgs,
// this fmt.Sprintf is in place to keep spacing consistent with cobras two spaces that's used in: Usage, Flags, etc
Example: fmt.Sprintf(" %s", "preflight check container quay.io/repo-name/container-name:version"),
PreRunE: validateCertificationProjectId,
PreRunE: validateCertificationProjectID,
RunE: checkContainerRunE,
}

Expand Down Expand Up @@ -211,16 +210,16 @@ func checkContainerPositionalArgs(cmd *cobra.Command, args []string) error {
return nil
}

// validateCertificationProjectId validates that the certification project id is in the proper format
// validateCertificationProjectID validates that the certification project id is in the proper format
// and throws an error if the value provided is in a legacy format that is not usable to query pyxis
func validateCertificationProjectId(cmd *cobra.Command, args []string) error {
func validateCertificationProjectID(cmd *cobra.Command, args []string) error {
certificationProjectID := viper.GetString("certification_project_id")
// splitting the certification project id into parts. if there are more than 2 elements in the array,
// we know they inputted a legacy project id, which can not be used to query pyxis
parts := strings.Split(certificationProjectID, "-")

if len(parts) > 2 {
return errors.New(fmt.Sprintf("certification project id: %s is improperly formatted see help command for instructions on obtaining proper value", certificationProjectID))
return fmt.Errorf("certification project id: %s is improperly formatted see help command for instructions on obtaining proper value", certificationProjectID)
}

if parts[0] == "ospid" {
Expand Down
8 changes: 4 additions & 4 deletions cmd/check_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ certification_project_id: mycertid`
viper.Set("certification_project_id", "123456789")
})
It("should not change the flag value", func() {
err := validateCertificationProjectId(checkContainerCmd(), []string{"foo"})
err := validateCertificationProjectID(checkContainerCmd(), []string{"foo"})
Expect(err).ToNot(HaveOccurred())
Expect(viper.GetString("certification_project_id")).To(Equal("123456789"))
})
Expand All @@ -546,7 +546,7 @@ certification_project_id: mycertid`
viper.Set("certification_project_id", "ospid-123456789")
})
It("should strip ospid- from the flag value", func() {
err := validateCertificationProjectId(checkContainerCmd(), []string{"foo"})
err := validateCertificationProjectID(checkContainerCmd(), []string{"foo"})
Expect(err).ToNot(HaveOccurred())
Expect(viper.GetString("certification_project_id")).To(Equal("123456789"))
})
Expand All @@ -556,7 +556,7 @@ certification_project_id: mycertid`
viper.Set("certification_project_id", "ospid-62423-f26c346-6cc1dc7fae92")
})
It("should throw an error", func() {
err := validateCertificationProjectId(checkContainerCmd(), []string{"foo"})
err := validateCertificationProjectID(checkContainerCmd(), []string{"foo"})
Expect(err).To(HaveOccurred())
})
})
Expand All @@ -565,7 +565,7 @@ certification_project_id: mycertid`
viper.Set("certification_project_id", "62423-f26c346-6cc1dc7fae92")
})
It("should throw an error", func() {
err := validateCertificationProjectId(checkContainerCmd(), []string{"foo"})
err := validateCertificationProjectID(checkContainerCmd(), []string{"foo"})
Expect(err).To(HaveOccurred())
})
})
Expand Down