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 old SA1006 lint errors #2695

Merged
merged 1 commit into from
Aug 20, 2024
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
3 changes: 1 addition & 2 deletions pkg/models/thirdpartyrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package models

import (
"errors"
"fmt"
"regexp"
"strings"

Expand Down Expand Up @@ -66,7 +65,7 @@ func (t *ThirdPartyRepo) ValidateRequest() error {
return errors.New(RepoNameCantBeInvalidMessage)
}
if !ValidateRepoURL(t.URL) {
return fmt.Errorf(InvalidURL)
return errors.New(InvalidURL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could have the Error as a constant directly InvalidURLErr = ..... That way whoever consumes the package can use errors.Is() ... to tell which error was returned (if interested).
Not a big deal, we'd need to refactor all the errors here, which is probably not what we want to do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be a nice follow-up if you'd like :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. Constants are used elsewhere, so we can always add error refactor to the list.

}
return nil
}
Expand Down
36 changes: 18 additions & 18 deletions pkg/routes/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestCreateWasCalledWithNameNotSet(t *testing.T) {
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(jsonImage)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
req, err := http.NewRequest("POST", "/", &buf)
if err != nil {
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestCreate(t *testing.T) {
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(jsonImage)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
req, err := http.NewRequest("POST", "/", &buf)
if err != nil {
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestCreateWithInvalidPackageName(t *testing.T) {
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(jsonImage)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
req, err := http.NewRequest("POST", "/", &buf)
if err != nil {
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestCreateWithThirdPartyRepositoryInfoInvalid(t *testing.T) {
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(jsonImage)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
req, err := http.NewRequest("POST", "/", &buf)
if err != nil {
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestCreateWithImageNameAlreadyExist(t *testing.T) {
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(jsonImage)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
req, err := http.NewRequest("POST", "/", &buf)
if err != nil {
Expand Down Expand Up @@ -312,12 +312,12 @@ func TestGetStatus(t *testing.T) {
}
respBody, err := io.ReadAll(rr.Body)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

err = json.Unmarshal(respBody, &ir)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
}

Expand Down Expand Up @@ -362,12 +362,12 @@ func TestGetImageDetailsById(t *testing.T) {
var ir ImageResponse
respBody, err := io.ReadAll(rr.Body)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

err = json.Unmarshal(respBody, &ir)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

if ir.Packages != 1 {
Expand Down Expand Up @@ -430,12 +430,12 @@ func TestGetImageDetailsByIdWithUpdate(t *testing.T) {
var ir ImageResponse
respBody, err := io.ReadAll(rr.Body)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

err = json.Unmarshal(respBody, &ir)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

if ir.Packages != 1 {
Expand Down Expand Up @@ -692,12 +692,12 @@ func TestGetRepoForImage(t *testing.T) {
var repoResponse models.Repo
respBody, err := io.ReadAll(rr.Body)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

err = json.Unmarshal(respBody, &repoResponse)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

if repoResponse.ID != testRepo.ID {
Expand Down Expand Up @@ -760,12 +760,12 @@ func TestGetImageByOstree(t *testing.T) {
var ir models.Image
respBody, err := io.ReadAll(rr.Body)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

err = json.Unmarshal(respBody, &ir)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

if ir.ID != testImage.ID {
Expand Down Expand Up @@ -793,7 +793,7 @@ func TestPostCheckImageNameAlreadyExist(t *testing.T) {
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(jsonImage)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
req, err := http.NewRequest("POST", "/", &buf)
if err != nil {
Expand Down Expand Up @@ -842,7 +842,7 @@ func TestPostCheckImageNameDoesNotExist(t *testing.T) {
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(jsonImage)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
req, err := http.NewRequest("POST", "/checkImageName", &buf)
if err != nil {
Expand All @@ -865,7 +865,7 @@ func TestPostCheckImageNameDoesNotExist(t *testing.T) {
handler.ServeHTTP(rr, req)
respBody, err := io.ReadAll(rr.Body)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
var ir bool
if err := json.Unmarshal(respBody, &ir); err != nil {
Expand Down