cweill / gotests

Automatically generate Go test boilerplate from your source code.
Apache License 2.0
4.92k stars 346 forks source link

add custom template #187

Open neocortexplus opened 8 months ago

neocortexplus commented 8 months ago

hello hope you doing well,

i want to create a custom template so simple template to return the output result in addition of the pass faill tests result ,

i create a simple_template.go and put it in the directory templates but when i run i got some weird messages , i didn't find any place to find a tutorial to help me to create my template,


 {{ define "Test" }}
func Test_{{ .Name }}(t *testing.T) {
    type args struct {
        {{- range .Fields }}
        {{ .Name }} {{ .Type }}
        {{- end }}
    }
    tests := []struct {
        name string
        args args
        want {{ .ResultType }}
    }{
        // TODO: Add test cases here.
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got := {{ .Name }}({{ range $index, $element := .Fields }}{{ if $index }}, {{ end }}tt.args.{{ $element.Name }}{{ end }})
            if got != tt.want {
                t.Errorf("{{ .Name }}() got = %v, want %v", got, tt.want)
            }
        })
    }
}
{{ end }}

root@07598207c071:/home# ls templates/ templates.go root@07598207c071:/home# gotests -w -only combineIntegerArrays -template_dir /home/templates/ . output.Process: render.Header: template: no template "header" associated with template "render"

is there any solution to apply . thanks in advance