go-frameproto/appendframeimage_test.go

97 lines
2.1 KiB
Go
Raw Normal View History

2024-02-15 00:27:07 +00:00
package frameproto
import (
"testing"
)
func TestAppendFrameImage(t *testing.T) {
tests := []struct{
2024-02-15 00:32:48 +00:00
URL string
2024-02-15 00:27:07 +00:00
Expected string
}{
{
2024-02-15 00:32:48 +00:00
URL: "",
2024-02-15 00:27:07 +00:00
Expected: `<meta property="fc:frame:image" content="" />`+"\n",
},
{
2024-02-15 00:32:48 +00:00
URL: "something",
2024-02-15 00:27:07 +00:00
Expected: `<meta property="fc:frame:image" content="something" />`+"\n",
},
{
2024-02-15 00:32:48 +00:00
URL: "Hello world! 🙂",
2024-02-15 00:27:07 +00:00
Expected: `<meta property="fc:frame:image" content="Hello world! 🙂" />`+"\n",
},
{
2024-02-15 00:32:48 +00:00
URL: "https://example.com/path/to/post/to.png",
2024-02-15 00:27:07 +00:00
Expected: `<meta property="fc:frame:image" content="https://example.com/path/to/post/to.png" />`+"\n",
},
{
2024-02-15 00:32:48 +00:00
URL: "x-proto:apple/banana/cherry",
2024-02-15 00:27:07 +00:00
Expected: `<meta property="fc:frame:image" content="x-proto:apple/banana/cherry" />`+"\n",
},
}
for testNumber, test := range tests {
{
var buffer [256]byte
var p []byte = buffer[0:0]
2024-02-15 00:32:48 +00:00
p = AppendFrameImage(p, test.URL)
2024-02-15 00:27:07 +00:00
expected := test.Expected
actual := string(p)
if expected != actual {
t.Errorf("For test #%d, the actual written meta-tag is not what was expected.", testNumber)
t.Logf("EXPECTED: %s", expected)
t.Logf("ACTUAL: %s", actual)
t.Logf("EXPECTED: %q", expected)
t.Logf("ACTUAL: %q", actual)
2024-02-15 00:32:48 +00:00
t.Logf("URL: %q", test.URL)
2024-02-15 00:27:07 +00:00
continue
}
}
{
const top string = "<html>\n<head>\n"
const bottom string = "</head>\n<body>\n</body>\n</html>\n"
var buffer [256]byte
var p []byte = buffer[0:0]
p = append(p, top...)
2024-02-15 00:32:48 +00:00
p = AppendFrameImage(p, test.URL)
2024-02-15 00:27:07 +00:00
p = append(p, bottom...)
expected := top + test.Expected + bottom
actual := string(p)
if expected != actual {
t.Errorf("For test #%d, the actual written meta-tag is not what was expected.", testNumber)
t.Logf("EXPECTED: %s", expected)
t.Logf("ACTUAL: %s", actual)
t.Logf("EXPECTED: %q", expected)
t.Logf("ACTUAL: %q", actual)
2024-02-15 00:32:48 +00:00
t.Logf("URL: %q", test.URL)
2024-02-15 00:27:07 +00:00
continue
}
}
}
}