From 774bc77ce56a19c1c6b1e14f286b35fe4a91ca52 Mon Sep 17 00:00:00 2001 From: Garfield Freeman Date: Thu, 22 Sep 2022 12:20:43 -0700 Subject: [PATCH] test: add test for target parsing --- pnrm/dg/pano_test.go | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/pnrm/dg/pano_test.go b/pnrm/dg/pano_test.go index ec8e7742..c3851f8c 100644 --- a/pnrm/dg/pano_test.go +++ b/pnrm/dg/pano_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/PaloAltoNetworks/pango/testdata" + "github.com/PaloAltoNetworks/pango/version" ) func TestPanoNormalization(t *testing.T) { @@ -33,3 +34,72 @@ func TestPanoNormalization(t *testing.T) { }) } } + +func TestDevices(t *testing.T) { + mc := &testdata.MockClient{} + ns := PanoramaNamespace(mc) + + mc.Version = version.Number{10, 0, 0, ""} + mc.AddResp(` + + war + + + + + + + + + + + +`) + + obj, err := ns.Get("foo") + if err != nil { + t.Fatalf("Error in get: %s", err) + } + if obj.Name != "foo" { + t.Fatalf("Name is not foo, but %q", obj.Name) + } + if obj.Description != "war" { + t.Fatalf("Description is %q, not war", obj.Description) + } + if len(obj.Devices) != 4 { + t.Fatalf("Devices is len %d, not 4", len(obj.Devices)) + } + + val, ok := obj.Devices["first"] + if !ok { + t.Fatalf("first not in devices") + } else if val != nil { + t.Fatalf("first val is not nil") + } + + val, ok = obj.Devices["second"] + if !ok { + t.Fatalf("second not in devices") + } else if val != nil { + t.Fatalf("second val is not nil") + } + + val, ok = obj.Devices["third"] + if !ok { + t.Fatalf("third not in devices") + } else if len(val) != 2 { + t.Fatalf("third vsys list is %#v not [vsys2, vsys3]", val) + } else if val[0] != "vsys2" && val[1] != "vsys2" { + t.Errorf("vsys2 not in val: %#v", val) + } else if val[0] != "vsys3" && val[1] != "vsys3" { + t.Errorf("vsys3 not in val: %#v", val) + } + + val, ok = obj.Devices["fourth"] + if !ok { + t.Fatalf("fourth not in devices") + } else if val != nil { + t.Fatalf("fourth val is not nil") + } + +}