2017-08-08 21:59:21 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2017-08-10 19:24:11 +00:00
|
|
|
|
2017-08-11 13:33:00 +00:00
|
|
|
"github.com/hashicorp/nomad/api/contexts"
|
2018-02-23 16:23:32 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-08-08 21:59:21 +00:00
|
|
|
)
|
|
|
|
|
2017-08-10 19:24:11 +00:00
|
|
|
func TestSearch_List(t *testing.T) {
|
2018-02-23 16:23:32 +00:00
|
|
|
require := require.New(t)
|
2017-08-08 21:59:21 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
c, s := makeClient(t, nil, nil)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
job := testJob()
|
|
|
|
_, _, err := c.Jobs().Register(job, nil)
|
2018-02-23 16:23:32 +00:00
|
|
|
require.Nil(err)
|
2017-08-08 21:59:21 +00:00
|
|
|
|
|
|
|
id := *job.ID
|
|
|
|
prefix := id[:len(id)-2]
|
2017-08-28 05:17:51 +00:00
|
|
|
resp, qm, err := c.Search().PrefixSearch(prefix, contexts.Jobs, nil)
|
2017-08-08 21:59:21 +00:00
|
|
|
|
2018-02-23 16:23:32 +00:00
|
|
|
require.Nil(err)
|
|
|
|
require.NotNil(qm)
|
|
|
|
require.NotNil(qm)
|
2017-08-08 21:59:21 +00:00
|
|
|
|
2017-08-11 14:44:46 +00:00
|
|
|
jobMatches := resp.Matches[contexts.Jobs]
|
2018-02-23 16:23:32 +00:00
|
|
|
require.Equal(1, len(jobMatches))
|
|
|
|
require.Equal(id, jobMatches[0])
|
2017-08-08 21:59:21 +00:00
|
|
|
}
|