github.com/sacloud/iaas-api-go@v1.12.0/search/key_test.go (about)

     1  // Copyright 2022-2023 The sacloud/iaas-api-go Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package search
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  func TestKey(t *testing.T) {
    24  	cases := []struct {
    25  		input  FilterKey
    26  		expect string
    27  	}{
    28  		{
    29  			input: FilterKey{
    30  				Field: "field",
    31  				Op:    OpEqual,
    32  			},
    33  			expect: "field",
    34  		},
    35  		{
    36  			input: FilterKey{
    37  				Field: "field",
    38  				Op:    OpGreaterThan,
    39  			},
    40  			expect: "field>",
    41  		},
    42  		{
    43  			input: FilterKey{
    44  				Field: "field",
    45  				Op:    OpGreaterEqual,
    46  			},
    47  			expect: "field>=",
    48  		},
    49  		{
    50  			input: FilterKey{
    51  				Field: "field",
    52  				Op:    OpLessThan,
    53  			},
    54  			expect: "field<",
    55  		},
    56  		{
    57  			input: FilterKey{
    58  				Field: "field",
    59  				Op:    OpLessEqual,
    60  			},
    61  			expect: "field<=",
    62  		},
    63  		{
    64  			input: FilterKey{
    65  				Field: "another-field-name",
    66  				Op:    OpEqual,
    67  			},
    68  			expect: "another-field-name",
    69  		},
    70  	}
    71  
    72  	for _, tc := range cases {
    73  		require.Equal(t, tc.expect, tc.input.String())
    74  	}
    75  }