github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/state/indexer/time_test.go (about)

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