Skip to content

Commit

Permalink
Adjust wrapper output and logging
Browse files Browse the repository at this point in the history
* remove all output and logging from core gocvent wrapper code
* adjust testing to use logrus for nicer output
* refactor testing on auth-dependent checks to fail early
  • Loading branch information
matthewpoer committed Jun 5, 2019
1 parent d312873 commit 3647e43
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 20 deletions.
22 changes: 7 additions & 15 deletions gocvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gocvent

import (
"errors"
"log"

"github.com/matthewpoer/gocvent/gosoap"
)
Expand All @@ -15,8 +14,7 @@ const xmlns string = "http://schemas.cvent.com/api/2006-11"
func (c *CventAPI) Auth(accountNumber string, user string, pass string) (bool, error) {
soap, err := gosoap.SoapClient(wsdlProduction)
if err != nil {
log.Printf("error not expected on soap invocation: %s", err)
return false, errors.New("WSDL Load Failure")
return false, errors.New("CventAPI.Auth error loading WSDL: " + err.Error())
}
c.soap = soap
params := gosoap.Params{
Expand All @@ -26,15 +24,13 @@ func (c *CventAPI) Auth(accountNumber string, user string, pass string) (bool, e
}
err = c.soap.Call("Login", params)
if err != nil {
log.Printf("error not expected on cvent Login: %s", err)
return false, errors.New("SOAP Call Failure")
return false, errors.New("CventAPI.Auth Soap Login Failure: " + err.Error())
}

var r LoginResponse
c.soap.Unmarshal(&r)
if r.LoginResult.LoginSuccess != "true" {
log.Printf("login was not successful?: %s", r.LoginResult.LoginSuccess)
return false, errors.New("Login Failure")
return false, errors.New("CventAPI.Auth Login Failure: " + r.LoginResult.ErrorMessage)
}

// store the retrieved Server URL and Header, and go ahead and set the soap
Expand All @@ -43,8 +39,7 @@ func (c *CventAPI) Auth(accountNumber string, user string, pass string) (bool, e
c.CventSessionHeader = r.LoginResult.CventSessionHeader
c.soap, err = gosoap.SoapClient(c.ServerURL)
if err != nil {
log.Printf("error not expected on soap re-invocation: %s", err)
return false, errors.New("New WSDL Load Failure")
return false, errors.New("CventAPI.Auth error loading revised WSDL: " + err.Error())
}
c.soap.HeaderName = "CventSessionHeader"
c.soap.HeaderParams = make(map[string]string)
Expand All @@ -62,8 +57,7 @@ func (c *CventAPI) DescribeCvObject(objectTypes []string) ([]DescribeCvObjectRes
params["ObjectTypes"] = ObjectTypes
err := c.soap.Call("DescribeCvObject", params)
if err != nil {
log.Printf("error not expected on cvent DescribeCvObject: %s", err)
return r.DescribeCvObjectResults, errors.New("SOAP Call Failure")
return r.DescribeCvObjectResults, errors.New("CventAPI.DescribeCvObject Soap DescribeCvObject Failure: " + err.Error())
}

c.soap.Unmarshal(&r)
Expand All @@ -77,8 +71,7 @@ func (c *CventAPI) DescribeGlobal() (DescribeGlobalResult, error) {
params := gosoap.Params{}
err := c.soap.Call("DescribeGlobal", params)
if err != nil {
log.Printf("error not expected on cvent DescribeGlobal: %s", err)
return r.DescribeGlobalResult, errors.New("SOAP Call Failure")
return r.DescribeGlobalResult, errors.New("CventAPI.DescribeGlobal Soap DescribeGlobal Failure: " + err.Error())
}

c.soap.Unmarshal(&r)
Expand All @@ -97,8 +90,7 @@ func (c *CventAPI) Search(ObjectType string, Filters []Filter) (SearchResult, er

err := c.soap.Call("Search", params)
if err != nil {
log.Printf("error not expected on cvent DescribeCvObject: %s", err)
return r.SearchResult, errors.New("SOAP Call Failure")
return r.SearchResult, errors.New("CventAPI.Search Soap Search Failure: " + err.Error())
}

c.soap.Unmarshal(&r)
Expand Down
66 changes: 61 additions & 5 deletions gocvent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"os"
"testing"

log "github.com/sirupsen/logrus"

"github.com/stretchr/testify/assert"
)

Expand All @@ -19,19 +21,36 @@ func genericAuth() (CventAPI, bool, error) {

func TestAuth(t *testing.T) {
cvent, success, err := genericAuth()
if err != nil {
log.Printf("TestAuth err from genericAuth(): %s", err)
}
assert.Nil(t, err)

if success != true {
log.Println("TestAuth success is false")
}
assert.True(t, success)

assert.NotEmpty(t, cvent.ServerURL)
assert.NotEmpty(t, cvent.CventSessionHeader)
}

func TestDescribeCvObjectMultiple(t *testing.T) {
cvent, success, err := genericAuth()
if err != nil || !success {
t.Errorf("TestDescribeCvObjectMultiple fails because authorization or invocation failed")
return
}

var objectList = make([]string, 3)
objectList[0] = "Contact"
objectList[1] = "Event"
objectList[2] = "User"
cvent, _, _ := genericAuth()

r, err := cvent.DescribeCvObject(objectList)
if err != nil {
log.Printf("TestDescribeCvObjectMultiple err from cvent.DescribeCvObject: %s", err)
}
assert.Nil(t, err)

// make sure that we found a DescribeCvObjectResult to represent each of our elements.
Expand Down Expand Up @@ -78,10 +97,19 @@ func TestDescribeCvObjectMultiple(t *testing.T) {
}

func TestDescribeCvObjectSingle(t *testing.T) {
cvent, success, err := genericAuth()
if err != nil || !success {
t.Errorf("TestDescribeCvObjectSingle fails because authorization or invocation failed")
return
}

var objectList = make([]string, 1)
objectList[0] = "Contact"
cvent, _, _ := genericAuth()

r, err := cvent.DescribeCvObject(objectList)
if err != nil {
log.Printf("TestDescribeCvObjectMultiple err from cvent.DescribeCvObject: %s", err)
}
assert.Nil(t, err)

// make sure that we found a DescribeCvObjectResult to represent each of our elements.
Expand All @@ -108,8 +136,16 @@ func TestDescribeCvObjectSingle(t *testing.T) {
}

func TestDescribeGlobal(t *testing.T) {
cvent, _, _ := genericAuth()
cvent, success, err := genericAuth()
if err != nil || !success {
t.Errorf("TestDescribeGlobal fails because authorization or invocation failed")
return
}

r, err := cvent.DescribeGlobal()
if err != nil {
log.Printf("TestDescribeGlobal err from cvent.DescribeGlobal: %s", err)
}
assert.Nil(t, err)
assert.NotEmpty(t, r.CurrentAPICalls)
assert.NotEmpty(t, r.CvObjectTypes)
Expand All @@ -119,13 +155,27 @@ func TestDescribeGlobal(t *testing.T) {
}

func TestSearchNoFilter(t *testing.T) {
cvent, _, _ := genericAuth()
cvent, success, err := genericAuth()
if err != nil || !success {
t.Errorf("TestSearchNoFilter fails because authorization or invocation failed")
return
}

r, err := cvent.Search("Contact", []Filter{})
if err != nil {
log.Printf("TestSearchNoFilter err from cvent.Search: %s", err)
}
assert.Nil(t, err)
assert.Greater(t, len(r.Ids), 0)
}

func TestSearchWithFilters(t *testing.T) {
cvent, success, err := genericAuth()
if err != nil || !success {
t.Errorf("TestSearchWithFilters fails because authorization or invocation failed")
return
}

Filters := make([]Filter, 2)
Filters[0] = Filter{
Field: "Company",
Expand All @@ -137,8 +187,11 @@ func TestSearchWithFilters(t *testing.T) {
Operator: "Equals",
Value: "Smith",
}
cvent, _, _ := genericAuth()

r, err := cvent.Search("Contact", Filters)
if err != nil {
log.Printf("TestSearchWithFilters err from cvent.Search: %s", err)
}
assert.Nil(t, err)
assert.Greater(t, len(r.Ids), 0)

Expand All @@ -154,6 +207,9 @@ func TestSearchWithFilters(t *testing.T) {
Filters[0].ValueArray = append(Filters[0].ValueArray, "Williams")
Filters[0].ValueArray = append(Filters[0].ValueArray, "Jones")
r, err = cvent.Search("Contact", Filters)
if err != nil {
log.Printf("TestSearchWithFilters err from cvent.Search: %s", err)
}
assert.Nil(t, err)
assert.Greater(t, len(r.Ids), 0)
assert.Greater(t, len(r.Ids), numberOfSmiths)
Expand Down

0 comments on commit 3647e43

Please sign in to comment.