blob: c11d01d20c8f2729b9d875c4f01edfd384f3367a [file] [log] [blame]
Daniele Rossi40fe70a2019-10-11 15:43:36 +02001/*
2 * Portions copyright 2019-present Open Networking Foundation
3 * Original copyright 2019-present Ciena Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the"github.com/stretchr/testify/assert" "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 */
17package afrouter
18
19import (
20 "flag"
21 "fmt"
22 "github.com/stretchr/testify/assert"
23 "os"
24 "path"
25 "testing"
26)
27
28func MakeConfigTestConfig() *Configuration {
29
30 var confFilePath string
31
32 config := Configuration{}
33
34 cmdParse := flag.NewFlagSet(path.Base(os.Args[0]), flag.ContinueOnError)
35 confFilePath = fmt.Sprintf("%s/src/github.com/opencord/voltha-api-server/arouter.json", os.Getenv("GOPATH"))
36 config.ConfigFile = cmdParse.String("config", confFilePath, "The configuration file for the affinity router")
37
38 return &config
39
40}
41
42// Test Config
43func TestConfigConfig(t *testing.T) {
44
45 var err error
46
47 configConf := MakeConfigTestConfig()
48 assert.NotNil(t, configConf)
49
50 err = configConf.LoadConfig()
51 assert.Nil(t, err)
52
53}
54
55// Test Config with wrong config file
56func TestConfigNoFile(t *testing.T) {
57
58 var err error
59 var confWrongFilePath string
60
61 configConf := MakeConfigTestConfig()
62 assert.NotNil(t, configConf)
63
64 confWrongFilePath = fmt.Sprintf("%s/src/github.com/opencord/voltha-api-server/xxx.json", os.Getenv("GOPATH"))
65 configConf.ConfigFile = &confWrongFilePath
66
67 err = configConf.LoadConfig()
68 assert.NotNil(t, err)
69
70}