mirror of https://github.com/status-im/consul.git
command/services/register: config mapping tests
This commit is contained in:
parent
3237047e72
commit
0fbaa18ed3
|
@ -1,7 +1,6 @@
|
|||
package register
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hashicorp/consul/agent/config"
|
||||
"github.com/hashicorp/consul/api"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
@ -10,12 +9,8 @@ import (
|
|||
// configToAgentService converts a ServiceDefinition struct to an
|
||||
// AgentServiceRegistration API struct.
|
||||
func configToAgentService(svc *config.ServiceDefinition) (*api.AgentServiceRegistration, error) {
|
||||
// mapstructure can do this for us, but we encapsulate it in this
|
||||
// helper function in case we need to change the logic in the future.
|
||||
var result api.AgentServiceRegistration
|
||||
var m map[string]interface{}
|
||||
err := mapstructure.Decode(svc, &m)
|
||||
if err == nil {
|
||||
println(fmt.Sprintf("%#v", m))
|
||||
err = mapstructure.Decode(m, &result)
|
||||
}
|
||||
return &result, err
|
||||
return &result, mapstructure.Decode(svc, &result)
|
||||
}
|
||||
|
|
|
@ -27,6 +27,46 @@ func TestConfigToAgentService(t *testing.T) {
|
|||
Port: 1234,
|
||||
},
|
||||
},
|
||||
{
|
||||
"Service with a check",
|
||||
&config.ServiceDefinition{
|
||||
Name: strPtr("web"),
|
||||
Check: &config.CheckDefinition{
|
||||
Name: strPtr("ping"),
|
||||
},
|
||||
},
|
||||
&api.AgentServiceRegistration{
|
||||
Name: "web",
|
||||
Check: &api.AgentServiceCheck{
|
||||
Name: "ping",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"Service with checks",
|
||||
&config.ServiceDefinition{
|
||||
Name: strPtr("web"),
|
||||
Checks: []config.CheckDefinition{
|
||||
config.CheckDefinition{
|
||||
Name: strPtr("ping"),
|
||||
},
|
||||
config.CheckDefinition{
|
||||
Name: strPtr("pong"),
|
||||
},
|
||||
},
|
||||
},
|
||||
&api.AgentServiceRegistration{
|
||||
Name: "web",
|
||||
Checks: api.AgentServiceChecks{
|
||||
&api.AgentServiceCheck{
|
||||
Name: "ping",
|
||||
},
|
||||
&api.AgentServiceCheck{
|
||||
Name: "pong",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
|
Loading…
Reference in New Issue