github.com/sacloud/iaas-api-go@v1.12.0/search/equal_expression_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 "encoding/json" 19 "fmt" 20 "testing" 21 "time" 22 23 "github.com/stretchr/testify/require" 24 ) 25 26 func TestEqualExpression(t *testing.T) { 27 targetTime := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) 28 targetTimeString := targetTime.Format(time.RFC3339) 29 30 cases := []struct { 31 input *EqualExpression 32 expect string 33 }{ 34 { 35 input: AndEqual("c1", "c2"), 36 expect: `"c1%20c2"`, 37 }, 38 { 39 input: AndEqual("c1", "", "c2"), 40 expect: `"c1%20%20c2"`, 41 }, 42 { 43 input: OrEqual("c1", "c2"), 44 expect: `["c1","c2"]`, 45 }, 46 { 47 input: OrEqual("c1", nil, "c2"), 48 expect: `["c1","c2"]`, 49 }, 50 { 51 input: OrEqual(1, 2), 52 expect: `["1","2"]`, 53 }, 54 { 55 input: OrEqual(targetTime), 56 expect: fmt.Sprintf(`["%s"]`, targetTimeString), 57 }, 58 } 59 60 for _, tc := range cases { 61 data, err := json.Marshal(tc.input) 62 require.NoError(t, err) 63 require.Equal(t, tc.expect, string(data)) 64 } 65 }