Skip to content

Commit

Permalink
Merge pull request #16 from shiftky/support_decode_vs_name
Browse files Browse the repository at this point in the history
Support decode VirtualServer name
  • Loading branch information
Yuki KIRII authored Dec 17, 2017
2 parents fff4dce + bbced7d commit 6f64e9f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func unmarshal(n *node, out reflect.Value) {
switch n.kind {
case ltmNodeNode, ltmPoolNode, ltmVirtualNode:
unmarshal(n.children[0], out)
if f, ok := lookupField("name", out); ok {
if f.Kind() == reflect.String && f.String() == "" {
f.SetString(n.value)
}
}
case structNode:
decodeStructNode(n, out)
case keyNode:
Expand Down
12 changes: 9 additions & 3 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tmsh
import (
"reflect"
"testing"

"github.com/k0kubun/pp"
)

func TestUnmarshalNode(t *testing.T) {
Expand Down Expand Up @@ -40,7 +42,8 @@ func TestUnmarshalNode(t *testing.T) {
}

if !reflect.DeepEqual(node, expect) {
t.Errorf("got %v\nwant %v", node, expect)
t.Errorf("got :" + pp.Sprint(node))
t.Errorf("want :" + pp.Sprint(expect))
}
}

Expand Down Expand Up @@ -170,7 +173,8 @@ func TestUnmarshalPool(t *testing.T) {
}

if !reflect.DeepEqual(pool, expect) {
t.Errorf("\ngot %v\nwant %v", pool, expect)
t.Errorf("got :" + pp.Sprint(pool))
t.Errorf("want :" + pp.Sprint(expect))
}
}

Expand Down Expand Up @@ -200,6 +204,7 @@ func TestUnmarshalVirtualServer(t *testing.T) {
}

expect := VirtualServer{
Name: "api.example.com_443",
Destination: "203.0.113.1:https",
IpProtocol: "tcp",
Mask: "255.255.255.255",
Expand All @@ -212,6 +217,7 @@ func TestUnmarshalVirtualServer(t *testing.T) {
}

if !reflect.DeepEqual(vs, expect) {
t.Errorf("\ngot %v\nwant %v", vs, expect)
t.Errorf("got :" + pp.Sprint(vs))
t.Errorf("want :" + pp.Sprint(expect))
}
}
3 changes: 3 additions & 0 deletions ltm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func TestGetVirtual(t *testing.T) {
}`

expect := &VirtualServer{
Name: "api.example.com_443",
Destination: "203.0.113.1:https",
IpProtocol: "tcp",
Mask: "255.255.255.255",
Expand Down Expand Up @@ -621,6 +622,7 @@ ltm virtual web.example.com_80 {

expect := []VirtualServer{
VirtualServer{
Name: "api.example.com_443",
Destination: "203.0.113.1:https",
IpProtocol: "tcp",
Mask: "255.255.255.255",
Expand All @@ -633,6 +635,7 @@ ltm virtual web.example.com_80 {
},
},
VirtualServer{
Name: "web.example.com_80",
Destination: "203.0.113.2:http",
IpProtocol: "tcp",
Mask: "255.255.255.255",
Expand Down

0 comments on commit 6f64e9f

Please sign in to comment.