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)
36 assert.Equal(t, 1500, config.KeepAliveResponseTimeoutMs)
37 assert.Equal(t, 500, config.KeepAliveDelayMs)
40 func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
41 configPath := "../resources/configuration.yaml"
42 configPathTmp := "../resources/configuration.yaml_tmp"
43 err := os.Rename(configPath, configPathTmp)
45 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
48 err = os.Rename(configPathTmp, configPath)
50 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
53 assert.Panics(t, func() { ParseConfiguration() })
56 func TestRmrConfigNotFoundFailure(t *testing.T) {
57 configPath := "../resources/configuration.yaml"
58 configPathTmp := "../resources/configuration.yaml_tmp"
59 err := os.Rename(configPath, configPathTmp)
61 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
64 err = os.Rename(configPathTmp, configPath)
66 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
69 yamlMap := map[string]interface{}{
70 "logging": map[string]interface{}{"logLevel": "info"},
71 "http": map[string]interface{}{"port": 3800},
73 buf, err := yaml.Marshal(yamlMap)
75 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
77 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
79 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
81 assert.PanicsWithValue(t, "#configuration.fillRmrConfig - failed to fill RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
84 func TestLoggingConfigNotFoundFailure(t *testing.T) {
85 configPath := "../resources/configuration.yaml"
86 configPathTmp := "../resources/configuration.yaml_tmp"
87 err := os.Rename(configPath, configPathTmp)
89 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
92 err = os.Rename(configPathTmp, configPath)
94 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
97 yamlMap := map[string]interface{}{
98 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
99 "http": map[string]interface{}{"port": 3800},
101 buf, err := yaml.Marshal(yamlMap)
103 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
105 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
107 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
109 assert.PanicsWithValue(t, "#configuration.fillLoggingConfig - failed to fill logging configuration: The entry 'logging' not found\n",
110 func() { ParseConfiguration() })
113 func TestHttpConfigNotFoundFailure(t *testing.T) {
114 configPath := "../resources/configuration.yaml"
115 configPathTmp := "../resources/configuration.yaml_tmp"
116 err := os.Rename(configPath, configPathTmp)
118 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
121 err = os.Rename(configPathTmp, configPath)
123 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
126 yamlMap := map[string]interface{}{
127 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
128 "logging": map[string]interface{}{"logLevel": "info"},
130 buf, err := yaml.Marshal(yamlMap)
132 t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
134 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
136 t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
138 assert.PanicsWithValue(t, "#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n",
139 func() { ParseConfiguration() })