github.com/hernad/nomad@v1.6.112/nomad/state/indexer/time_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package indexer 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/hernad/nomad/ci" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func Test_IndexFromTimeQuery(t *testing.T) { 15 ci.Parallel(t) 16 17 testCases := []struct { 18 inputArg interface{} 19 expectedOutputBytes []byte 20 expectedOutputError error 21 name string 22 }{ 23 { 24 inputArg: &TimeQuery{ 25 Value: time.Date(1987, time.April, 13, 8, 3, 0, 0, time.UTC), 26 }, 27 expectedOutputBytes: []byte{0x0, 0x0, 0x0, 0x0, 0x20, 0x80, 0x9b, 0xb4}, 28 expectedOutputError: nil, 29 name: "generic test 1", 30 }, 31 { 32 inputArg: &TimeQuery{ 33 Value: time.Date(2022, time.April, 27, 14, 12, 0, 0, time.UTC), 34 }, 35 expectedOutputBytes: []byte{0x0, 0x0, 0x0, 0x0, 0x62, 0x69, 0x4f, 0x30}, 36 expectedOutputError: nil, 37 name: "generic test 2", 38 }, 39 } 40 41 for _, tc := range testCases { 42 t.Run(tc.name, func(t *testing.T) { 43 actualOutput, actualError := IndexFromTimeQuery(tc.inputArg) 44 require.Equal(t, tc.expectedOutputError, actualError) 45 require.Equal(t, tc.expectedOutputBytes, actualOutput) 46 }) 47 } 48 }