github.com/braveheart12/insolar-09-08-19@v0.8.7/api/requester/config_test.go (about) 1 /* 2 * Copyright 2019 Insolar Technologies 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package requester 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/require" 23 ) 24 25 func TestReadFile_BadFile(t *testing.T) { 26 err := readFile("zzz", nil) 27 require.EqualError(t, err, "[ readFile ] Problem with reading config: open zzz: no such file or directory") 28 } 29 30 func TestReadFile_NotJson(t *testing.T) { 31 err := readFile("testdata/bad_json.json", nil) 32 require.EqualError(t, err, "[ readFile ] Problem with unmarshaling config: invalid character ']' after object key") 33 } 34 35 func TestReadRequestConfigFromFile(t *testing.T) { 36 conf, err := ReadRequestConfigFromFile("testdata/requestConfig.json") 37 require.NoError(t, err) 38 require.Equal(t, "CreateMember", conf.Method) 39 40 require.Len(t, conf.Params, 2) 41 require.Equal(t, float64(200), conf.Params[0]) 42 require.Equal(t, "Test", conf.Params[1]) 43 } 44 45 func TestReadUserConfigFromFile(t *testing.T) { 46 conf, err := ReadUserConfigFromFile("testdata/userConfig.json") 47 require.NoError(t, err) 48 require.Contains(t, conf.PrivateKey, "MHcCAQEEIPOsF3ujjM7jnb7V") 49 require.Equal(t, "4FFB8zfQoGznSmzDxwv4njX1aR9ioL8GHSH17QXH2AFa.4K3NiGuqYGqKPnYp6XeGd2kdN4P9veL6rYcWkLKWXZCu", conf.Caller) 50 }