github.com/GoogleCloudPlatform/compute-image-tools/cli_tools@v0.0.0-20240516224744-de2dabc4ed1b/common/utils/flags/string_utils_test.go (about) 1 // Copyright 2020 Google Inc. All Rights Reserved. 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 flags 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 const expected = "test string" 24 25 func TestTrimmedStringSetTrimsSpace(t *testing.T) { 26 input := " test string " 27 var s = TrimmedString("") 28 err := s.Set(input) 29 assert.Nil(t, err) 30 assert.Equal(t, expected, string(s)) 31 } 32 33 func TestTrimmedStringStringReturnsString(t *testing.T) { 34 var s = TrimmedString(expected) 35 output := s.String() 36 assert.Equal(t, expected, output) 37 } 38 39 func TestLowerTrimmedStringSetTrimsSpace(t *testing.T) { 40 input := " TeSt StRiNg " 41 var s = LowerTrimmedString("") 42 err := s.Set(input) 43 assert.Nil(t, err) 44 assert.Equal(t, expected, string(s)) 45 } 46 47 func TestLowerTrimmedStringStringReturnsString(t *testing.T) { 48 var s = LowerTrimmedString(expected) 49 output := s.String() 50 assert.Equal(t, expected, output) 51 }