Esempio n. 1
0
func runner(t *testing.T, tests []testT, iterable []string) {
	user := dt.User{FlexID: "0", FlexIDType: 3}
	data := struct {
		FlexIDType dt.FlexIDType
		FlexID     string
		CMD        string
	}{
		FlexIDType: user.FlexIDType,
		FlexID:     user.FlexID,
	}
	u := os.Getenv("ABOT_URL") + "/"
	for i, test := range tests {
		in, err := core.NewMsg(&user, test.Input)
		if err != nil {
			t.Fatal(err)
		}
		if i == 1 {
			p.SetMemory(in, keyMem, iterable)
		}
		data.CMD = test.Input
		byt, err := json.Marshal(data)
		if err != nil {
			t.Fatal("failed to marshal req.", err)
		}
		c, b := request("POST", u, byt)
		if c != http.StatusOK {
			t.Fatal("expected", http.StatusOK, "got", c, b)
		}
		if !strings.Contains(b, test.Expected) {
			t.Fatalf("test %d/%d: expected %q, got %q\n", i+1,
				len(tests), test.Expected, b)
		}
	}
	cleanup()
}
Esempio n. 2
0
func TestIsGreeting(t *testing.T) {
	u := &dt.User{ID: 1}
	in, err := core.NewMsg(u, "Hi there")
	if err != nil {
		t.Fatal(err)
	}
	if !IsGreeting(in) {
		t.Fatal("expected greeting")
	}
	in, err = core.NewMsg(u, "Any random sentence.")
	if err != nil {
		t.Fatal(err)
	}
	if IsGreeting(in) {
		t.Fatal("expected not greeting")
	}
}