Skip to content

Commit

Permalink
test: add test for target parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
shinmog committed Sep 22, 2022
1 parent 8ea0628 commit 774bc77
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions pnrm/dg/pano_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/PaloAltoNetworks/pango/testdata"
"github.com/PaloAltoNetworks/pango/version"
)

func TestPanoNormalization(t *testing.T) {
Expand Down Expand Up @@ -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(`
<entry name="foo">
<description>war</description>
<devices>
<entry name="first"/>
<entry name="second"/>
<entry name="third">
<vsys>
<entry name="vsys2"/>
<entry name="vsys3"/>
</vsys>
</entry>
<entry name="fourth"/>
</devices>
</entry>`)

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")
}

}

0 comments on commit 774bc77

Please sign in to comment.