123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- package main
- import (
- "reflect"
- "testing"
- )
- func TestHandle(t *testing.T) {
- var tests = []struct {
- config map[interface{}]interface{}
- skeys []string
- val string
- exp map[interface{}]interface{}
- }{
- {
- config: map[interface{}]interface{}{
- "default": map[interface{}]interface{} {
- "protocol": "tcp",
- "port": 5563,
- "optional": map[interface{}] interface{} {
- "ClientId": "client1",
- },
- },
- },
- skeys:[]string{"default", "protocol"},
- val: "ssl",
- exp: map[interface{}]interface{}{
- "default": map[interface{}]interface{} {
- "protocol": "ssl",
- "port": 5563,
- "optional": map[interface{}] interface{} {
- "ClientId": "client1",
- },
- },
- },
- },
- {
- config: map[interface{}]interface{}{
- "default": map[interface{}]interface{} {
- "protocol": "tcp",
- "port": 5563,
- "optional": map[interface{}] interface{} {
- "ClientId": "client1",
- },
- },
- },
- skeys:[]string{"default", "optional", "CLIENTID"},
- val: "client2",
- exp: map[interface{}]interface{}{
- "default": map[interface{}]interface{} {
- "protocol": "tcp",
- "port": 5563,
- "optional": map[interface{}] interface{} {
- "ClientId": "client2",
- },
- },
- },
- },
- {
- config: map[interface{}]interface{}{
- "default": map[interface{}]interface{} {
- "protocol": "tcp",
- "port": 5563,
- "optional": map[interface{}] interface{} {
- "ClientId": "client1",
- },
- },
- },
- skeys:[]string{"default", "optional", "KEEPALIVE"},
- val: "5000",
- exp: map[interface{}]interface{}{
- "default": map[interface{}]interface{} {
- "protocol": "tcp",
- "port": 5563,
- "optional": map[interface{}] interface{} {
- "ClientId": "client1",
- "KeepAlive": "5000",
- },
- },
- },
- },
- {
- config: map[interface{}]interface{}{
- "default": map[interface{}]interface{} {
- "protocol": "tcp",
- "port": 5563,
- "optional": map[interface{}] interface{} {
- "ClientId": "client1",
- },
- },
- },
- skeys:[]string{"application_conf", "test"},
- val: "ssl",
- exp: map[interface{}]interface{}{
- "default": map[interface{}]interface{} {
- "protocol": "tcp",
- "port": 5563,
- "optional": map[interface{}] interface{} {
- "ClientId": "client1",
- },
- },
- "application_conf": map[interface{}]interface{} {
- "test": "ssl",
- },
- },
- },
- }
- for i, tt := range tests {
- Handle("edgex", tt.config, tt.skeys, tt.val)
- if !reflect.DeepEqual(tt.exp, tt.config) {
- t.Errorf("%d \tresult mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.exp, tt.config)
- }
- }
- }
- func TestProcessEnv(t *testing.T) {
- fileMap["edgex"] = "test/edgex.yaml"
- var tests = []struct {
- vars []string
- file string
- expt map[interface{}]interface{}
- }{
- {
- vars: []string{
- "EDGEX__DEFAULT__TYPE=zmq",
- "EDGEX__DEFAULT__OPTIONAL__CLIENTID=clientid_0000",
- "EDGEX__APPLICATION_CONF__PROTOCOL=ssl",
- },
- file: "edgex",
- expt: map[interface{}]interface{}{
- "default": map[interface {}]interface{} {
- "protocol": "tcp",
- "type": "zmq",
- "optional": map[interface{}] interface{} {
- "ClientId": "clientid_0000",
- },
- },
- "application_conf": map[interface{}]interface{} {
- "protocol":"ssl",
- },
- },
- },
- }
- files := make(map[string]map[interface{}]interface{})
- for i, tt := range tests {
- ProcessEnv(files, tt.vars)
- if !reflect.DeepEqual(tt.expt, files[tt.file]) {
- t.Errorf("%d \tresult mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.expt, files[tt.file])
- }
- }
- }
|