github.com/blend/go-sdk@v1.20240719.1/webutil/split_colon_test.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package webutil 9 10 import ( 11 "fmt" 12 "testing" 13 14 "github.com/blend/go-sdk/assert" 15 "github.com/blend/go-sdk/ex" 16 ) 17 18 func TestSplitColon(t *testing.T) { 19 assert := assert.New(t) 20 21 // Missing ":" 22 input := "some text" 23 _, _, err := SplitColon(input) 24 assert.True(ErrIsInvalidSplitColonInput(err)) 25 assert.Equal(fmt.Sprintf(`input: %q`, input), ex.ErrMessage(err)) 26 27 // No text before the ":" 28 input = ":p4ssw0rd" 29 _, _, err = SplitColon(input) 30 assert.True(ErrIsInvalidSplitColonInput(err)) 31 assert.Equal(fmt.Sprintf(`input: %q`, input), ex.ErrMessage(err)) 32 33 // No text after the ":" 34 input = "user@mail.invalid:" 35 _, _, err = SplitColon(input) 36 assert.True(ErrIsInvalidSplitColonInput(err)) 37 assert.Equal(fmt.Sprintf(`input: %q`, input), ex.ErrMessage(err)) 38 39 // Valid input value 40 var first, second string 41 first, second, err = SplitColon("cake:eat-it-too") 42 assert.Nil(err) 43 assert.Equal(first, "cake") 44 assert.Equal(second, "eat-it-too") 45 }