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.
22 "github.com/stretchr/testify/assert"
29 func TestRunServer(t *testing.T) {
33 func TestParseConfigurationSuccess(t *testing.T) {
34 config := configuration.ParseConfiguration()
35 assert.Equal(t, 3800, config.Http.Port)
36 assert.Equal(t, 3801, config.Rmr.Port)
37 assert.Equal(t, 4096, config.Rmr.MaxMsgSize)
38 assert.Equal(t, "info", config.Logging.LogLevel)
39 assert.Equal(t, 100, config.NotificationResponseBuffer)
40 assert.Equal(t,5, config.BigRedButtonTimeoutSec)
43 func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
44 configPath := "../resources/configuration.yaml"
45 configPathTmp := "../resources/configuration.yaml_tmp"
46 err := os.Rename(configPath, configPathTmp)
48 t.Errorf("#http_server_test.TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
51 err = os.Rename(configPathTmp, configPath)
53 t.Errorf("#http_server_test.TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
56 assert.Panics(t, func (){configuration.ParseConfiguration()})
59 func TestRmrConfigNotFoundFailure(t *testing.T) {
60 configPath := "../resources/configuration.yaml"
61 configPathTmp := "../resources/configuration.yaml_tmp"
62 err := os.Rename(configPath, configPathTmp)
64 t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
67 err = os.Rename(configPathTmp, configPath)
69 t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
72 yamlMap := map[string]interface{}{
73 "logging":map[string]interface{}{"logLevel":"info"},
74 "http":map[string]interface{}{"port":3800},
76 buf, err := yaml.Marshal(yamlMap)
78 t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
80 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
82 t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
84 assert.PanicsWithValue(t, "#http_server.fillRmrConfig - failed to fill RMR configuration: The entry 'rmr' not found\n", func (){configuration.ParseConfiguration()})
87 func TestLoggingConfigNotFoundFailure(t *testing.T) {
88 configPath := "../resources/configuration.yaml"
89 configPathTmp := "../resources/configuration.yaml_tmp"
90 err := os.Rename(configPath, configPathTmp)
92 t.Errorf("#http_server_test.TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
95 err = os.Rename(configPathTmp, configPath)
97 t.Errorf("#http_server_test.TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
100 yamlMap := map[string]interface{}{
101 "rmr":map[string]interface{}{"port":3801, "maxMsgSize":4096},
102 "http":map[string]interface{}{"port":3800},
104 buf, err := yaml.Marshal(yamlMap)
106 t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
108 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
110 t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
112 assert.PanicsWithValue(t, "#http_server.fillLoggingConfig - failed to fill logging configuration: The entry 'logging' not found\n",
113 func (){configuration.ParseConfiguration()})
116 func TestHttpConfigNotFoundFailure(t *testing.T) {
117 configPath := "../resources/configuration.yaml"
118 configPathTmp := "../resources/configuration.yaml_tmp"
119 err := os.Rename(configPath, configPathTmp)
121 t.Errorf("#http_server_test.TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
124 err = os.Rename(configPathTmp, configPath)
126 t.Errorf("#http_server_test.TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
129 yamlMap := map[string]interface{}{
130 "rmr":map[string]interface{}{"port":3801, "maxMsgSize":4096},
131 "logging":map[string]interface{}{"logLevel":"info"},
133 buf, err := yaml.Marshal(yamlMap)
135 t.Errorf("#http_server_test.TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
137 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
139 t.Errorf("#http_server_test.TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
141 assert.PanicsWithValue(t, "#http_server.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n",
142 func (){configuration.ParseConfiguration()})