Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added tests for configuration.
Signed-off-by: Andrew Neudegg <andrew.neudegg@finbourne.com>
- Loading branch information
1 parent
271f3f1
commit 6029bca
Showing
4 changed files
with
163 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package configuration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfigurationSimple(t *testing.T) { | ||
config := []byte(` | ||
applicationSettings: {} | ||
sourceConfigurations: | ||
- name: http/simple | ||
config: | ||
ListenAddr: :5050 | ||
MaxBodySize: 512 | ||
relayConfigs: | ||
- name: memory | ||
config: {} | ||
distributorConfigurations: | ||
- name: http/direct | ||
config: | ||
Addr: http://localhost:5051 | ||
`) | ||
c := RawConfig{ | ||
ConfigData: config, | ||
} | ||
lC, err := c.Load() | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, lC.SourceConfigs[0].Name, "http/simple") | ||
assert.Equal(t, lC.RelayConfigs[0].Name, "memory") | ||
assert.Equal(t, lC.DistributorConfigs[0].Name, "http/direct") | ||
} | ||
|
||
func TestConfigurationSubConfigs(t *testing.T) { | ||
config := []byte(` | ||
applicationSettings: {} | ||
sourceConfigurations: | ||
- name: mock/config | ||
config: {} | ||
subConfigs: | ||
- name: example/example1 | ||
config: | ||
ListenAddr: :5050 | ||
MaxBodySize: 512 | ||
- name: example/example2 | ||
config: | ||
ListenAddr: :5050 | ||
MaxBodySize: 512 | ||
relayConfigs: | ||
- name: memory | ||
config: {} | ||
distributorConfigurations: | ||
- name: http/direct | ||
config: | ||
Addr: http://localhost:5051 | ||
`) | ||
c := RawConfig{ | ||
ConfigData: config, | ||
} | ||
lC, err := c.Load() | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, lC.SourceConfigs[0].Name, "mock/config") | ||
assert.Equal(t, lC.RelayConfigs[0].Name, "memory") | ||
assert.Equal(t, lC.DistributorConfigs[0].Name, "http/direct") | ||
|
||
assert.Equal(t, lC.SourceConfigs[0].SubConfigs[0].Name, "example/example1") | ||
assert.Equal(t, lC.SourceConfigs[0].SubConfigs[1].Name, "example/example2") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package configuration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var rawExampleConfig = []byte(` | ||
applicationSettings: {} | ||
# sourceConfigurations | ||
sourceConfigurations: | ||
- name: first | ||
sourceConfig: | ||
A: example | ||
B: example | ||
- name: second | ||
sourceConfig: | ||
A: example | ||
B: example | ||
# relayConfigs | ||
relayConfigs: | ||
- name: thing | ||
sourceConfig: | ||
A: example | ||
B: example | ||
# distributorConfigurations | ||
distributorConfigurations: | ||
- name: thing | ||
sourceConfig: | ||
A: example | ||
B: example | ||
`) | ||
|
||
func TestRawSmoke(t *testing.T) { | ||
f := RawConfig{ | ||
ConfigData: rawExampleConfig, | ||
} | ||
|
||
_, err := f.Load() | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestRawBadData(t *testing.T) { | ||
testBytes := append([]byte("testing"), rawExampleConfig...) | ||
f := RawConfig{ | ||
ConfigData: testBytes, | ||
} | ||
|
||
_, err := f.Load() | ||
assert.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters