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