github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/entity/collection_attr_test.go (about)

     1  // Copyright (C) 2019-2021 Zilliz. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
     4  // with the License. You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software distributed under the License
     9  // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
    10  // or implied. See the License for the specific language governing permissions and limitations under the License.
    11  
    12  package entity
    13  
    14  import (
    15  	"fmt"
    16  	"strconv"
    17  	"testing"
    18  
    19  	"github.com/stretchr/testify/suite"
    20  )
    21  
    22  type CollectionTTLSuite struct {
    23  	suite.Suite
    24  }
    25  
    26  func (s *CollectionTTLSuite) TestValid() {
    27  	type testCase struct {
    28  		input     string
    29  		expectErr bool
    30  	}
    31  
    32  	cases := []testCase{
    33  		{input: "a", expectErr: true},
    34  		{input: "1000", expectErr: false},
    35  		{input: "0", expectErr: false},
    36  		{input: "-10", expectErr: true},
    37  	}
    38  
    39  	for _, tc := range cases {
    40  		s.Run(tc.input, func() {
    41  			ca := ttlCollAttr{}
    42  			ca.value = tc.input
    43  			err := ca.Valid()
    44  			if tc.expectErr {
    45  				s.Error(err)
    46  			} else {
    47  				s.NoError(err)
    48  			}
    49  		})
    50  	}
    51  }
    52  
    53  func (s *CollectionTTLSuite) TestCollectionTTL() {
    54  	type testCase struct {
    55  		input     int64
    56  		expectErr bool
    57  	}
    58  
    59  	cases := []testCase{
    60  		{input: 1000, expectErr: false},
    61  		{input: 0, expectErr: false},
    62  		{input: -10, expectErr: true},
    63  	}
    64  
    65  	for _, tc := range cases {
    66  		s.Run(fmt.Sprintf("%d", tc.input), func() {
    67  			ca := CollectionTTL(tc.input)
    68  			key, value := ca.KeyValue()
    69  			s.Equal(cakTTL, key)
    70  			s.Equal(strconv.FormatInt(tc.input, 10), value)
    71  			err := ca.Valid()
    72  			if tc.expectErr {
    73  				s.Error(err)
    74  			} else {
    75  				s.NoError(err)
    76  			}
    77  		})
    78  	}
    79  }
    80  
    81  func TestCollectionTTL(t *testing.T) {
    82  	suite.Run(t, new(CollectionTTLSuite))
    83  }
    84  
    85  type CollectionAutoCompactionSuite struct {
    86  	suite.Suite
    87  }
    88  
    89  func (s *CollectionAutoCompactionSuite) TestValid() {
    90  	type testCase struct {
    91  		input     string
    92  		expectErr bool
    93  	}
    94  
    95  	cases := []testCase{
    96  		{input: "a", expectErr: true},
    97  		{input: "true", expectErr: false},
    98  		{input: "false", expectErr: false},
    99  		{input: "", expectErr: true},
   100  	}
   101  
   102  	for _, tc := range cases {
   103  		s.Run(tc.input, func() {
   104  			ca := autoCompactionCollAttr{}
   105  			ca.value = tc.input
   106  			err := ca.Valid()
   107  			if tc.expectErr {
   108  				s.Error(err)
   109  			} else {
   110  				s.NoError(err)
   111  			}
   112  		})
   113  	}
   114  }
   115  
   116  func (s *CollectionAutoCompactionSuite) TestCollectionAutoCompactionEnabled() {
   117  
   118  	cases := []bool{true, false}
   119  
   120  	for _, tc := range cases {
   121  		s.Run(fmt.Sprintf("%v", tc), func() {
   122  			ca := CollectionAutoCompactionEnabled(tc)
   123  			key, value := ca.KeyValue()
   124  			s.Equal(cakAutoCompaction, key)
   125  			s.Equal(strconv.FormatBool(tc), value)
   126  		})
   127  	}
   128  }
   129  
   130  func TestCollectionAutoCompaction(t *testing.T) {
   131  	suite.Run(t, new(CollectionAutoCompactionSuite))
   132  }