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

Refactor to remove unnecessary error in the return values #5617

Merged
merged 1 commit into from
Mar 3, 2025
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
4 changes: 2 additions & 2 deletions pkg/app/pipedv1/plugin/kubernetes/deployment/determine.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func parseContainerImage(image string) (img containerImage) {

// determineVersions decides artifact versions of an application.
// It finds all container images that are being specified in the workload manifests then returns their names and tags.
func determineVersions(manifests []provider.Manifest) ([]*model.ArtifactVersion, error) {
func determineVersions(manifests []provider.Manifest) []*model.ArtifactVersion {
imageMap := map[string]struct{}{}
for _, m := range manifests {
for _, c := range provider.FindContainerImages(m) {
Expand All @@ -66,7 +66,7 @@ func determineVersions(manifests []provider.Manifest) ([]*model.ArtifactVersion,
})
}

return versions, nil
return versions
}

// findManifests returns the manifests that have the specified kind and name.
Expand Down
17 changes: 6 additions & 11 deletions pkg/app/pipedv1/plugin/kubernetes/deployment/determine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ func TestParseContainerImage(t *testing.T) {
}
}
func TestDetermineVersions(t *testing.T) {
t.Parallel()

tests := []struct {
name string
manifests []string
want []*model.ArtifactVersion
wantErr bool
}{
{
name: "single manifest with one container",
Expand Down Expand Up @@ -247,8 +248,7 @@ spec:
spec: {}
`,
},
want: []*model.ArtifactVersion{},
wantErr: false,
want: []*model.ArtifactVersion{},
},
{
name: "manifest with invalid containers field -- skipped",
Expand All @@ -265,23 +265,18 @@ spec:
- "invalid-containers-field"
`,
},
wantErr: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

var manifests []provider.Manifest
for _, data := range tt.manifests {
manifests = append(manifests, mustUnmarshalYAML[provider.Manifest](t, []byte(strings.TrimSpace(data))))
}
got, err := determineVersions(manifests)
if tt.wantErr {
require.Error(t, err)
return
} else {
require.NoError(t, err)
}
got := determineVersions(manifests)
assert.ElementsMatch(t, tt.want, got)
})
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/app/pipedv1/plugin/kubernetes/deployment/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,8 @@
return nil, status.Error(codes.Internal, err.Error())
}

versions, err := determineVersions(manifests)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &deployment.DetermineVersionsResponse{
Versions: versions,
Versions: determineVersions(manifests),

Check warning on line 149 in pkg/app/pipedv1/plugin/kubernetes/deployment/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/plugin/kubernetes/deployment/server.go#L149

Added line #L149 was not covered by tests
}, nil
}

Expand Down
Loading