2024-02-14 23:58:51 +00:00
|
|
|
package frameproto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAppendFramePostURL(t *testing.T) {
|
|
|
|
|
|
|
|
tests := []struct{
|
2024-02-15 00:37:13 +00:00
|
|
|
URL string
|
2024-02-14 23:58:51 +00:00
|
|
|
Expected string
|
|
|
|
}{
|
|
|
|
{
|
2024-02-15 00:37:13 +00:00
|
|
|
URL: "",
|
2024-02-14 23:58:51 +00:00
|
|
|
Expected: `<meta property="fc:frame:post_url" content="" />`+"\n",
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
2024-02-15 00:37:13 +00:00
|
|
|
URL: "something",
|
2024-02-14 23:58:51 +00:00
|
|
|
Expected: `<meta property="fc:frame:post_url" content="something" />`+"\n",
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
2024-02-15 00:37:13 +00:00
|
|
|
URL: "Hello world! 🙂",
|
2024-02-14 23:58:51 +00:00
|
|
|
Expected: `<meta property="fc:frame:post_url" content="Hello world! 🙂" />`+"\n",
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
2024-02-15 00:37:13 +00:00
|
|
|
URL: "https://example.com/path/to/post/to.php",
|
2024-02-14 23:58:51 +00:00
|
|
|
Expected: `<meta property="fc:frame:post_url" content="https://example.com/path/to/post/to.php" />`+"\n",
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
2024-02-15 00:37:13 +00:00
|
|
|
URL: "x-proto:apple/banana/cherry",
|
2024-02-14 23:58:51 +00:00
|
|
|
Expected: `<meta property="fc:frame:post_url" 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:37:13 +00:00
|
|
|
p = AppendFramePostURL(p, test.URL)
|
2024-02-14 23:58:51 +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:37:13 +00:00
|
|
|
t.Logf("URL: %q", test.URL)
|
2024-02-14 23:58:51 +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:37:13 +00:00
|
|
|
p = AppendFramePostURL(p, test.URL)
|
2024-02-14 23:58:51 +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:37:13 +00:00
|
|
|
t.Logf("URL: %q", test.URL)
|
2024-02-14 23:58:51 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|