From c6a8ea629d0a562cee808a488242225cde835d7d Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Thu, 12 May 2022 11:31:10 -0500 Subject: [PATCH] wip add test --- dependency/nomad_services_test.go | 55 ++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/dependency/nomad_services_test.go b/dependency/nomad_services_test.go index c0736d774..c56bdaf47 100644 --- a/dependency/nomad_services_test.go +++ b/dependency/nomad_services_test.go @@ -53,17 +53,55 @@ func TestNewNomadServicesQueryQuery(t *testing.T) { } } -func TestNomadServicesQuery_Fetch(t *testing.T) { +func TestNomadServicesQuery_Fetch_1arg(t *testing.T) { + cases := []struct { + name string + service string + exp []*NomadServicesSnippet + }{ + { + name: "all", + service: "", + exp: []*NomadServicesSnippet{ + &NomadServicesSnippet{ + Name: "example-cache", + Tags: ServiceTags([]string{"tag1", "tag2"}), + }, + }, + }, + } + + for i, tc := range cases { + t.Run(fmt.Sprintf("%d_%s", i, tc.name), func(t *testing.T) { + d, err := NewNomadServicesQuery(tc.service) + if err != nil { + t.Fatal(err) + } + act, _, err := d.Fetch(testClients, nil) + if err != nil { + t.Fatal(err) + } + + require.Equal(t, tc.exp, act) + }) + } +} + +func TestNomadServicesQuery_Fetch_3arg(t *testing.T) { cases := []struct { - name string - i string - exp []*NomadServicesSnippet + name string + service string + count int + key string + exp []*NomadServicesSnippet }{ { - "all", - "", - []*NomadServicesSnippet{ + name: "choose one", + service: "example-cache", + count: 1, + key: "abc123", + exp: []*NomadServicesSnippet{ &NomadServicesSnippet{ Name: "example-cache", Tags: ServiceTags([]string{"tag1", "tag2"}), @@ -74,7 +112,7 @@ func TestNomadServicesQuery_Fetch(t *testing.T) { for i, tc := range cases { t.Run(fmt.Sprintf("%d_%s", i, tc.name), func(t *testing.T) { - d, err := NewNomadServicesQuery(tc.i) + d, err := NewNomadServiceChooseQuery(tc.count, tc.key, tc.service) if err != nil { t.Fatal(err) } @@ -88,6 +126,7 @@ func TestNomadServicesQuery_Fetch(t *testing.T) { }) } } + func TestNomadServicesQuery_String(t *testing.T) { cases := []struct {