Skip to content

Commit

Permalink
MGMT-15295: Fixc bug in list manifests (#5366)
Browse files Browse the repository at this point in the history
While making a behavioural change to the way in which we list manifests 689a73c
A bug was introduced. This bug causes a crash when manifests are listed.

This PR corrects the bug and introduces a test of the code in which the
bug was found
  • Loading branch information
paul-maidment committed Jul 19, 2023
1 parent 6091d13 commit 56151a0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
2 changes: 0 additions & 2 deletions internal/manifests/manifests.go
Expand Up @@ -172,8 +172,6 @@ func (m *Manifests) ListClusterManifestsInternal(ctx context.Context, params ope
}
if isUserManifest {
manifests = append(manifests, &models.Manifest{FileName: filename, Folder: folder})
} else {
return nil, common.NewApiError(http.StatusInternalServerError, errors.Errorf("Cannot list file %s in cluster %s", file, params.ClusterID.String()))
}
}
return manifests, nil
Expand Down
41 changes: 33 additions & 8 deletions internal/manifests/manifests_test.go
Expand Up @@ -885,14 +885,6 @@ spec:
})

Describe("IsUserManifest", func() {
var (
manifestsAPI *manifests.Manifests
db *gorm.DB
ctx = context.Background()
ctrl *gomock.Controller
mockS3Client *s3wrapper.MockAPI
)

BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
mockS3Client = s3wrapper.NewMockAPI(ctrl)
Expand Down Expand Up @@ -924,6 +916,39 @@ spec:
Expect(manifestsAPI.IsUserManifest(ctx, clusterId, "openshift", "system-generated-manifest.yaml")).To(BeFalse())
})
})

Describe("ListClusterManifestsInternal", func() {
It("Should be able to list only user manifests if user and non user manifests are present", func() {
clusterId := registerCluster().ID
manifests := []string{
filepath.Join(clusterId.String(), constants.ManifestFolder, "openshift", "system-generated-manifest.yaml"),
filepath.Join(clusterId.String(), constants.ManifestFolder, "openshift", "user-generated-manifest.yaml"),
}
objectName := filepath.Join(clusterId.String(), constants.ManifestFolder)
mockS3Client.EXPECT().ListObjectsByPrefix(ctx, objectName).Return(manifests, nil).Times(1)
mockS3Client.EXPECT().DoesObjectExist(
ctx,
filepath.Join(
clusterId.String(),
constants.ManifestMetadataFolder,
"openshift",
"system-generated-manifest.yaml", "user-supplied")).Return(false, nil).Times(1)
mockS3Client.EXPECT().DoesObjectExist(
ctx,
filepath.Join(
clusterId.String(),
constants.ManifestMetadataFolder,
"openshift",
"user-generated-manifest.yaml", "user-supplied")).Return(true, nil).Times(1)
listedManifests, err := manifestsAPI.ListClusterManifestsInternal(ctx, operations.V2ListClusterManifestsParams{
ClusterID: *clusterId,
})
Expect(err).NotTo(HaveOccurred())
Expect(len(listedManifests)).To(Equal(1))
Expect(listedManifests[0].Folder).To(Equal("openshift"))
Expect(listedManifests[0].FileName).To(Equal("user-generated-manifest.yaml"))
})
})
})

type VoidReadCloser struct {
Expand Down

0 comments on commit 56151a0

Please sign in to comment.