42 lines
758 B
Go
42 lines
758 B
Go
package playground
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestShare(t *testing.T) {
|
|
var resp string
|
|
contents := "test"
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
resp += "test-"
|
|
_, _ = w.Write([]byte(resp))
|
|
}))
|
|
shareURL = server.URL
|
|
|
|
link, err := Share(context.Background(), contents)
|
|
if err != nil {
|
|
t.Log(err)
|
|
t.FailNow()
|
|
}
|
|
|
|
if !strings.EqualFold(link, resp) {
|
|
t.Logf("Expected `%s` but got `%s`\n", resp, link)
|
|
t.FailNow()
|
|
}
|
|
|
|
link2, err := Share(context.Background(), contents)
|
|
if err != nil {
|
|
t.Log(err)
|
|
t.FailNow()
|
|
}
|
|
|
|
if !strings.EqualFold(link2, "test-") {
|
|
t.Logf("Expected `test-` but got `%s`\n", link2)
|
|
t.FailNow()
|
|
}
|
|
}
|