Skip to content
Snippets Groups Projects
Commit 7f14f157 authored by Danis Kirasirov's avatar Danis Kirasirov
Browse files

add unittests for SetURLWithTemplate()

parent 58a85488
No related branches found
No related tags found
No related merge requests found
package files
import (
"testing"
"text/template"
"github.com/stretchr/testify/require"
)
func TestFile_SetURLWithTemplate(t *testing.T) {
tests := []struct {
name string
file *File
template *template.Template
wantErr bool
wantURL string
}{
{
name: "template is nil",
file: &File{
URL: "https://cloud.com/",
},
template: nil,
wantErr: false,
wantURL: "https://cloud.com/",
},
{
name: "template is bad",
file: &File{},
template: template.Must(template.New("url").Parse("{{.NonExistentField}}")),
wantErr: true,
},
{
name: "success",
file: &File{
Size: 1024,
MimeType: "image/png",
Key: "file-key",
},
template: template.Must(template.New("url").Parse("https://cloud-proxy.com/{{.Key}}?size={{.Size}}#{{.MimeType}}")),
wantErr: false,
wantURL: "https://cloud-proxy.com/file-key?size=1024#image/png",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.file.SetURLWithTemplate(tt.template)
if tt.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, tt.wantURL, tt.file.URL)
}
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment