Skip to content

Commit

Permalink
test: Add template loading test with different path separators
Browse files Browse the repository at this point in the history
  • Loading branch information
UnseenWizzard authored and Laubi committed May 24, 2023
1 parent 00a572a commit fcafaf9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/config/v2/template/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ package template
import (
"fmt"
"github.com/dynatrace/dynatrace-configuration-as-code/internal/log"
"github.com/spf13/afero"
"path/filepath"
"strings"

"github.com/spf13/afero"
)

// Template is the main interface of a configuration payload that may contain template references (using Go Templates)
Expand Down
36 changes: 36 additions & 0 deletions pkg/config/v2/template/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,42 @@ func TestLoadTemplate_ReturnsErrorIfFileDoesNotExist(t *testing.T) {
assert.ErrorContains(t, gotErr, testFilepath)
}

func TestLoadTemplate_WorksWithAnyPathSeparator(t *testing.T) {

testFs := afero.NewReadOnlyFs(afero.NewOsFs())
tests := []struct {
name string
givenFilepath string
}{
{
"windows path",
`test-resources\template.json`,
},
{
"relative windows path",
`..\template\test-resources\template.json`,
},
{
"unix path",
`test-resources/template.json`,
},
{
"relative unix path",
`../template/test-resources/template.json`,
},
{
"mixed path",
`..\template\test-resources/template.json`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, gotErr := LoadTemplate(testFs, tt.givenFilepath)
assert.NilError(t, gotErr)
})
}
}

func Test_fileBasedTemplate_Id_Returns_Path(t *testing.T) {
template := fileBasedTemplate{
path: "PATH",
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/v2/template/test-resources/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": {{ .name }}
}

0 comments on commit fcafaf9

Please sign in to comment.