|
| 1 | +// +build unit |
| 2 | + |
| 3 | +/* |
| 4 | +Copyright 2018 Iguazio Systems Ltd. |
| 5 | +
|
| 6 | +Licensed under the Apache License, Version 2.0 (the "License") with |
| 7 | +an addition restriction as set forth herein. You may not use this |
| 8 | +file except in compliance with the License. You may obtain a copy of |
| 9 | +the License at http://www.apache.org/licenses/LICENSE-2.0. |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 14 | +implied. See the License for the specific language governing |
| 15 | +permissions and limitations under the License. |
| 16 | +
|
| 17 | +In addition, you may not use the software for any purposes that are |
| 18 | +illegal under applicable law, and the grant of the foregoing license |
| 19 | +under the Apache 2.0 license is conditioned upon your compliance with |
| 20 | +such restriction. |
| 21 | +*/ |
| 22 | + |
| 23 | +package tsdbctl |
| 24 | + |
| 25 | +import ( |
| 26 | + "github.com/stretchr/testify/suite" |
| 27 | + "math" |
| 28 | + "testing" |
| 29 | +) |
| 30 | + |
| 31 | +type testAddSuite struct { |
| 32 | + suite.Suite |
| 33 | +} |
| 34 | + |
| 35 | +func (suite *testAddSuite) TestStrToTV() { |
| 36 | + |
| 37 | + ts, vs, err := strToTV("1533814796000,1533894796000", "10.1,202") |
| 38 | + |
| 39 | + suite.Require().Nil(err) |
| 40 | + suite.Require().Equal(ts, []int64{1533814796000, 1533894796000}) |
| 41 | + suite.Require().Equal(vs, []float64{10.1, 202}) |
| 42 | +} |
| 43 | + |
| 44 | +func (suite *testAddSuite) TestStrToTVSpecialValues() { |
| 45 | + |
| 46 | + ts, vs, err := strToTV("1533814796000,1533894796000,1533899796000", "NaN,Inf,-Inf") |
| 47 | + |
| 48 | + suite.Require().Nil(err) |
| 49 | + suite.Require().Equal(ts, []int64{1533814796000, 1533894796000, 1533899796000}) |
| 50 | + suite.Require().True(math.IsNaN(vs[0])) // NaN != NaN, so we have to check this explicitly |
| 51 | + suite.Require().Equal(vs[1:], []float64{math.Inf(1), math.Inf(-1)}) |
| 52 | +} |
| 53 | + |
| 54 | +func (suite *testAddSuite) TestStrToTVInvalidValue() { |
| 55 | + |
| 56 | + ts, vs, err := strToTV("1533814796000,1533894796000,1533899796000", "1.2,5,z") |
| 57 | + |
| 58 | + suite.Require().Nil(ts) |
| 59 | + suite.Require().Nil(vs) |
| 60 | + suite.Require().Error(err) |
| 61 | +} |
| 62 | + |
| 63 | +func (suite *testAddSuite) TestStrToTVInvalidTime() { |
| 64 | + |
| 65 | + ts, vs, err := strToTV("1533814796000,1533894796000,abc", "1.2,5,5.1") |
| 66 | + |
| 67 | + suite.Require().Nil(ts) |
| 68 | + suite.Require().Nil(vs) |
| 69 | + suite.Require().Error(err) |
| 70 | +} |
| 71 | + |
| 72 | +func TestAddSuite(t *testing.T) { |
| 73 | + suite.Run(t, new(testAddSuite)) |
| 74 | +} |
0 commit comments