Skip to content

Commit

Permalink
wip add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed May 12, 2022
1 parent c6a8ea6 commit 2758940
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dependency/nomad_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ func NewNomadServiceQuery(s string) (*NomadServiceQuery, error) {
}, nil
}

func NewNomadServiceChooseQuery(count int, hash string, s string) (*NomadServiceQuery, error) {
// NewNomadServiceChooseQuery parses s using NewNomadServiceQuery, and then also
// configures the resulting query with the choose parameter set according to the
// count and key arguments.
func NewNomadServiceChooseQuery(count int, key, s string) (*NomadServiceQuery, error) {
query, err := NewNomadServiceQuery(s)
if err != nil {
return nil, err
}

choose := fmt.Sprintf("%d|%s", count, hash)
choose := fmt.Sprintf("%d|%s", count, key)
query.choose = choose

return query, nil
Expand Down
48 changes: 48 additions & 0 deletions dependency/nomad_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ func TestNewNomadServiceQuery(t *testing.T) {
},
false,
},
{
"choose",
"name:1|abc123",
&NomadServiceQuery{
name: "name",
choose: "1|abc123",
},
false,
},
{
"tag_Name_region_choose",
"tag.name@us-east-1:1|abc123",
&NomadServiceQuery{
region: "us-east-1",
name: "name",
tag: "tag",
choose: "1:abc123",
},
false,
},
}

for i, tc := range cases {
Expand Down Expand Up @@ -234,3 +254,31 @@ func TestNomadServiceQuery_String(t *testing.T) {
})
}
}

func TestNomadServiceQuery_String_3arg(t *testing.T) {
cases := []struct {
name string
i string
count int
key string
exp string
}{
{
"choose",
"redis",
3,
"abc123",
"nomad.service(redis:3|abc123)",
},
}

for i, tc := range cases {
t.Run(fmt.Sprintf("%d_%s", i, tc.name), func(t *testing.T) {
d, err := NewNomadServiceChooseQuery(3, "abc123", tc.i)
if err != nil {
t.Fatal(err)
}
require.Equal(t, tc.exp, d.String())
})
}
}

0 comments on commit 2758940

Please sign in to comment.