github.com/m3db/m3@v1.5.0/src/query/functions/unconsolidated/timestamp_test.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package unconsolidated
    22  
    23  import (
    24  	"testing"
    25  	"time"
    26  
    27  	"github.com/m3db/m3/src/query/executor/transform"
    28  	"github.com/m3db/m3/src/query/models"
    29  	"github.com/m3db/m3/src/query/parser"
    30  	"github.com/m3db/m3/src/query/test"
    31  	"github.com/m3db/m3/src/query/test/executor"
    32  
    33  	"github.com/stretchr/testify/assert"
    34  	"github.com/stretchr/testify/require"
    35  )
    36  
    37  func TestTimestamp(t *testing.T) {
    38  	values, bounds := test.GenerateValuesAndBounds(nil, nil)
    39  	block := test.NewBlockFromValues(bounds, values)
    40  	c, sink := executor.NewControllerWithSink(parser.NodeID(rune(1)))
    41  	node := newTimestampOp(TimestampType).Node(c, transform.Options{})
    42  	err := node.Process(models.NoopQueryContext(), parser.NodeID(rune(0)), block)
    43  	require.NoError(t, err)
    44  	assert.Len(t, sink.Values, 2)
    45  
    46  	start := bounds.Start
    47  	step := bounds.StepSize
    48  	for _, vals := range sink.Values {
    49  		for i, val := range vals {
    50  			expected := float64(start.Add(time.Duration(i) * step).Seconds())
    51  			diff := expected - val
    52  			assert.True(t, diff < 1)
    53  		}
    54  	}
    55  }