blob: 5d6865498aaabc35ca342d8675a6766573010464 [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)
David Bainbridgece74dbc2019-10-15 16:22:30 +000035
36 /*
37 * The test code is run in the context (path) the package under test,
38 * as such the "PWD" is "$BASE/internal/pkg/afrouter". The config being
39 * used for testing is 3 directories up.
40 */
41 confFilePath = "../../../arouter.json"
Daniele Rossi40fe70a2019-10-11 15:43:36 +020042 config.ConfigFile = cmdParse.String("config", confFilePath, "The configuration file for the affinity router")
43
44 return &config
45
46}
47
48// Test Config
49func TestConfigConfig(t *testing.T) {
50
51 var err error
52
53 configConf := MakeConfigTestConfig()
54 assert.NotNil(t, configConf)
55
56 err = configConf.LoadConfig()
57 assert.Nil(t, err)
58
59}
60
61// Test Config with wrong config file
62func TestConfigNoFile(t *testing.T) {
63
64 var err error
65 var confWrongFilePath string
66
67 configConf := MakeConfigTestConfig()
68 assert.NotNil(t, configConf)
69
70 confWrongFilePath = fmt.Sprintf("%s/src/github.com/opencord/voltha-api-server/xxx.json", os.Getenv("GOPATH"))
71 configConf.ConfigFile = &confWrongFilePath
72
73 err = configConf.LoadConfig()
74 assert.NotNil(t, err)
75
76}