-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzone_test.go
More file actions
67 lines (61 loc) · 1.58 KB
/
Copy pathzone_test.go
File metadata and controls
67 lines (61 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package fortimgr
import (
"context"
"testing"
)
func TestListZones(t *testing.T) {
t.Run("not logged in", func(t *testing.T) {
c, _ := NewClient("https://example.com", WithCredentials("u", "p"))
_, err := c.ListZones(context.Background(), "root")
if err != ErrNotLoggedIn {
t.Errorf("err = %v, want ErrNotLoggedIn", err)
}
})
t.Run("success", func(t *testing.T) {
client := newTestClient(t, map[string]string{
"/pm/config/adom/root/obj/system/zone": `[
{
"name": "trust",
"interface": ["port1", "port2", "port3"],
"intrazone": 0,
"description": "Trusted internal zone"
},
{
"name": "untrust",
"interface": ["wan1"],
"intrazone": "deny",
"description": ""
}
]`,
})
zones, err := client.ListZones(context.Background(), "root")
if err != nil {
t.Fatal(err)
}
if len(zones) != 2 {
t.Fatalf("len = %d, want 2", len(zones))
}
z := zones[0]
if z.Name != "trust" {
t.Errorf("Name = %q", z.Name)
}
if len(z.Interfaces) != 3 || z.Interfaces[0] != "port1" {
t.Errorf("Interfaces = %v", z.Interfaces)
}
if z.Intrazone != "allow" {
t.Errorf("Intrazone = %q, want \"allow\"", z.Intrazone)
}
if z.Description != "Trusted internal zone" {
t.Errorf("Description = %q", z.Description)
}
if zones[1].Name != "untrust" {
t.Errorf("Name = %q", zones[1].Name)
}
if zones[1].Intrazone != "deny" {
t.Errorf("Intrazone = %q, want \"deny\"", zones[1].Intrazone)
}
if len(zones[1].Interfaces) != 1 || zones[1].Interfaces[0] != "wan1" {
t.Errorf("Interfaces = %v", zones[1].Interfaces)
}
})
}