3943dd1e16
This is a followup to running tests in serial in CI. Since the API package cannot import anything outside of api/, copy the ci.Parallel function into api/internal/testutil, and have api tests use that.
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/nomad/api/contexts"
|
|
"github.com/hashicorp/nomad/api/internal/testutil"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSearch_PrefixSearch(t *testing.T) {
|
|
testutil.Parallel(t)
|
|
|
|
c, s := makeClient(t, nil, nil)
|
|
defer s.Stop()
|
|
|
|
job := testJob()
|
|
_, _, err := c.Jobs().Register(job, nil)
|
|
require.NoError(t, err)
|
|
|
|
id := *job.ID
|
|
prefix := id[:len(id)-2]
|
|
resp, qm, err := c.Search().PrefixSearch(prefix, contexts.Jobs, nil)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, qm)
|
|
require.NotNil(t, resp)
|
|
|
|
jobMatches := resp.Matches[contexts.Jobs]
|
|
require.Len(t, jobMatches, 1)
|
|
require.Equal(t, id, jobMatches[0])
|
|
}
|
|
|
|
func TestSearch_FuzzySearch(t *testing.T) {
|
|
testutil.Parallel(t)
|
|
|
|
c, s := makeClient(t, nil, nil)
|
|
defer s.Stop()
|
|
|
|
job := testJob()
|
|
_, _, err := c.Jobs().Register(job, nil)
|
|
require.NoError(t, err)
|
|
|
|
resp, qm, err := c.Search().FuzzySearch("bin", contexts.All, nil)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, qm)
|
|
require.NotNil(t, resp)
|
|
|
|
commandMatches := resp.Matches[contexts.Commands]
|
|
require.Len(t, commandMatches, 1)
|
|
require.Equal(t, "/bin/sleep", commandMatches[0].ID)
|
|
require.Equal(t, []string{
|
|
"default", *job.ID, "group1", "task1",
|
|
}, commandMatches[0].Scope)
|
|
}
|