Skip to content

Commit

Permalink
test: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryooooooga committed Jun 12, 2023
1 parent ed20638 commit 29675a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
5 changes: 1 addition & 4 deletions pkg/commands/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ func (cmd *Command) previewFile(filename string) error {
return fmt.Errorf("template for %s does not exist", filename)
}

data, err := templateVariables(filename, tpl)
if err != nil {
return err
}
data := templateVariables(filename, tpl)

if err := cmd.Renderer.RenderTemplate(cmd.Output, tpl, data); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestPreview(t *testing.T) {
cmd := newTestCommand(t, false, false)

err := cmd.Preview(s.files)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, s.expectedOutput, cmd.Output.(*bytes.Buffer).String())
})
}
Expand Down
11 changes: 4 additions & 7 deletions pkg/commands/touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ func (cmd *Command) renderTemplate(filename string, tpl *repositories.TemplateFi
}
defer output.Close()

data, err := templateVariables(filename, tpl)
if err != nil {
return err
}
data := templateVariables(filename, tpl)

if err := cmd.Renderer.RenderTemplate(output, tpl, data); err != nil {
return err
Expand All @@ -106,16 +103,16 @@ func (cmd *Command) renderTemplate(filename string, tpl *repositories.TemplateFi
return nil
}

func templateVariables(filename string, tpl *repositories.TemplateFile) (map[string]any, error) {
func templateVariables(filename string, tpl *repositories.TemplateFile) map[string]any {
filepath, err := filepath.Abs(filename)
if err != nil {
return nil, err
filepath = filename
}

return map[string]any{
"Filename": filename,
"Filepath": filepath,
"TemplateFilename": tpl.Path,
"TemplateFilepath": tpl.Path,
}, nil
}
}

0 comments on commit 29675a1

Please sign in to comment.