2020-01-31 19:57:58 -07:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
2020-02-19 18:03:29 -07:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
2020-10-20 19:05:09 -06:00
|
|
|
"runtime"
|
2020-01-31 19:57:58 -07:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPluginsToMe(t *testing.T) {
|
|
|
|
if ToMe("a", "a") == false {
|
|
|
|
t.Error("ToMe expected true; got false\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPluginsNameRE(t *testing.T) {
|
|
|
|
n := NameRE.ReplaceAllString("@test:test.com", "$1")
|
|
|
|
if n != "test" {
|
|
|
|
t.Errorf("NameRE expected 'test'; got %q\n", n)
|
|
|
|
}
|
|
|
|
}
|
2020-02-19 18:03:29 -07:00
|
|
|
|
2020-05-07 19:34:24 -06:00
|
|
|
func TestPluginsRemoveName(t *testing.T) {
|
|
|
|
expected := "this is for you"
|
|
|
|
n := RemoveName("mctest", fmt.Sprintf("mctest: %s", expected))
|
|
|
|
if n != expected {
|
|
|
|
t.Errorf("Expected %q; got %q\n", expected, n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 18:03:29 -07:00
|
|
|
type testResp struct {
|
|
|
|
Name string `json:"test"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPRequestDoJSON(t *testing.T) {
|
2020-10-20 19:05:09 -06:00
|
|
|
if runtime.GOOS != "plan9" {
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
_, err := fmt.Fprintln(w, `{"test":"success"}`)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
var tr = &testResp{}
|
|
|
|
|
|
|
|
req := HTTPRequest{
|
|
|
|
ResBody: tr,
|
|
|
|
URL: ts.URL,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := req.DoJSON()
|
2020-05-13 17:36:26 -06:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2020-02-19 18:03:29 -07:00
|
|
|
|
2020-10-20 19:05:09 -06:00
|
|
|
if tr.Name != "success" {
|
|
|
|
t.Errorf("Expected 'test'; got '%s'\n", tr.Name)
|
|
|
|
}
|
2020-02-19 18:03:29 -07:00
|
|
|
}
|
|
|
|
}
|