-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_test.go
61 lines (50 loc) · 1.52 KB
/
text_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package aurora_test
import (
"os"
"testing"
aurora "github.com/auroraapi/aurora-go"
"github.com/auroraapi/aurora-go/errors"
"github.com/stretchr/testify/require"
)
var apiErrorType *errors.APIError
func TestTextInterpret(t *testing.T) {
query := "what is the weather in los angeles"
text := aurora.NewText(query)
require.Equal(t, query, text.Text)
i, err := text.Interpret()
require.Nil(t, err)
require.NotNil(t, i)
require.Equal(t, "weather", i.Intent)
require.Equal(t, "los angeles", i.Entities["location"])
}
func TestTextInterpretEmptyString(t *testing.T) {
query := ""
text := aurora.NewText(query)
require.Equal(t, query, text.Text)
_, err := text.Interpret()
require.NotNil(t, err)
require.IsType(t, apiErrorType, err)
}
func TestTextInterpretMultipleEntities(t *testing.T) {
query := "what is the weather in los angeles tomorrow"
text := aurora.NewText(query)
require.Equal(t, query, text.Text)
i, err := text.Interpret()
require.Nil(t, err)
require.NotNil(t, i)
require.Equal(t, "weather", i.Intent)
require.Equal(t, "los angeles", i.Entities["location"])
require.Equal(t, "tomorrow", i.Entities["time"])
}
// TestMain sets up testing parameters and runs all tests
func TestMain(m *testing.M) {
// set configuration from environment
aurora.Config.AppID = os.Getenv("APP_ID")
aurora.Config.AppToken = os.Getenv("APP_TOKEN")
aurora.Config.DeviceID = os.Getenv("DEVICE_ID")
if len(os.Getenv("API_HOST")) > 0 {
aurora.Config.Backend.SetBaseURL(os.Getenv("API_HOST"))
}
// run tests
os.Exit(m.Run())
}