Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Tests #3

Merged
merged 13 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
keys:
- vendor-dep-{{ checksum "Gopkg.lock" }}

- run: dep ensure -vendor-only
- run: dep ensure -vendor-only -v

- save_cache:
key: vendor-dep-{{ checksum "Gopkg.lock" }}
Expand All @@ -26,9 +26,9 @@ jobs:
command: |
go build -v
- run:
name: Run tests
name: Run acceptance tests
command: |
go test
TF_ACC=1 go test -v ./...

- store_artifacts:
path: "/go/bin/terraform-provider-uptimerobot"
Expand Down
47 changes: 33 additions & 14 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@


[[constraint]]
branch = "master"
name = "github.com/hashicorp/terraform"
version = "v0.11.7"

[prune]
go-tests = true
Expand Down
31 changes: 31 additions & 0 deletions uptimerobot/api/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uptimerobotapi

type Account struct {
Email string
MonitorLimit int
MonitorInterval int
UpMonitors int
DownMonitors int
PausedMonitors int
}

func (client UptimeRobotApiClient) GetAccountDetails() (acc Account, err error) {
body, err := client.MakeCall(
"getAccountDetails",
"",
)

if err != nil {
return
}
account := body["account"].(map[string]interface{})

acc.Email = account["email"].(string)
acc.MonitorLimit = int(account["monitor_limit"].(float64))
acc.MonitorInterval = int(account["monitor_interval"].(float64))
acc.UpMonitors = int(account["up_monitors"].(float64))
acc.DownMonitors = int(account["down_monitors"].(float64))
acc.PausedMonitors = int(account["paused_monitors"].(float64))

return
}
135 changes: 135 additions & 0 deletions uptimerobot/api/alert_contact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package uptimerobotapi

import (
"encoding/json"
"errors"
"fmt"
"net/url"
)

var alertContactType = map[string]int{
"sms": 1,
"email": 2,
"twitter-dm": 3,
"boxcar": 4,
"webhook": 5,
"pushbullet": 6,
"zapier": 7,
"pushover": 8,
"hipchat": 10,
"slack": 11,
}
var AlertContactType = mapKeys(alertContactType)

var alertContactStatus = map[string]int{
"not activated": 0,
"paused": 1,
"active": 2,
}

var AlertContactStatus = mapKeys(alertContactStatus)

type AlertContact struct {
ID int `json:"id"`
FriendlyName string `json:"friendly_name"`
Value string `json:"value"`
Type string
Status string
}

func (client UptimeRobotApiClient) GetAlertContact(id int) (ac AlertContact, err error) {
ac.ID = id
data := url.Values{}
data.Add("alert_contacts", fmt.Sprintf("%d", id))

body, err := client.MakeCall(
"getAlertContacts",
data.Encode(),
)
if err != nil {
return
}

alertcontacts, ok := body["alert_contacts"].([]interface{})
if !ok {
j, _ := json.Marshal(body)
err = errors.New("Unknown response from the server: " + string(j))
return
}

alertcontact := alertcontacts[0].(map[string]interface{})

ac.FriendlyName = alertcontact["friendly_name"].(string)
ac.Value = alertcontact["value"].(string)
ac.Type = intToString(alertContactType, int(alertcontact["type"].(float64)))
ac.Status = intToString(alertContactStatus, int(alertcontact["status"].(float64)))

return
}

type AlertContactCreateRequest struct {
FriendlyName string
Type string
Value string
}

func (client UptimeRobotApiClient) CreateAlertContact(req AlertContactCreateRequest) (ac AlertContact, err error) {
data := url.Values{}
data.Add("friendly_name", req.FriendlyName)
data.Add("type", fmt.Sprintf("%d", alertContactType[req.Type]))
data.Add("value", req.Value)

body, err := client.MakeCall(
"newAlertContact",
data.Encode(),
)
if err != nil {
return
}

alertcontact, ok := body["alertcontact"].(map[string]interface{})
if !ok {
j, _ := json.Marshal(body)
err = errors.New("Unknown response from the server: " + string(j))
return
}

return client.GetAlertContact(int(alertcontact["id"].(float64)))
}

func (client UptimeRobotApiClient) DeleteAlertContact(id int) (err error) {
data := url.Values{}
data.Add("id", fmt.Sprintf("%d", id))

_, err = client.MakeCall(
"deleteAlertContact",
data.Encode(),
)
if err != nil {
return
}
return
}

type AlertContactUpdateRequest struct {
ID int
FriendlyName string
Value string
}

func (client UptimeRobotApiClient) UpdateAlertContact(req AlertContactUpdateRequest) (err error) {
data := url.Values{}
data.Add("id", fmt.Sprintf("%d", req.ID))
data.Add("friendly_name", req.FriendlyName)
data.Add("value", req.Value)

_, err = client.MakeCall(
"editAlertContact",
data.Encode(),
)
if err != nil {
return
}

return
}
Loading