Skip to content

Commit

Permalink
Add acceptance tests for contacts and teams
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsouza committed Sep 17, 2020
1 parent 310f41c commit 244750e
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 4 deletions.
148 changes: 148 additions & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,151 @@ func TestProbes(t *testing.T) {
assert.NotNil(t, probes)
assert.NotEmpty(t, probes)
}

func TestContacts(t *testing.T) {
if !runAcceptance {
t.Skip()
}

contact := pingdom.Contact{
Name: "Test User",
Paused: false,
NotificationTargets: pingdom.NotificationTargets{
SMS: []pingdom.SMSNotification{
{
CountryCode: "00",
Number: "5555555555",
Provider: "nexmo",
Severity: "LOW",
},
{
CountryCode: "00",
Number: "5555555555",
Provider: "nexmo",
Severity: "HIGH",
},
},
},
}

createMsg, err := client.Contacts.Create(&contact)
assert.NoError(t, err)
assert.NotNil(t, createMsg)
assert.NotEmpty(t, createMsg)

contact.ID = createMsg.ID

listMsg, err := client.Contacts.List()
assert.NoError(t, err)
assert.NotNil(t, listMsg)
assert.NotEmpty(t, listMsg)

contact.NotificationTargets.SMS[0].Number = "2222222222"
updateMsg, err := client.Contacts.Update(contact.ID, &contact)
assert.NoError(t, err)
assert.NotNil(t, updateMsg)

delMsg, err := client.Contacts.Delete(contact.ID)
assert.NoError(t, err)
assert.NotNil(t, delMsg)
}

func TestTeams(t *testing.T) {
if !runAcceptance {
t.Skip()
}

team := pingdom.Team{
Name: "Test team",
MemberIDs: []int{},
}

createMsg, err := client.Teams.Create(&team)
assert.NoError(t, err)
assert.NotNil(t, createMsg)
assert.NotEmpty(t, createMsg)

team.ID = createMsg.ID

listMsg, err := client.Teams.List()
assert.NoError(t, err)
assert.NotNil(t, listMsg)
assert.NotEmpty(t, listMsg)

team.Name = "Test team renamed"
updateMsg, err := client.Teams.Update(team.ID, &team)
assert.NoError(t, err)
assert.NotNil(t, updateMsg)
assert.NotEmpty(t, updateMsg)

delMsg, err := client.Teams.Delete(team.ID)
assert.NoError(t, err)
assert.NotNil(t, delMsg)
}

func TestTeamAndContactConnections(t *testing.T) {
if !runAcceptance {
t.Skip()
}

contact := pingdom.Contact{
Name: "Test User",
Paused: false,
NotificationTargets: pingdom.NotificationTargets{
SMS: []pingdom.SMSNotification{
{
CountryCode: "00",
Number: "5555555555",
Provider: "nexmo",
Severity: "LOW",
},
{
CountryCode: "00",
Number: "5555555555",
Provider: "nexmo",
Severity: "HIGH",
},
},
},
}

team := pingdom.Team{
Name: "Test team",
MemberIDs: []int{},
}

createTeamMsg, err := client.Teams.Create(&team)
assert.NoError(t, err)
assert.NotNil(t, createTeamMsg)
assert.NotEmpty(t, createTeamMsg)

team.ID = createTeamMsg.ID

createContactMsg, err := client.Contacts.Create(&contact)
assert.NoError(t, err)
assert.NotNil(t, createContactMsg)
assert.NotEmpty(t, createContactMsg)

contact.ID = createContactMsg.ID

team.MemberIDs = append(team.MemberIDs, contact.ID)

// Verify we can add contacts
updateMsg, err := client.Teams.Update(team.ID, &team)
assert.NoError(t, err)
assert.NotNil(t, updateMsg)
assert.NotEmpty(t, updateMsg)
assert.NotEmpty(t, updateMsg.Members)

team.MemberIDs = []int{}
// Verify we can remove contacts
updateMsg, err = client.Teams.Update(team.ID, &team)
assert.NoError(t, err)
assert.NotNil(t, updateMsg)
assert.NotEmpty(t, updateMsg)
assert.Empty(t, updateMsg.Members)

delMsg, err := client.Teams.Delete(team.ID)
assert.NoError(t, err)
assert.NotNil(t, delMsg)
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ go 1.13

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2
github.com/stretchr/testify v1.3.0
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

0 comments on commit 244750e

Please sign in to comment.