github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/state/paginator/tokenizer_test.go (about) 1 package paginator 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/nomad/ci" 8 "github.com/hashicorp/nomad/nomad/mock" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestStructsTokenizer(t *testing.T) { 13 ci.Parallel(t) 14 15 j := mock.Job() 16 17 cases := []struct { 18 name string 19 opts StructsTokenizerOptions 20 expected string 21 }{ 22 { 23 name: "ID", 24 opts: StructsTokenizerOptions{ 25 WithID: true, 26 }, 27 expected: fmt.Sprintf("%v", j.ID), 28 }, 29 { 30 name: "Namespace.ID", 31 opts: StructsTokenizerOptions{ 32 WithNamespace: true, 33 WithID: true, 34 }, 35 expected: fmt.Sprintf("%v.%v", j.Namespace, j.ID), 36 }, 37 { 38 name: "CreateIndex.Namespace.ID", 39 opts: StructsTokenizerOptions{ 40 WithCreateIndex: true, 41 WithNamespace: true, 42 WithID: true, 43 }, 44 expected: fmt.Sprintf("%v.%v.%v", j.CreateIndex, j.Namespace, j.ID), 45 }, 46 { 47 name: "CreateIndex.ID", 48 opts: StructsTokenizerOptions{ 49 WithCreateIndex: true, 50 WithID: true, 51 }, 52 expected: fmt.Sprintf("%v.%v", j.CreateIndex, j.ID), 53 }, 54 { 55 name: "CreateIndex.Namespace", 56 opts: StructsTokenizerOptions{ 57 WithCreateIndex: true, 58 WithNamespace: true, 59 }, 60 expected: fmt.Sprintf("%v.%v", j.CreateIndex, j.Namespace), 61 }, 62 } 63 64 for _, tc := range cases { 65 t.Run(tc.name, func(t *testing.T) { 66 tokenizer := StructsTokenizer{opts: tc.opts} 67 require.Equal(t, tc.expected, tokenizer.GetToken(j)) 68 }) 69 } 70 }