github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/internal/i18n/messages_test.go (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package i18n 18 19 import ( 20 "context" 21 "testing" 22 23 "github.com/stretchr/testify/assert" 24 "golang.org/x/text/language" 25 ) 26 27 func TestExpand(t *testing.T) { 28 lang := language.Make("en") 29 ctx := WithLang(context.Background(), lang) 30 str := Expand(ctx, MsgWebsocketClientError, "myinsert") 31 assert.Equal(t, "Error received from WebSocket client: myinsert", str) 32 } 33 34 func TestExpandWithCode(t *testing.T) { 35 lang := language.Make("en") 36 ctx := WithLang(context.Background(), lang) 37 str := ExpandWithCode(ctx, MsgWebsocketClientError, "myinsert") 38 assert.Equal(t, "FF10108: Error received from WebSocket client: myinsert", str) 39 } 40 41 func TestGetStatusHint(t *testing.T) { 42 code, ok := GetStatusHint(string(MsgResponseMarshalError)) 43 assert.True(t, ok) 44 assert.Equal(t, 400, code) 45 } 46 47 func TestDuplicateKey(t *testing.T) { 48 ffm("ABCD1234", "test1") 49 assert.Panics(t, func() { 50 ffm("ABCD1234", "test2") 51 }) 52 }