Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl committed Dec 30, 2021
1 parent 3678ebf commit 8e7b85c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
3 changes: 0 additions & 3 deletions resource-service/handler/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ func (p ResourceManager) GetResource(params models.GetResourceParams) (*models.G
}

resourcePath := configPath + "/" + unescapedResourceName
if !p.fileSystem.FileExists(resourcePath) {
return nil, errors.ErrResourceNotFound
}

return p.readResource(gitContext, params, resourcePath)
}
Expand Down
52 changes: 52 additions & 0 deletions resource-service/handler/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ func TestResourceManager_GetResource_ProjectResource(t *testing.T) {
require.Equal(t, fields.git.CheckoutBranchCalls()[0].Branch, "main")

require.Empty(t, fields.git.GetFileRevisionCalls())
require.Len(t, fields.fileSystem.ReadFileCalls(), 1)
}

func TestResourceManager_GetResource_ProjectResource_ProvideGitCommitID(t *testing.T) {
Expand Down Expand Up @@ -737,6 +738,57 @@ func TestResourceManager_GetResource_ProjectResource_ProvideGitCommitID(t *testi
require.Equal(t, "my-commit-id", fields.git.GetFileRevisionCalls()[0].Revision)
}

func TestResourceManager_GetResource_ProjectResource_ProjectNotFound(t *testing.T) {
fields := getTestResourceManagerFields()

fields.git.ProjectExistsFunc = func(gitContext common.GitContext) bool {
return false
}
rm := NewResourceManager(fields.git, fields.credentialReader, fields.fileSystem)

result, err := rm.GetResource(models.GetResourceParams{
Project: models.Project{
ProjectName: "my-project",
},
ResourceURI: "file1",
GetResourceQuery: models.GetResourceQuery{
GitCommitID: "my-commit-id",
},
})

require.NotNil(t, err)

require.Nil(t, result)

require.Empty(t, fields.git.CheckoutBranchCalls())
require.Empty(t, fields.git.GetFileRevisionCalls())
}

func TestResourceManager_GetResource_ProjectResource_InvalidResourceName(t *testing.T) {
fields := getTestResourceManagerFields()

rm := NewResourceManager(fields.git, fields.credentialReader, fields.fileSystem)

result, err := rm.GetResource(models.GetResourceParams{
Project: models.Project{
ProjectName: "my-project",
},
ResourceURI: "fi%le1",
GetResourceQuery: models.GetResourceQuery{
GitCommitID: "my-commit-id",
},
})

require.ErrorIs(t, err, errors2.ErrResourceInvalidResourceURI)

require.Nil(t, result)

require.Len(t, fields.git.CheckoutBranchCalls(), 1)
require.Equal(t, fields.git.CheckoutBranchCalls()[0].Branch, "main")

require.Empty(t, fields.git.GetFileRevisionCalls())
}

type fakeFileInfo struct {
name string
isDir bool
Expand Down

0 comments on commit 8e7b85c

Please sign in to comment.