|
@@ -6,15 +6,14 @@ import (
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
)
|
|
|
|
|
|
-func TestValue(t *testing.T) {
|
|
|
|
- // Test cases for Value function that generates content-disposition headers
|
|
|
|
|
|
+func TestContentDispositionValue(t *testing.T) {
|
|
|
|
+ // Test cases for ContentDispositionValue function that generates content-disposition headers
|
|
tests := []struct {
|
|
tests := []struct {
|
|
name string
|
|
name string
|
|
url string
|
|
url string
|
|
filename string
|
|
filename string
|
|
ext string
|
|
ext string
|
|
returnAttachment bool
|
|
returnAttachment bool
|
|
- fallback bool
|
|
|
|
expected string
|
|
expected string
|
|
contentType string
|
|
contentType string
|
|
}{
|
|
}{
|
|
@@ -25,7 +24,6 @@ func TestValue(t *testing.T) {
|
|
ext: "",
|
|
ext: "",
|
|
contentType: "",
|
|
contentType: "",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: false,
|
|
|
|
expected: "inline; filename=\"test.jpg\"",
|
|
expected: "inline; filename=\"test.jpg\"",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -35,8 +33,7 @@ func TestValue(t *testing.T) {
|
|
ext: "",
|
|
ext: "",
|
|
contentType: "",
|
|
contentType: "",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: false,
|
|
|
|
- expected: "inline; filename=\"\"",
|
|
|
|
|
|
+ expected: "inline; filename=\"image\"",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "EmptyFilenameWithExt",
|
|
name: "EmptyFilenameWithExt",
|
|
@@ -45,8 +42,7 @@ func TestValue(t *testing.T) {
|
|
ext: ".png",
|
|
ext: ".png",
|
|
contentType: "",
|
|
contentType: "",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: false,
|
|
|
|
- expected: "inline; filename=\".png\"",
|
|
|
|
|
|
+ expected: "inline; filename=\"image.png\"",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "EmptyFilenameWithFilenameAndExt",
|
|
name: "EmptyFilenameWithFilenameAndExt",
|
|
@@ -55,7 +51,6 @@ func TestValue(t *testing.T) {
|
|
ext: ".png",
|
|
ext: ".png",
|
|
contentType: "",
|
|
contentType: "",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: false,
|
|
|
|
expected: "inline; filename=\"example.png\"",
|
|
expected: "inline; filename=\"example.png\"",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -65,7 +60,6 @@ func TestValue(t *testing.T) {
|
|
ext: ".jpg",
|
|
ext: ".jpg",
|
|
contentType: "",
|
|
contentType: "",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: false,
|
|
|
|
expected: "inline; filename=\"example.jpg\"",
|
|
expected: "inline; filename=\"example.jpg\"",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -75,7 +69,6 @@ func TestValue(t *testing.T) {
|
|
ext: ".jpg",
|
|
ext: ".jpg",
|
|
contentType: "",
|
|
contentType: "",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: false,
|
|
|
|
expected: "inline; filename=\"face.jpg\"",
|
|
expected: "inline; filename=\"face.jpg\"",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -85,7 +78,6 @@ func TestValue(t *testing.T) {
|
|
ext: ".jpg",
|
|
ext: ".jpg",
|
|
contentType: "",
|
|
contentType: "",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: false,
|
|
|
|
expected: "inline; filename=\"face.jpg\"",
|
|
expected: "inline; filename=\"face.jpg\"",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -95,7 +87,6 @@ func TestValue(t *testing.T) {
|
|
ext: ".png",
|
|
ext: ".png",
|
|
contentType: "",
|
|
contentType: "",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: true,
|
|
|
|
expected: "inline; filename=\"image.png\"",
|
|
expected: "inline; filename=\"image.png\"",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -105,7 +96,6 @@ func TestValue(t *testing.T) {
|
|
ext: "",
|
|
ext: "",
|
|
contentType: "",
|
|
contentType: "",
|
|
returnAttachment: true,
|
|
returnAttachment: true,
|
|
- fallback: false,
|
|
|
|
expected: "attachment; filename=\"test.jpg\"",
|
|
expected: "attachment; filename=\"test.jpg\"",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -114,7 +104,6 @@ func TestValue(t *testing.T) {
|
|
filename: "my\"file",
|
|
filename: "my\"file",
|
|
ext: ".png",
|
|
ext: ".png",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: false,
|
|
|
|
contentType: "",
|
|
contentType: "",
|
|
expected: "inline; filename=\"my%22file.png\"",
|
|
expected: "inline; filename=\"my%22file.png\"",
|
|
},
|
|
},
|
|
@@ -125,14 +114,13 @@ func TestValue(t *testing.T) {
|
|
ext: "",
|
|
ext: "",
|
|
contentType: "image/png",
|
|
contentType: "image/png",
|
|
returnAttachment: false,
|
|
returnAttachment: false,
|
|
- fallback: false,
|
|
|
|
expected: "inline; filename=\"my%22file.png\"",
|
|
expected: "inline; filename=\"my%22file.png\"",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
|
|
for _, tc := range tests {
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
- result := ContentDispositionValue(tc.url, tc.filename, tc.ext, tc.contentType, tc.returnAttachment, tc.fallback)
|
|
|
|
|
|
+ result := ContentDispositionValue(tc.url, tc.filename, tc.ext, tc.contentType, tc.returnAttachment)
|
|
require.Equal(t, tc.expected, result)
|
|
require.Equal(t, tc.expected, result)
|
|
})
|
|
})
|
|
}
|
|
}
|