Skip to content

Commit

Permalink
gofmt'ing code
Browse files Browse the repository at this point in the history
  • Loading branch information
shinmog committed Dec 11, 2019
1 parent 59593df commit 82241f9
Show file tree
Hide file tree
Showing 451 changed files with 49,437 additions and 49,822 deletions.
1,822 changes: 910 additions & 912 deletions client.go

Large diffs are not rendered by default.

267 changes: 133 additions & 134 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -1,179 +1,178 @@
package pango

import (
"bytes"
"log"
"os"
"strings"
"testing"
"bytes"
"log"
"os"
"strings"
"testing"

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


func init() {
log.SetFlags(0)
log.SetFlags(0)
}

// rl restores the logger output to the default log location.
func rl() {
log.SetOutput(os.Stderr)
log.SetOutput(os.Stderr)
}

func TestClientStringerHidesPasswords(t *testing.T) {
c := &Client{
Hostname: "foo",
Username: "admin",
Password: "secret",
}

if strings.Index(c.String(), "secret") != -1 {
t.Fail()
}
c := &Client{
Hostname: "foo",
Username: "admin",
Password: "secret",
}

if strings.Index(c.String(), "secret") != -1 {
t.Fail()
}
}

func TestClientStringerHidesApiKey(t *testing.T) {
c := &Client{
Hostname: "foo",
Username: "admin",
ApiKey: "secret",
}

if strings.Index(c.String(), "secret") != -1 {
t.Fail()
}
c := &Client{
Hostname: "foo",
Username: "admin",
ApiKey: "secret",
}

if strings.Index(c.String(), "secret") != -1 {
t.Fail()
}
}

func TestLogActionDisabled(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuiet,
}
c.LogAction("no")
if buf.String() != "" {
t.Fail()
}
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuiet,
}
c.LogAction("no")
if buf.String() != "" {
t.Fail()
}
}

func TestLogActionEnabled(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogAction,
}
c.LogAction("yes")
s := buf.String()
if s != "yes\n" {
t.Fail()
}
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogAction,
}
c.LogAction("yes")
s := buf.String()
if s != "yes\n" {
t.Fail()
}
}

func TestLogQueryDisabled(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuiet,
}
c.LogQuery("no")
if buf.String() != "" {
t.Fail()
}
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuiet,
}
c.LogQuery("no")
if buf.String() != "" {
t.Fail()
}
}

func TestLogQueryEnabled(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuery,
}
c.LogQuery("yes")
s := buf.String()
if s != "yes\n" {
t.Fail()
}
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuery,
}
c.LogQuery("yes")
s := buf.String()
if s != "yes\n" {
t.Fail()
}
}

func TestLogOpDisabled(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuiet,
}
c.LogOp("no")
if buf.String() != "" {
t.Fail()
}
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuiet,
}
c.LogOp("no")
if buf.String() != "" {
t.Fail()
}
}

func TestLogOpEnabled(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogOp,
}
c.LogOp("yes")
s := buf.String()
if s != "yes\n" {
t.Fail()
}
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogOp,
}
c.LogOp("yes")
s := buf.String()
if s != "yes\n" {
t.Fail()
}
}

func TestLogUidDisabled(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuiet,
}
c.LogUid("no")
if buf.String() != "" {
t.Fail()
}
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogQuiet,
}
c.LogUid("no")
if buf.String() != "" {
t.Fail()
}
}

func TestLogUidEnabled(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogUid,
}
c.LogUid("yes")
s := buf.String()
if s != "yes\n" {
t.Fail()
}
var buf bytes.Buffer
log.SetOutput(&buf)
defer rl()

c := &Client{
Logging: LogUid,
}
c.LogUid("yes")
s := buf.String()
if s != "yes\n" {
t.Fail()
}
}

func TestRetrieveApiKey(t *testing.T) {
c := &Client{}
c.rb = [][]byte{
[]byte(testdata.ApiKeyXml),
}
if err := c.Initialize(); err != nil {
t.Errorf("Initialize failed: %s", err)
return
}

err := c.RetrieveApiKey()
if err != nil {
t.Errorf("Failed to retrieve api key: %s", err)
} else if c.ApiKey != "secret" {
t.Fail()
}
c := &Client{}
c.rb = [][]byte{
[]byte(testdata.ApiKeyXml),
}
if err := c.Initialize(); err != nil {
t.Errorf("Initialize failed: %s", err)
return
}

err := c.RetrieveApiKey()
if err != nil {
t.Errorf("Failed to retrieve api key: %s", err)
} else if c.ApiKey != "secret" {
t.Fail()
}
}
44 changes: 22 additions & 22 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ The Initialize function is invoked as part of this discovery, so there is no
need to Initialize() the Client connection prior to invoking this.
*/
func Connect(c Client) (interface{}, error) {
var err error
var err error

logg := c.Logging
c.Logging = LogQuiet
logg := c.Logging
c.Logging = LogQuiet

if err = c.Initialize(); err != nil {
return nil, err
}
if err = c.Initialize(); err != nil {
return nil, err
}

model := c.SystemInfo["model"]
if model == "Panorama" || model[:2] == "M-" {
pano := &Panorama{Client: c}
pano.Logging = logg
if err = pano.Initialize(); err != nil {
return nil, err
}
return pano, nil
} else {
fw := &Firewall{Client: c}
fw.Logging = logg
if err = fw.Initialize(); err != nil {
return nil, err
}
return fw, nil
}
model := c.SystemInfo["model"]
if model == "Panorama" || model[:2] == "M-" {
pano := &Panorama{Client: c}
pano.Logging = logg
if err = pano.Initialize(); err != nil {
return nil, err
}
return pano, nil
} else {
fw := &Firewall{Client: c}
fw.Logging = logg
if err = fw.Initialize(); err != nil {
return nil, err
}
return fw, nil
}
}
Loading

0 comments on commit 82241f9

Please sign in to comment.