2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
21 "github.com/stretchr/testify/assert"
28 func TestParseConfigurationSuccess(t *testing.T) {
29 config := ParseConfiguration()
30 assert.Equal(t, 3800, config.Http.Port)
31 assert.Equal(t, 3801, config.Rmr.Port)
32 assert.Equal(t, 65536, config.Rmr.MaxMsgSize)
33 assert.Equal(t, "info", config.Logging.LogLevel)
34 assert.Equal(t, 100, config.NotificationResponseBuffer)
35 assert.Equal(t, 5, config.BigRedButtonTimeoutSec)
38 func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
39 configPath := "../resources/configuration.yaml"
40 configPathTmp := "../resources/configuration.yaml_tmp"
41 err := os.Rename(configPath, configPathTmp)
43 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
46 err = os.Rename(configPathTmp, configPath)
48 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
51 assert.Panics(t, func() { ParseConfiguration() })
54 func TestRmrConfigNotFoundFailure(t *testing.T) {
55 configPath := "../resources/configuration.yaml"
56 configPathTmp := "../resources/configuration.yaml_tmp"
57 err := os.Rename(configPath, configPathTmp)
59 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
62 err = os.Rename(configPathTmp, configPath)
64 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
67 yamlMap := map[string]interface{}{
68 "logging": map[string]interface{}{"logLevel": "info"},
69 "http": map[string]interface{}{"port": 3800},
71 buf, err := yaml.Marshal(yamlMap)
73 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
75 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
77 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
79 assert.PanicsWithValue(t, "#configuration.fillRmrConfig - failed to fill RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
82 func TestLoggingConfigNotFoundFailure(t *testing.T) {
83 configPath := "../resources/configuration.yaml"
84 configPathTmp := "../resources/configuration.yaml_tmp"
85 err := os.Rename(configPath, configPathTmp)
87 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
90 err = os.Rename(configPathTmp, configPath)
92 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
95 yamlMap := map[string]interface{}{
96 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
97 "http": map[string]interface{}{"port": 3800},
99 buf, err := yaml.Marshal(yamlMap)
101 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
103 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
105 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
107 assert.PanicsWithValue(t, "#configuration.fillLoggingConfig - failed to fill logging configuration: The entry 'logging' not found\n",
108 func() { ParseConfiguration() })
111 func TestHttpConfigNotFoundFailure(t *testing.T) {
112 configPath := "../resources/configuration.yaml"
113 configPathTmp := "../resources/configuration.yaml_tmp"
114 err := os.Rename(configPath, configPathTmp)
116 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
119 err = os.Rename(configPathTmp, configPath)
121 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
124 yamlMap := map[string]interface{}{
125 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
126 "logging": map[string]interface{}{"logLevel": "info"},
128 buf, err := yaml.Marshal(yamlMap)
130 t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
132 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
134 t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
136 assert.PanicsWithValue(t, "#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n",
137 func() { ParseConfiguration() })