From a88e9b9b13ab703c3ff39595701e1d36b5ed49da Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Tue, 16 Jan 2018 15:05:10 +0200 Subject: update vendor/github.com/DreamItGetIT/statuscake to latest version --- .../DreamItGetIT/statuscake/cmd/statuscake/main.go | 229 +++++++++++++++++++++ .../statuscake/fixtures/auth_error.json | 4 + .../statuscake/fixtures/tests_all_ok.json | 22 ++ .../statuscake/fixtures/tests_delete_error.json | 5 + .../statuscake/fixtures/tests_delete_ok.json | 6 + .../statuscake/fixtures/tests_detail_ok.json | 34 +++ .../statuscake/fixtures/tests_update_error.json | 9 + .../tests_update_error_slice_of_issues.json | 5 + .../statuscake/fixtures/tests_update_ok.json | 6 + .../DreamItGetIT/statuscake/responses.go | 56 +++-- vendor/github.com/DreamItGetIT/statuscake/tests.go | 33 ++- vendor/vendor.json | 6 +- 12 files changed, 392 insertions(+), 23 deletions(-) create mode 100644 vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json diff --git a/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go b/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go new file mode 100644 index 0000000..dc86b47 --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go @@ -0,0 +1,229 @@ +package main + +import ( + "fmt" + logpkg "log" + "os" + "strconv" + + "github.com/DreamItGetIT/statuscake" +) + +var log *logpkg.Logger + +type command func(*statuscake.Client, ...string) error + +var commands map[string]command + +func init() { + log = logpkg.New(os.Stderr, "", 0) + commands = map[string]command{ + "list": cmdList, + "detail": cmdDetail, + "delete": cmdDelete, + "create": cmdCreate, + "update": cmdUpdate, + } +} + +func colouredStatus(s string) string { + switch s { + case "Up": + return fmt.Sprintf("\033[0;32m%s\033[0m", s) + case "Down": + return fmt.Sprintf("\033[0;31m%s\033[0m", s) + default: + return s + } +} + +func getEnv(name string) string { + v := os.Getenv(name) + if v == "" { + log.Fatalf("`%s` env variable is required", name) + } + + return v +} + +func cmdList(c *statuscake.Client, args ...string) error { + tt := c.Tests() + tests, err := tt.All() + if err != nil { + return err + } + + for _, t := range tests { + var paused string + if t.Paused { + paused = "yes" + } else { + paused = "no" + } + + fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) + fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) + fmt.Printf(" TestType: %s\n", t.TestType) + fmt.Printf(" Paused: %s\n", paused) + fmt.Printf(" ContactID: %d\n", t.ContactID) + fmt.Printf(" Uptime: %f\n", t.Uptime) + } + + return nil +} + +func cmdDetail(c *statuscake.Client, args ...string) error { + if len(args) != 1 { + return fmt.Errorf("command `detail` requires a single argument `TestID`") + } + + id, err := strconv.Atoi(args[0]) + if err != nil { + return err + } + + tt := c.Tests() + t, err := tt.Detail(id) + if err != nil { + return err + } + + var paused string + if t.Paused { + paused = "yes" + } else { + paused = "no" + } + + fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) + fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) + fmt.Printf(" WebsiteURL: %s\n", t.WebsiteURL) + fmt.Printf(" PingURL: %s\n", t.PingURL) + fmt.Printf(" TestType: %s\n", t.TestType) + fmt.Printf(" Paused: %s\n", paused) + fmt.Printf(" ContactID: %d\n", t.ContactID) + fmt.Printf(" Uptime: %f\n", t.Uptime) + + return nil +} + +func cmdDelete(c *statuscake.Client, args ...string) error { + if len(args) != 1 { + return fmt.Errorf("command `delete` requires a single argument `TestID`") + } + + id, err := strconv.Atoi(args[0]) + if err != nil { + return err + } + + return c.Tests().Delete(id) +} + +func askString(name string) string { + var v string + + fmt.Printf("%s: ", name) + _, err := fmt.Scanln(&v) + if err != nil { + log.Fatal(err) + } + + return v +} + +func askInt(name string) int { + v := askString(name) + i, err := strconv.Atoi(v) + if err != nil { + log.Fatalf("Invalid number `%s`", v) + } + + return i +} + +func cmdCreate(c *statuscake.Client, args ...string) error { + t := &statuscake.Test{ + WebsiteName: askString("WebsiteName"), + WebsiteURL: askString("WebsiteURL"), + TestType: askString("TestType"), + CheckRate: askInt("CheckRate"), + } + + t2, err := c.Tests().Update(t) + if err != nil { + return err + } + + fmt.Printf("CREATED: \n%+v\n", t2) + + return nil +} + +func cmdUpdate(c *statuscake.Client, args ...string) error { + if len(args) != 1 { + return fmt.Errorf("command `update` requires a single argument `TestID`") + } + + id, err := strconv.Atoi(args[0]) + if err != nil { + return err + } + + tt := c.Tests() + t, err := tt.Detail(id) + if err != nil { + return err + } + + t.TestID = id + t.WebsiteName = askString(fmt.Sprintf("WebsiteName [%s]", t.WebsiteName)) + t.WebsiteURL = askString(fmt.Sprintf("WebsiteURL [%s]", t.WebsiteURL)) + t.TestType = askString(fmt.Sprintf("TestType [%s]", t.TestType)) + t.CheckRate = askInt(fmt.Sprintf("CheckRate [%d]", t.CheckRate)) + + t2, err := c.Tests().Update(t) + if err != nil { + return err + } + + fmt.Printf("UPDATED: \n%+v\n", t2) + + return nil +} + +func usage() { + fmt.Printf("Usage:\n") + fmt.Printf(" %s COMMAND\n", os.Args[0]) + fmt.Printf("Available commands:\n") + for k := range commands { + fmt.Printf(" %+v\n", k) + } +} + +func main() { + username := getEnv("STATUSCAKE_USERNAME") + apikey := getEnv("STATUSCAKE_APIKEY") + + if len(os.Args) < 2 { + usage() + os.Exit(1) + } + + var err error + + c, err := statuscake.New(statuscake.Auth{Username: username, Apikey: apikey}) + if err != nil { + log.Fatal(err) + } + + if cmd, ok := commands[os.Args[1]]; ok { + err = cmd(c, os.Args[2:]...) + } else { + err = fmt.Errorf("Unknown command `%s`", os.Args[1]) + } + + if err != nil { + log.Fatalf("Error running command `%s`: %s", os.Args[1], err.Error()) + } +} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json new file mode 100644 index 0000000..4f14be5 --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json @@ -0,0 +1,4 @@ +{ + "ErrNo": 0, + "Error": "Can not access account. Was both Username and API Key provided?" +} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json new file mode 100644 index 0000000..81a913d --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json @@ -0,0 +1,22 @@ +[ + { + "TestID": 100, + "Paused": false, + "TestType": "HTTP", + "WebsiteName": "www 1", + "ContactGroup": null, + "ContactID": "1", + "Status": "Up", + "Uptime": 100 + }, + { + "TestID": 101, + "Paused": true, + "TestType": "HTTP", + "WebsiteName": "www 2", + "ContactGroup": null, + "ContactID": "2", + "Status": "Down", + "Uptime": 0 + } +] diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json new file mode 100644 index 0000000..6fad58e --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json @@ -0,0 +1,5 @@ +{ + "Success": false, + "Error": "this is an error" +} + diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json new file mode 100644 index 0000000..0dd279b --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json @@ -0,0 +1,6 @@ +{ + "TestID": 6735, + "Affected": 1, + "Success": true, + "Message": "This Check Has Been Deleted. It can not be recovered." +} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json new file mode 100644 index 0000000..9754aa2 --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json @@ -0,0 +1,34 @@ +{ + "TestID": 6735, + "TestType": "HTTP", + "Paused": false, + "WebsiteName": "NL", + "CustomHeader": "{\"some\":{\"json\": [\"value\"]}}", + "UserAgent": "product/version (comment)", + "ContactGroup": "StatusCake Alerts", + "ContactID": "536", + "Status": "Up", + "Uptime": 0, + "CheckRate": 60, + "Timeout": 40, + "LogoImage": "", + "WebsiteHost": "Various", + "NodeLocations": [ + "UK", + "JP", + "SG1", + "SLC" + ], + "FindString": "", + "DoNotFind": false, + "LastTested": "2013-01-20 14:38:18", + "NextLocation": "USNY", + "Processing": false, + "ProcessingState": "Pretest", + "ProcessingOn": "dalas.localdomain", + "DownTimes": "0", + "UseJar": 0, + "PostRaw": "", + "FinalEndpoint": "", + "FollowRedirect": false +} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json new file mode 100644 index 0000000..a76c5eb --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json @@ -0,0 +1,9 @@ +{ + "Issues": { + "WebsiteName": "issue a", + "WebsiteURL": "issue b", + "CheckRate": "issue c" + }, + "Success": false, + "Message": "Required Data is Missing." +} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json new file mode 100644 index 0000000..02e98eb --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json @@ -0,0 +1,5 @@ +{ + "Issues": ["hello", "world"], + "Success": false, + "Message": "Required Data is Missing." +} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json new file mode 100644 index 0000000..7c2dee2 --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json @@ -0,0 +1,6 @@ +{ + "Issues": {}, + "Success": true, + "Message": "", + "InsertID": 1234 +} diff --git a/vendor/github.com/DreamItGetIT/statuscake/responses.go b/vendor/github.com/DreamItGetIT/statuscake/responses.go index b9216b7..9cdcb11 100644 --- a/vendor/github.com/DreamItGetIT/statuscake/responses.go +++ b/vendor/github.com/DreamItGetIT/statuscake/responses.go @@ -1,5 +1,9 @@ package statuscake +import ( + "strings" +) + type autheticationErrorResponse struct { ErrNo int Error string @@ -24,9 +28,11 @@ type detailResponse struct { Paused bool `json:"Paused"` WebsiteName string `json:"WebsiteName"` URI string `json:"URI"` - ContactID int `json:"ContactID"` + ContactID string `json:"ContactID"` Status string `json:"Status"` Uptime float64 `json:"Uptime"` + CustomHeader string `json:"CustomHeader"` + UserAgent string `json:"UserAgent"` CheckRate int `json:"CheckRate"` Timeout int `json:"Timeout"` LogoImage string `json:"LogoImage"` @@ -44,27 +50,39 @@ type detailResponse struct { DownTimes int `json:"DownTimes,string"` Sensitive bool `json:"Sensitive"` TriggerRate int `json:"TriggerRate,string"` + UseJar int `json:"UseJar"` + PostRaw string `json:"PostRaw"` + FinalEndpoint string `json:"FinalEndpoint"` + FollowRedirect bool `json:"FollowRedirect"` + StatusCodes []string `json:"StatusCodes"` } func (d *detailResponse) test() *Test { return &Test{ - TestID: d.TestID, - TestType: d.TestType, - Paused: d.Paused, - WebsiteName: d.WebsiteName, - WebsiteURL: d.URI, - ContactID: d.ContactID, - Status: d.Status, - Uptime: d.Uptime, - CheckRate: d.CheckRate, - Timeout: d.Timeout, - LogoImage: d.LogoImage, - Confirmation: d.Confirmation, - WebsiteHost: d.WebsiteHost, - NodeLocations: d.NodeLocations, - FindString: d.FindString, - DoNotFind: d.DoNotFind, - Port: d.Port, - TriggerRate: d.TriggerRate, + TestID: d.TestID, + TestType: d.TestType, + Paused: d.Paused, + WebsiteName: d.WebsiteName, + WebsiteURL: d.URI, + CustomHeader: d.CustomHeader, + UserAgent: d.UserAgent, + ContactID: d.ContactID, + Status: d.Status, + Uptime: d.Uptime, + CheckRate: d.CheckRate, + Timeout: d.Timeout, + LogoImage: d.LogoImage, + Confirmation: d.Confirmation, + WebsiteHost: d.WebsiteHost, + NodeLocations: d.NodeLocations, + FindString: d.FindString, + DoNotFind: d.DoNotFind, + Port: d.Port, + TriggerRate: d.TriggerRate, + UseJar: d.UseJar, + PostRaw: d.PostRaw, + FinalEndpoint: d.FinalEndpoint, + FollowRedirect: d.FollowRedirect, + StatusCodes: strings.Join(d.StatusCodes[:], ","), } } diff --git a/vendor/github.com/DreamItGetIT/statuscake/tests.go b/vendor/github.com/DreamItGetIT/statuscake/tests.go index 4053e53..1b37fa1 100644 --- a/vendor/github.com/DreamItGetIT/statuscake/tests.go +++ b/vendor/github.com/DreamItGetIT/statuscake/tests.go @@ -21,6 +21,12 @@ type Test struct { // Website name. Tags are stripped out WebsiteName string `json:"WebsiteName" querystring:"WebsiteName"` + // CustomHeader. A special header that will be sent along with the HTTP tests. + CustomHeader string `json:"CustomHeader" querystring:"CustomHeader"` + + // Use to populate the test with a custom user agent + UserAgent string `json:"UserAgent" queryString:"UserAgent"` + // Test location, either an IP (for TCP and Ping) or a fully qualified URL for other TestTypes WebsiteURL string `json:"WebsiteURL" querystring:"WebsiteURL"` @@ -28,7 +34,7 @@ type Test struct { Port int `json:"Port" querystring:"Port"` // Contact group ID - will return int of contact group used else 0 - ContactID int `json:"ContactID" querystring:"ContactGroup"` + ContactID string `json:"ContactID" querystring:"ContactGroup"` // Current status at last test Status string `json:"Status"` @@ -91,6 +97,18 @@ type Test struct { // Comma Seperated List of StatusCodes to Trigger Error on (on Update will replace, so send full list each time) StatusCodes string `json:"StatusCodes" querystring:"StatusCodes"` + + // Set to 1 to enable the Cookie Jar. Required for some redirects. + UseJar int `json:"UseJar" querystring:"UseJar"` + + // Raw POST data seperated by an ampersand + PostRaw string `json:"PostRaw" querystring:"PostRaw"` + + // Use to specify the expected Final URL in the testing process + FinalEndpoint string `json:"FinalEndpoint" querystring:"FinalEndpoint"` + + // Use to specify whether redirects should be followed + FollowRedirect bool `json:"FollowRedirect" querystring:"FollowRedirect"` } // Validate checks if the Test is valid. If it's invalid, it returns a ValidationError with all invalid fields. It returns nil otherwise. @@ -137,6 +155,19 @@ func (t *Test) Validate() error { e["TriggerRate"] = "must be between 0 and 59" } + if t.PostRaw != "" && t.TestType != "HTTP" { + e["PostRaw"] = "must be HTTP to submit a POST request" + } + + if t.FinalEndpoint != "" && t.TestType != "HTTP" { + e["FinalEndpoint"] = "must be a Valid URL" + } + + var jsonVerifiable map[string]interface{} + if json.Unmarshal([]byte(t.CustomHeader), &jsonVerifiable) != nil { + e["CustomHeader"] = "must be provided as json string" + } + if len(e) > 0 { return e } diff --git a/vendor/vendor.json b/vendor/vendor.json index 8b44fbd..921131f 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -3,10 +3,10 @@ "ignore": "appengine test github.com/hashicorp/nomad/ github.com/hashicorp/terraform/backend", "package": [ { - "checksumSHA1": "MV5JueYPwNkLZ+KNqmDcNDhsKi4=", + "checksumSHA1": "xjfJ6T+mQFmC9oMR+UKdGtbs/p4=", "path": "github.com/DreamItGetIT/statuscake", - "revision": "acc13ec021cd1e8a6ebb1d9035f513217f5c4562", - "revisionTime": "2017-04-10T11:34:45Z" + "revision": "2081e16dbe691bccf20b1901897d8f8245beefcd", + "revisionTime": "2018-01-09T18:02:45Z" }, { "checksumSHA1": "FIL83loX9V9APvGQIjJpbxq53F0=", -- cgit v1.2.3 From 754f142077413d1cfd1e3c8e2fc3f3c0c341ca69 Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Tue, 16 Jan 2018 15:07:28 +0200 Subject: update statuscake provider for support all the features from the statuscake module --- statuscake/resource_statuscaketest.go | 258 ++++++++++++++++++++++++++--- statuscake/resource_statuscaketest_test.go | 103 +++++++++++- 2 files changed, 335 insertions(+), 26 deletions(-) diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 101ee83..27cf9bf 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -34,7 +34,7 @@ func resourceStatusCakeTest() *schema.Resource { }, "contact_id": { - Type: schema.TypeInt, + Type: schema.TypeString, Optional: true, }, @@ -76,6 +76,120 @@ func resourceStatusCakeTest() *schema.Resource { Optional: true, Default: 5, }, + "custom_header": { + Type: schema.TypeString, + Optional: true, + }, + + "user_agent": { + Type: schema.TypeString, + Optional: true, + }, + + "status": { + Type: schema.TypeString, + Optional: true, + }, + + "uptime": { + Type: schema.TypeFloat, + Optional: true, + }, + + "node_locations": { + Type: schema.TypeList, + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + }, + + "ping_url": { + Type: schema.TypeString, + Optional: true, + }, + + "basic_user": { + Type: schema.TypeString, + Optional: true, + }, + + "basic_pass": { + Type: schema.TypeString, + Optional: true, + }, + + "public": { + Type: schema.TypeInt, + Optional: true, + }, + + "logo_image": { + Type: schema.TypeString, + Optional: true, + }, + + "branding": { + Type: schema.TypeInt, + Optional: true, + }, + + "website_host": { + Type: schema.TypeString, + Optional: true, + }, + + "virus": { + Type: schema.TypeInt, + Optional: true, + }, + + "find_string": { + Type: schema.TypeString, + Optional: true, + }, + + "do_not_find": { + Type: schema.TypeBool, + Optional: true, + }, + + "real_browser": { + Type: schema.TypeInt, + Optional: true, + }, + + "test_tags": { + Type: schema.TypeString, + Optional: true, + }, + + "status_codes": { + Type: schema.TypeString, + Optional: true, + Default: "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, " + + "408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, " + + "504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, " + + "598, 599", + }, + + "use_jar": { + Type: schema.TypeInt, + Optional: true, + }, + + "post_raw": { + Type: schema.TypeString, + Optional: true, + }, + + "final_endpoint": { + Type: schema.TypeString, + Optional: true, + }, + + "follow_redirect": { + Type: schema.TypeBool, + Optional: true, + }, }, } } @@ -84,16 +198,38 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { client := meta.(*statuscake.Client) newTest := &statuscake.Test{ - WebsiteName: d.Get("website_name").(string), - WebsiteURL: d.Get("website_url").(string), - CheckRate: d.Get("check_rate").(int), - TestType: d.Get("test_type").(string), - Paused: d.Get("paused").(bool), - Timeout: d.Get("timeout").(int), - ContactID: d.Get("contact_id").(int), - Confirmation: d.Get("confirmations").(int), - Port: d.Get("port").(int), - TriggerRate: d.Get("trigger_rate").(int), + WebsiteName: d.Get("website_name").(string), + WebsiteURL: d.Get("website_url").(string), + CheckRate: d.Get("check_rate").(int), + TestType: d.Get("test_type").(string), + Paused: d.Get("paused").(bool), + Timeout: d.Get("timeout").(int), + ContactID: d.Get("contact_id").(string), + Confirmation: d.Get("confirmations").(int), + Port: d.Get("port").(int), + TriggerRate: d.Get("trigger_rate").(int), + CustomHeader: d.Get("custom_header").(string), + UserAgent: d.Get("user_agent").(string), + Status: d.Get("status").(string), + Uptime: d.Get("uptime").(float64), + NodeLocations: d.Get("node_locations").([]string), + PingURL: d.Get("ping_url").(string), + BasicUser: d.Get("basic_user").(string), + BasicPass: d.Get("basic_pass").(string), + Public: d.Get("public").(int), + LogoImage: d.Get("logo_image").(string), + Branding: d.Get("branding").(int), + WebsiteHost: d.Get("website_host").(string), + Virus: d.Get("virus").(int), + FindString: d.Get("find_string").(string), + DoNotFind: d.Get("do_not_find").(bool), + RealBrowser: d.Get("real_browser").(int), + TestTags: d.Get("test_tags").(string), + StatusCodes: d.Get("status_codes").(string), + UseJar: d.Get("use_jar").(int), + PostRaw: d.Get("post_raw").(string), + FinalEndpoint: d.Get("final_endpoint").(string), + FollowRedirect: d.Get("follow_redirect").(bool), } log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) @@ -159,6 +295,28 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { d.Set("confirmations", testResp.Confirmation) d.Set("port", testResp.Port) d.Set("trigger_rate", testResp.TriggerRate) + d.Set("custom_header", testResp.CustomHeader) + d.Set("user_agent", testResp.UserAgent) + d.Set("status", testResp.Status) + d.Set("uptime", testResp.Uptime) + d.Set("node_locations", testResp.NodeLocations) + d.Set("ping_url", testResp.PingURL) + d.Set("basic_user", testResp.BasicUser) + d.Set("basic_pass", testResp.BasicPass) + d.Set("public", testResp.Public) + d.Set("logo_image", testResp.LogoImage) + d.Set("branding", testResp.Branding) + d.Set("website_host", testResp.WebsiteHost) + d.Set("virus", testResp.Virus) + d.Set("find_string", testResp.FindString) + d.Set("do_not_find", testResp.DoNotFind) + d.Set("real_browser", testResp.RealBrowser) + d.Set("test_tags", testResp.TestTags) + d.Set("status_codes", testResp.StatusCodes) + d.Set("use_jar", testResp.UseJar) + d.Set("post_raw", testResp.PostRaw) + d.Set("final_endpoint", testResp.FinalEndpoint) + d.Set("follow_redirect", testResp.FollowRedirect) return nil } @@ -181,7 +339,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { test.CheckRate = v.(int) } if v, ok := d.GetOk("contact_id"); ok { - test.ContactID = v.(int) + test.ContactID = v.(string) } if v, ok := d.GetOk("test_type"); ok { test.TestType = v.(string) @@ -192,9 +350,6 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { if v, ok := d.GetOk("timeout"); ok { test.Timeout = v.(int) } - if v, ok := d.GetOk("contact_id"); ok { - test.ContactID = v.(int) - } if v, ok := d.GetOk("confirmations"); ok { test.Confirmation = v.(int) } @@ -204,13 +359,72 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { if v, ok := d.GetOk("trigger_rate"); ok { test.TriggerRate = v.(int) } - - defaultStatusCodes := "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, " + - "408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, " + - "504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, " + - "598, 599" - - test.StatusCodes = defaultStatusCodes + if v, ok := d.GetOk("custom_header"); ok { + test.CustomHeader = v.(string) + } + if v, ok := d.GetOk("user_agent"); ok { + test.UserAgent = v.(string) + } + if v, ok := d.GetOk("status"); ok { + test.Status = v.(string) + } + if v, ok := d.GetOk("uptime"); ok { + test.Uptime = v.(float64) + } + if v, ok := d.GetOk("node_locations"); ok { + test.NodeLocations = v.([]string) + } + if v, ok := d.GetOk("ping_url"); ok { + test.PingURL = v.(string) + } + if v, ok := d.GetOk("basic_user"); ok { + test.BasicUser = v.(string) + } + if v, ok := d.GetOk("basic_pass"); ok { + test.BasicPass = v.(string) + } + if v, ok := d.GetOk("public"); ok { + test.Public = v.(int) + } + if v, ok := d.GetOk("logo_image"); ok { + test.LogoImage = v.(string) + } + if v, ok := d.GetOk("branding"); ok { + test.Branding = v.(int) + } + if v, ok := d.GetOk("website_host"); ok { + test.WebsiteHost = v.(string) + } + if v, ok := d.GetOk("virus"); ok { + test.Virus = v.(int) + } + if v, ok := d.GetOk("find_string"); ok { + test.FindString = v.(string) + } + if v, ok := d.GetOk("do_not_find"); ok { + test.DoNotFind = v.(bool) + } + if v, ok := d.GetOk("real_browser"); ok { + test.RealBrowser = v.(int) + } + if v, ok := d.GetOk("test_tags"); ok { + test.TestTags = v.(string) + } + if v, ok := d.GetOk("status_codes"); ok { + test.StatusCodes = v.(string) + } + if v, ok := d.GetOk("use_jar"); ok { + test.UseJar = v.(int) + } + if v, ok := d.GetOk("post_raw"); ok { + test.PostRaw = v.(string) + } + if v, ok := d.GetOk("final_endpoint"); ok { + test.FinalEndpoint = v.(string) + } + if v, ok := d.GetOk("follow_redirect"); ok { + test.FollowRedirect = v.(bool) + } return test } diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index f07fcc5..b39d23c 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -74,6 +74,31 @@ func TestAccStatusCake_withUpdate(t *testing.T) { resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"), resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"), resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"), + resource.TestCheckResourceAttr("statuscake_test.google", "custom_header", "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"), + resource.TestCheckResourceAttr("statuscake_test.google", "user_agent", "string9988"), + resource.TestCheckResourceAttr("statuscake_test.google", "status", "string22117"), + resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "3498.27"), + resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.#", "3"), + resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.0", "string16045"), + resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.1", "string19741"), + resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.2", "string12122"), + resource.TestCheckResourceAttr("statuscake_test.google", "ping_url", "string8410"), + resource.TestCheckResourceAttr("statuscake_test.google", "basic_user", "string27052"), + resource.TestCheckResourceAttr("statuscake_test.google", "basic_pass", "string5659"), + resource.TestCheckResourceAttr("statuscake_test.google", "public", "0"), + resource.TestCheckResourceAttr("statuscake_test.google", "logo_image", "string21087"), + resource.TestCheckResourceAttr("statuscake_test.google", "branding", "25875"), + resource.TestCheckResourceAttr("statuscake_test.google", "website_host", "string32368"), + resource.TestCheckResourceAttr("statuscake_test.google", "virus", "1"), + resource.TestCheckResourceAttr("statuscake_test.google", "find_string", "string15212"), + resource.TestCheckResourceAttr("statuscake_test.google", "do_not_find", "false"), + resource.TestCheckResourceAttr("statuscake_test.google", "real_browser", "1"), + resource.TestCheckResourceAttr("statuscake_test.google", "test_tags", "string8191"), + resource.TestCheckResourceAttr("statuscake_test.google", "status_codes", "string23065"), + resource.TestCheckResourceAttr("statuscake_test.google", "use_jar", "1"), + resource.TestCheckResourceAttr("statuscake_test.google", "post_raw", "string32096"), + resource.TestCheckResourceAttr("statuscake_test.google", "final_endpoint", "string10781"), + resource.TestCheckResourceAttr("statuscake_test.google", "follow_redirect", "true"), ), }, }, @@ -137,13 +162,61 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC case "timeout": err = check(key, value, strconv.Itoa(test.Timeout)) case "contact_id": - err = check(key, value, strconv.Itoa(test.ContactID)) + err = check(key, value, test.ContactID) case "confirmations": err = check(key, value, strconv.Itoa(test.Confirmation)) case "trigger_rate": err = check(key, value, strconv.Itoa(test.TriggerRate)) + case "custom_header": + err = check(key, value, test.CustomHeader) + case "user_agent": + err = check(key, value, test.UserAgent) + case "status": + err = check(key, value, test.Status) + case "uptime": + err = check(key, value, strconv.FormatFloat(test.Uptime, 'f', -1, 64)) + case "node_locations": + for _, tv := range test.NodeLocations { + err = check(key, value, tv) + if err != nil { + return err + } + } + case "ping_url": + err = check(key, value, test.PingURL) + case "basic_user": + err = check(key, value, test.BasicUser) + case "basic_pass": + err = check(key, value, test.BasicPass) + case "public": + err = check(key, value, strconv.Itoa(test.Public)) + case "logo_image": + err = check(key, value, test.LogoImage) + case "branding": + err = check(key, value, strconv.Itoa(test.Branding)) + case "website_host": + err = check(key, value, test.WebsiteHost) + case "virus": + err = check(key, value, strconv.Itoa(test.Virus)) + case "find_string": + err = check(key, value, test.FindString) + case "do_not_find": + err = check(key, value, strconv.FormatBool(test.DoNotFind)) + case "real_browser": + err = check(key, value, strconv.Itoa(test.RealBrowser)) + case "test_tags": + err = check(key, value, test.TestTags) + case "status_codes": + err = check(key, value, test.StatusCodes) + case "use_jar": + err = check(key, value, strconv.Itoa(test.UseJar)) + case "post_raw": + err = check(key, value, test.PostRaw) + case "final_endpoint": + err = check(key, value, test.FinalEndpoint) + case "follow_redirect": + err = check(key, value, strconv.FormatBool(test.FollowRedirect)) } - if err != nil { return err } @@ -171,7 +244,7 @@ resource "statuscake_test" "google" { test_type = "HTTP" check_rate = 300 timeout = 10 - contact_id = 43402 + contact_id = "43402" confirmations = 1 trigger_rate = 10 } @@ -185,6 +258,28 @@ resource "statuscake_test" "google" { check_rate = 500 paused = true trigger_rate = 20 + custom_header = "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }" + user_agent = "string9988" + status = "string22117" + uptime = 3498.27 + node_locations = [ "string16045", "string19741", "string12122" ] + ping_url = "string8410" + basic_user = "string27052" + basic_pass = "string5659" + public = 0 + logo_image = "string21087" + branding = 25875 + website_host = "string32368" + virus = 1 + find_string = "string15212" + do_not_find = false + real_browser = 1 + test_tags = "string8191" + status_codes = "string23065" + use_jar = 1 + post_raw = "string32096" + final_endpoint = "string10781" + follow_redirect = true } ` @@ -195,7 +290,7 @@ resource "statuscake_test" "google" { test_type = "TCP" check_rate = 300 timeout = 10 - contact_id = 43402 + contact_id = "43402" confirmations = 1 port = 80 } -- cgit v1.2.3 From a609749989d4ea67354ac5a464ce42a7b807b869 Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Tue, 16 Jan 2018 16:11:43 +0200 Subject: `status` and `uptime` params is calculated --- statuscake/resource_statuscaketest.go | 12 ++++-------- statuscake/resource_statuscaketest_test.go | 6 ------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 27cf9bf..50e16f9 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -88,12 +88,12 @@ func resourceStatusCakeTest() *schema.Resource { "status": { Type: schema.TypeString, - Optional: true, + Computed: true, }, "uptime": { Type: schema.TypeFloat, - Optional: true, + Computed: true, }, "node_locations": { @@ -240,6 +240,8 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { } d.Set("test_id", fmt.Sprintf("%d", response.TestID)) + d.Set("status", response.Status) + d.Set("uptime", fmt.Sprintf("%.3f", response.Uptime)) d.SetId(fmt.Sprintf("%d", response.TestID)) return ReadTest(d, meta) @@ -365,12 +367,6 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { if v, ok := d.GetOk("user_agent"); ok { test.UserAgent = v.(string) } - if v, ok := d.GetOk("status"); ok { - test.Status = v.(string) - } - if v, ok := d.GetOk("uptime"); ok { - test.Uptime = v.(float64) - } if v, ok := d.GetOk("node_locations"); ok { test.NodeLocations = v.([]string) } diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index b39d23c..99acd04 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -171,10 +171,6 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC err = check(key, value, test.CustomHeader) case "user_agent": err = check(key, value, test.UserAgent) - case "status": - err = check(key, value, test.Status) - case "uptime": - err = check(key, value, strconv.FormatFloat(test.Uptime, 'f', -1, 64)) case "node_locations": for _, tv := range test.NodeLocations { err = check(key, value, tv) @@ -260,8 +256,6 @@ resource "statuscake_test" "google" { trigger_rate = 20 custom_header = "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }" user_agent = "string9988" - status = "string22117" - uptime = 3498.27 node_locations = [ "string16045", "string19741", "string12122" ] ping_url = "string8410" basic_user = "string27052" -- cgit v1.2.3 From 41dde1b862a43456a48d47f0942acc441740be7f Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Tue, 16 Jan 2018 16:11:47 +0200 Subject: update documentation --- website/docs/r/test.html.markdown | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/website/docs/r/test.html.markdown b/website/docs/r/test.html.markdown index 0a1df9f..a385b00 100644 --- a/website/docs/r/test.html.markdown +++ b/website/docs/r/test.html.markdown @@ -36,7 +36,26 @@ The following arguments are supported: * `confirmations` - (Optional) The number of confirmation servers to use in order to detect downtime. Defaults to 0. * `port` - (Optional) The port to use when specifying a TCP test. * `trigger_rate` - (Optional) The number of minutes to wait before sending an alert. Default is `5`. - +* `custom_header` - (Optional) Custom HTTP header, must be supplied as JSON. +* `user_agent` - (Optional) Test with a custom user agent set. +* `node_locations` - (Optional) Set test node locations, must be array of strings. +* `ping_url` - (Optional) A URL to ping if a site goes down. +* `basic_user` - (Optional) A Basic Auth User account to use to login +* `basic_pass` - (Optional) If BasicUser is set then this should be the password for the BasicUser. +* `public` - (Optional) Set 1 to enable public reporting, 0 to disable. +* `logo_image` - (Optional) A URL to a image to use for public reporting. +* `branding` - (Optional) Set to 0 to use branding (default) or 1 to disable public reporting branding). +* `website_host` - (Optional) Used internally, when possible please add. +* `virus` - (Optional) Enable virus checking or not. 1 to enable +* `find_string` - (Optional) A string that should either be found or not found. +* `do_not_find` - (Optional) If the above string should be found to trigger a alert. 1 = will trigger if find_string found. +* `real_browser` - (Optional) Use 1 to TURN OFF real browser testing. +* `test_tags` - (Optional) Tags should be seperated by a comma - no spacing between tags (this,is,a set,of,tags). +* `status_codes` - (Optional) Comma Seperated List of StatusCodes to Trigger Error on. Defaults are "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, 408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, 598, 599". +* `use_jar` - (Optional) Set to true to enable the Cookie Jar. Required for some redirects. Default is false. +* `post_raw` - (Optional) Use to populate the RAW POST data field on the test. +* `final_endpoint` - (Optional) Use to specify the expected Final URL in the testing process. +* `follow_redirect` - (Optional) Use to specify whether redirects should be followed, set to true to enable. Default is false. ## Attributes Reference -- cgit v1.2.3 From b01919994f2f0113f00c3afb931cb5a278d7ab0b Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Wed, 17 Jan 2018 16:54:57 +0200 Subject: fix type casts --- statuscake/resource_statuscaketest.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 50e16f9..187f711 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -10,6 +10,16 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) +func castInterfaceToSliceStrings(in interface{}) []string { + input := in.([]interface{}) + res := make([]string, len(input)) + + for i, element := range input { + res[i] = element.(string) + } + return res +} + func resourceStatusCakeTest() *schema.Resource { return &schema.Resource{ Create: CreateTest, @@ -212,7 +222,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { UserAgent: d.Get("user_agent").(string), Status: d.Get("status").(string), Uptime: d.Get("uptime").(float64), - NodeLocations: d.Get("node_locations").([]string), + NodeLocations: castInterfaceToSliceStrings(d.Get("node_locations")), PingURL: d.Get("ping_url").(string), BasicUser: d.Get("basic_user").(string), BasicPass: d.Get("basic_pass").(string), @@ -301,7 +311,9 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { d.Set("user_agent", testResp.UserAgent) d.Set("status", testResp.Status) d.Set("uptime", testResp.Uptime) - d.Set("node_locations", testResp.NodeLocations) + if err := d.Set("node_locations", testResp.NodeLocations); err != nil { + return fmt.Errorf("[WARN] Error setting node locations: %s", err) + } d.Set("ping_url", testResp.PingURL) d.Set("basic_user", testResp.BasicUser) d.Set("basic_pass", testResp.BasicPass) @@ -368,7 +380,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { test.UserAgent = v.(string) } if v, ok := d.GetOk("node_locations"); ok { - test.NodeLocations = v.([]string) + test.NodeLocations = castInterfaceToSliceStrings(v) } if v, ok := d.GetOk("ping_url"); ok { test.PingURL = v.(string) -- cgit v1.2.3 From c9458806c73b69e6af47eddd83391197b6d2a641 Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Wed, 17 Jan 2018 16:55:18 +0200 Subject: merge changes from https://github.com/DreamItGetIT/statuscake/pull/24 to vendor directory --- statuscake/resource_statuscaketest.go | 6 +++--- statuscake/resource_statuscaketest_test.go | 6 +++--- vendor/github.com/DreamItGetIT/statuscake/responses.go | 2 +- vendor/github.com/DreamItGetIT/statuscake/tests.go | 2 +- vendor/vendor.json | 7 ++++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 187f711..459c71a 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -44,7 +44,7 @@ func resourceStatusCakeTest() *schema.Resource { }, "contact_id": { - Type: schema.TypeString, + Type: schema.TypeInt, Optional: true, }, @@ -214,7 +214,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { TestType: d.Get("test_type").(string), Paused: d.Get("paused").(bool), Timeout: d.Get("timeout").(int), - ContactID: d.Get("contact_id").(string), + ContactID: d.Get("contact_id").(int), Confirmation: d.Get("confirmations").(int), Port: d.Get("port").(int), TriggerRate: d.Get("trigger_rate").(int), @@ -353,7 +353,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { test.CheckRate = v.(int) } if v, ok := d.GetOk("contact_id"); ok { - test.ContactID = v.(string) + test.ContactID = v.(int) } if v, ok := d.GetOk("test_type"); ok { test.TestType = v.(string) diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index 99acd04..b727e92 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -162,7 +162,7 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC case "timeout": err = check(key, value, strconv.Itoa(test.Timeout)) case "contact_id": - err = check(key, value, test.ContactID) + err = check(key, value, strconv.Itoa(test.ContactID)) case "confirmations": err = check(key, value, strconv.Itoa(test.Confirmation)) case "trigger_rate": @@ -240,7 +240,7 @@ resource "statuscake_test" "google" { test_type = "HTTP" check_rate = 300 timeout = 10 - contact_id = "43402" + contact_id = 43402 confirmations = 1 trigger_rate = 10 } @@ -284,7 +284,7 @@ resource "statuscake_test" "google" { test_type = "TCP" check_rate = 300 timeout = 10 - contact_id = "43402" + contact_id = 43402 confirmations = 1 port = 80 } diff --git a/vendor/github.com/DreamItGetIT/statuscake/responses.go b/vendor/github.com/DreamItGetIT/statuscake/responses.go index 9cdcb11..3cbf36d 100644 --- a/vendor/github.com/DreamItGetIT/statuscake/responses.go +++ b/vendor/github.com/DreamItGetIT/statuscake/responses.go @@ -28,7 +28,7 @@ type detailResponse struct { Paused bool `json:"Paused"` WebsiteName string `json:"WebsiteName"` URI string `json:"URI"` - ContactID string `json:"ContactID"` + ContactID int `json:"ContactID"` Status string `json:"Status"` Uptime float64 `json:"Uptime"` CustomHeader string `json:"CustomHeader"` diff --git a/vendor/github.com/DreamItGetIT/statuscake/tests.go b/vendor/github.com/DreamItGetIT/statuscake/tests.go index 1b37fa1..a41b0bd 100644 --- a/vendor/github.com/DreamItGetIT/statuscake/tests.go +++ b/vendor/github.com/DreamItGetIT/statuscake/tests.go @@ -34,7 +34,7 @@ type Test struct { Port int `json:"Port" querystring:"Port"` // Contact group ID - will return int of contact group used else 0 - ContactID string `json:"ContactID" querystring:"ContactGroup"` + ContactID int `json:"ContactID" querystring:"ContactGroup"` // Current status at last test Status string `json:"Status"` diff --git a/vendor/vendor.json b/vendor/vendor.json index 921131f..d2bc87c 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -3,10 +3,11 @@ "ignore": "appengine test github.com/hashicorp/nomad/ github.com/hashicorp/terraform/backend", "package": [ { - "checksumSHA1": "xjfJ6T+mQFmC9oMR+UKdGtbs/p4=", + "checksumSHA1": "6Fo7YzTT+MDviHOsqg6dNw8WrV4=", + "origin": "github.com/matschaffer/statuscake", "path": "github.com/DreamItGetIT/statuscake", - "revision": "2081e16dbe691bccf20b1901897d8f8245beefcd", - "revisionTime": "2018-01-09T18:02:45Z" + "revision": "24c596002b80d84cf3bfb0f714e880c1b2e9af16", + "revisionTime": "2018-01-16T08:09:52Z" }, { "checksumSHA1": "FIL83loX9V9APvGQIjJpbxq53F0=", -- cgit v1.2.3 From aa4f9726b4fd3cc624fe5784b033840a6c92c84c Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:07:31 +0900 Subject: Parameterize the contact ID used for acceptance testing This allowed me to run acceptance tests on my own account. --- statuscake/provider_test.go | 15 +++++++++++++++ statuscake/resource_statuscaketest_test.go | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/statuscake/provider_test.go b/statuscake/provider_test.go index 83045d0..81d5888 100644 --- a/statuscake/provider_test.go +++ b/statuscake/provider_test.go @@ -1,7 +1,9 @@ package statuscake import ( + "fmt" "os" + "strconv" "testing" "github.com/hashicorp/terraform/helper/schema" @@ -10,12 +12,25 @@ import ( var testAccProviders map[string]terraform.ResourceProvider var testAccProvider *schema.Provider +var testContactGroupId int func init() { testAccProvider = Provider().(*schema.Provider) testAccProviders = map[string]terraform.ResourceProvider{ "statuscake": testAccProvider, } + + if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v == "" { + fmt.Println("STATUSCAKE_TEST_CONTACT_GROUP_ID must be set for acceptance tests") + os.Exit(1) + } else { + id, err := strconv.Atoi(v) + if err != nil { + fmt.Println("STATUSCAKE_TEST_CONTACT_GROUP_ID must be a valid int") + os.Exit(1) + } + testContactGroupId = id + } } func TestProvider(t *testing.T) { diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index b727e92..ea69756 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -19,7 +19,7 @@ func TestAccStatusCake_basic(t *testing.T) { CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ { - Config: testAccTestConfig_basic, + Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId), Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), testAccTestCheckAttributes("statuscake_test.google", &test), @@ -38,7 +38,7 @@ func TestAccStatusCake_tcp(t *testing.T) { CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ { - Config: testAccTestConfig_tcp, + Config: fmt.Sprintf(testAccTestConfig_tcp, testContactGroupId), Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), testAccTestCheckAttributes("statuscake_test.google", &test), @@ -57,7 +57,7 @@ func TestAccStatusCake_withUpdate(t *testing.T) { CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ { - Config: testAccTestConfig_basic, + Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId), Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), ), @@ -240,7 +240,7 @@ resource "statuscake_test" "google" { test_type = "HTTP" check_rate = 300 timeout = 10 - contact_id = 43402 + contact_id = %d confirmations = 1 trigger_rate = 10 } @@ -284,7 +284,7 @@ resource "statuscake_test" "google" { test_type = "TCP" check_rate = 300 timeout = 10 - contact_id = 43402 + contact_id = %d confirmations = 1 port = 80 } -- cgit v1.2.3 From ed5e20e8578d3a01b41fecf3f075887bd3e24584 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:08:10 +0900 Subject: Mark basic_pass sensitive Avoids showing the password in plan output --- statuscake/resource_statuscaketest.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 459c71a..e824955 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -123,8 +123,9 @@ func resourceStatusCakeTest() *schema.Resource { }, "basic_pass": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + Sensitive: true, }, "public": { -- cgit v1.2.3 From 5c7efdcb8c0a6d3d21f1fb1481bb95e402296d77 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:10:15 +0900 Subject: Remove status codes default In my testing, the default response was `[""]` and having the default provided cause test assertion failures --- statuscake/resource_statuscaketest.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index e824955..8e67bcd 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -176,10 +176,6 @@ func resourceStatusCakeTest() *schema.Resource { "status_codes": { Type: schema.TypeString, Optional: true, - Default: "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, " + - "408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, " + - "504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, " + - "598, 599", }, "use_jar": { -- cgit v1.2.3 From d01e3cca165df6d7d4a9d2a6cf30ed5a7bed9a4c Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:10:53 +0900 Subject: Fix status & uptime assertions They were present in the details but the values were different during my testing. Hopefully this proves true for all future testing. --- statuscake/resource_statuscaketest_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index ea69756..62d6bf9 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -76,8 +76,8 @@ func TestAccStatusCake_withUpdate(t *testing.T) { resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"), resource.TestCheckResourceAttr("statuscake_test.google", "custom_header", "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"), resource.TestCheckResourceAttr("statuscake_test.google", "user_agent", "string9988"), - resource.TestCheckResourceAttr("statuscake_test.google", "status", "string22117"), - resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "3498.27"), + resource.TestCheckResourceAttr("statuscake_test.google", "status", "Up"), + resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "0"), resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.#", "3"), resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.0", "string16045"), resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.1", "string19741"), -- cgit v1.2.3 From 89027b6ac2e02ed5097e2aed6e2a5e0b0476d5f9 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:14:33 +0900 Subject: Switch node locations to a set and consider empty string to be empty set Note that we also don't check the individual locations anymore. The key numbers will be randomized and not testing content seems to be the method employed by the AWS provider as well https://github.com/terraform-providers/terraform-provider-aws/blob/81bba6b1f567aed561c6a6a30916504ee0886c68/aws/resource_aws_autoscaling_group_test.go#L404 --- statuscake/resource_statuscaketest.go | 25 +++++++++++++++++-------- statuscake/resource_statuscaketest_test.go | 3 --- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 8e67bcd..b2b0c68 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -10,16 +10,24 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func castInterfaceToSliceStrings(in interface{}) []string { - input := in.([]interface{}) - res := make([]string, len(input)) +func castSetToSliceStrings(configured []interface{}) []string { + res := make([]string, len(configured)) - for i, element := range input { + for i, element := range configured { res[i] = element.(string) } return res } +// Special handling for node_locations since statuscake will return `[""]` for the empty case +func considerEmptyStringAsEmptyArray(in []string) []string { + if len(in) == 1 && in[0] == "" { + return []string{} + } else { + return in + } +} + func resourceStatusCakeTest() *schema.Resource { return &schema.Resource{ Create: CreateTest, @@ -107,9 +115,10 @@ func resourceStatusCakeTest() *schema.Resource { }, "node_locations": { - Type: schema.TypeList, + Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, + Set: schema.HashString, }, "ping_url": { @@ -219,7 +228,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { UserAgent: d.Get("user_agent").(string), Status: d.Get("status").(string), Uptime: d.Get("uptime").(float64), - NodeLocations: castInterfaceToSliceStrings(d.Get("node_locations")), + NodeLocations: castSetToSliceStrings(d.Get("node_locations").(*schema.Set).List()), PingURL: d.Get("ping_url").(string), BasicUser: d.Get("basic_user").(string), BasicPass: d.Get("basic_pass").(string), @@ -308,7 +317,7 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { d.Set("user_agent", testResp.UserAgent) d.Set("status", testResp.Status) d.Set("uptime", testResp.Uptime) - if err := d.Set("node_locations", testResp.NodeLocations); err != nil { + if err := d.Set("node_locations", considerEmptyStringAsEmptyArray(testResp.NodeLocations)); err != nil { return fmt.Errorf("[WARN] Error setting node locations: %s", err) } d.Set("ping_url", testResp.PingURL) @@ -377,7 +386,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { test.UserAgent = v.(string) } if v, ok := d.GetOk("node_locations"); ok { - test.NodeLocations = castInterfaceToSliceStrings(v) + test.NodeLocations = castSetToSliceStrings(v.(*schema.Set).List()) } if v, ok := d.GetOk("ping_url"); ok { test.PingURL = v.(string) diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index 62d6bf9..555cff1 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -79,9 +79,6 @@ func TestAccStatusCake_withUpdate(t *testing.T) { resource.TestCheckResourceAttr("statuscake_test.google", "status", "Up"), resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "0"), resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.#", "3"), - resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.0", "string16045"), - resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.1", "string19741"), - resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.2", "string12122"), resource.TestCheckResourceAttr("statuscake_test.google", "ping_url", "string8410"), resource.TestCheckResourceAttr("statuscake_test.google", "basic_user", "string27052"), resource.TestCheckResourceAttr("statuscake_test.google", "basic_pass", "string5659"), -- cgit v1.2.3 From ef20d8d74891bfcfbf17088c4cd9c39cd1e347dd Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:15:21 +0900 Subject: Don't attempt to set or verify values which aren't present in the details response The `TestCheckResourceAttr` tests can stay since they rely on the state from the previous apply. --- statuscake/resource_statuscaketest.go | 15 +++++---------- statuscake/resource_statuscaketest_test.go | 18 ------------------ 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index b2b0c68..d7d3f36 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -314,24 +314,19 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { d.Set("port", testResp.Port) d.Set("trigger_rate", testResp.TriggerRate) d.Set("custom_header", testResp.CustomHeader) - d.Set("user_agent", testResp.UserAgent) d.Set("status", testResp.Status) d.Set("uptime", testResp.Uptime) if err := d.Set("node_locations", considerEmptyStringAsEmptyArray(testResp.NodeLocations)); err != nil { return fmt.Errorf("[WARN] Error setting node locations: %s", err) } - d.Set("ping_url", testResp.PingURL) - d.Set("basic_user", testResp.BasicUser) - d.Set("basic_pass", testResp.BasicPass) - d.Set("public", testResp.Public) d.Set("logo_image", testResp.LogoImage) - d.Set("branding", testResp.Branding) - d.Set("website_host", testResp.WebsiteHost) - d.Set("virus", testResp.Virus) + // Even after WebsiteHost is set, the API returns "" + // API docs aren't clear on usage will only override state if we get a non-empty value back + if testResp.WebsiteHost != "" { + d.Set("website_host", testResp.WebsiteHost) + } d.Set("find_string", testResp.FindString) d.Set("do_not_find", testResp.DoNotFind) - d.Set("real_browser", testResp.RealBrowser) - d.Set("test_tags", testResp.TestTags) d.Set("status_codes", testResp.StatusCodes) d.Set("use_jar", testResp.UseJar) d.Set("post_raw", testResp.PostRaw) diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index 555cff1..da3a349 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -166,8 +166,6 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC err = check(key, value, strconv.Itoa(test.TriggerRate)) case "custom_header": err = check(key, value, test.CustomHeader) - case "user_agent": - err = check(key, value, test.UserAgent) case "node_locations": for _, tv := range test.NodeLocations { err = check(key, value, tv) @@ -175,30 +173,14 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC return err } } - case "ping_url": - err = check(key, value, test.PingURL) - case "basic_user": - err = check(key, value, test.BasicUser) - case "basic_pass": - err = check(key, value, test.BasicPass) case "public": err = check(key, value, strconv.Itoa(test.Public)) case "logo_image": err = check(key, value, test.LogoImage) - case "branding": - err = check(key, value, strconv.Itoa(test.Branding)) - case "website_host": - err = check(key, value, test.WebsiteHost) - case "virus": - err = check(key, value, strconv.Itoa(test.Virus)) case "find_string": err = check(key, value, test.FindString) case "do_not_find": err = check(key, value, strconv.FormatBool(test.DoNotFind)) - case "real_browser": - err = check(key, value, strconv.Itoa(test.RealBrowser)) - case "test_tags": - err = check(key, value, test.TestTags) case "status_codes": err = check(key, value, test.StatusCodes) case "use_jar": -- cgit v1.2.3 From 85e124eb0c7b262ff9c486abe9662f515f47fc5b Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Wed, 31 Jan 2018 13:45:28 +0200 Subject: update github.com/DreamItGetIT/statuscake --- .../DreamItGetIT/statuscake/cmd/statuscake/main.go | 229 --------------------- .../statuscake/fixtures/auth_error.json | 4 - .../statuscake/fixtures/tests_all_ok.json | 22 -- .../statuscake/fixtures/tests_delete_error.json | 5 - .../statuscake/fixtures/tests_delete_ok.json | 6 - .../statuscake/fixtures/tests_detail_ok.json | 34 --- .../statuscake/fixtures/tests_update_error.json | 9 - .../tests_update_error_slice_of_issues.json | 5 - .../statuscake/fixtures/tests_update_ok.json | 6 - vendor/vendor.json | 5 +- 10 files changed, 2 insertions(+), 323 deletions(-) delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json diff --git a/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go b/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go deleted file mode 100644 index dc86b47..0000000 --- a/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go +++ /dev/null @@ -1,229 +0,0 @@ -package main - -import ( - "fmt" - logpkg "log" - "os" - "strconv" - - "github.com/DreamItGetIT/statuscake" -) - -var log *logpkg.Logger - -type command func(*statuscake.Client, ...string) error - -var commands map[string]command - -func init() { - log = logpkg.New(os.Stderr, "", 0) - commands = map[string]command{ - "list": cmdList, - "detail": cmdDetail, - "delete": cmdDelete, - "create": cmdCreate, - "update": cmdUpdate, - } -} - -func colouredStatus(s string) string { - switch s { - case "Up": - return fmt.Sprintf("\033[0;32m%s\033[0m", s) - case "Down": - return fmt.Sprintf("\033[0;31m%s\033[0m", s) - default: - return s - } -} - -func getEnv(name string) string { - v := os.Getenv(name) - if v == "" { - log.Fatalf("`%s` env variable is required", name) - } - - return v -} - -func cmdList(c *statuscake.Client, args ...string) error { - tt := c.Tests() - tests, err := tt.All() - if err != nil { - return err - } - - for _, t := range tests { - var paused string - if t.Paused { - paused = "yes" - } else { - paused = "no" - } - - fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) - fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) - fmt.Printf(" TestType: %s\n", t.TestType) - fmt.Printf(" Paused: %s\n", paused) - fmt.Printf(" ContactID: %d\n", t.ContactID) - fmt.Printf(" Uptime: %f\n", t.Uptime) - } - - return nil -} - -func cmdDetail(c *statuscake.Client, args ...string) error { - if len(args) != 1 { - return fmt.Errorf("command `detail` requires a single argument `TestID`") - } - - id, err := strconv.Atoi(args[0]) - if err != nil { - return err - } - - tt := c.Tests() - t, err := tt.Detail(id) - if err != nil { - return err - } - - var paused string - if t.Paused { - paused = "yes" - } else { - paused = "no" - } - - fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) - fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) - fmt.Printf(" WebsiteURL: %s\n", t.WebsiteURL) - fmt.Printf(" PingURL: %s\n", t.PingURL) - fmt.Printf(" TestType: %s\n", t.TestType) - fmt.Printf(" Paused: %s\n", paused) - fmt.Printf(" ContactID: %d\n", t.ContactID) - fmt.Printf(" Uptime: %f\n", t.Uptime) - - return nil -} - -func cmdDelete(c *statuscake.Client, args ...string) error { - if len(args) != 1 { - return fmt.Errorf("command `delete` requires a single argument `TestID`") - } - - id, err := strconv.Atoi(args[0]) - if err != nil { - return err - } - - return c.Tests().Delete(id) -} - -func askString(name string) string { - var v string - - fmt.Printf("%s: ", name) - _, err := fmt.Scanln(&v) - if err != nil { - log.Fatal(err) - } - - return v -} - -func askInt(name string) int { - v := askString(name) - i, err := strconv.Atoi(v) - if err != nil { - log.Fatalf("Invalid number `%s`", v) - } - - return i -} - -func cmdCreate(c *statuscake.Client, args ...string) error { - t := &statuscake.Test{ - WebsiteName: askString("WebsiteName"), - WebsiteURL: askString("WebsiteURL"), - TestType: askString("TestType"), - CheckRate: askInt("CheckRate"), - } - - t2, err := c.Tests().Update(t) - if err != nil { - return err - } - - fmt.Printf("CREATED: \n%+v\n", t2) - - return nil -} - -func cmdUpdate(c *statuscake.Client, args ...string) error { - if len(args) != 1 { - return fmt.Errorf("command `update` requires a single argument `TestID`") - } - - id, err := strconv.Atoi(args[0]) - if err != nil { - return err - } - - tt := c.Tests() - t, err := tt.Detail(id) - if err != nil { - return err - } - - t.TestID = id - t.WebsiteName = askString(fmt.Sprintf("WebsiteName [%s]", t.WebsiteName)) - t.WebsiteURL = askString(fmt.Sprintf("WebsiteURL [%s]", t.WebsiteURL)) - t.TestType = askString(fmt.Sprintf("TestType [%s]", t.TestType)) - t.CheckRate = askInt(fmt.Sprintf("CheckRate [%d]", t.CheckRate)) - - t2, err := c.Tests().Update(t) - if err != nil { - return err - } - - fmt.Printf("UPDATED: \n%+v\n", t2) - - return nil -} - -func usage() { - fmt.Printf("Usage:\n") - fmt.Printf(" %s COMMAND\n", os.Args[0]) - fmt.Printf("Available commands:\n") - for k := range commands { - fmt.Printf(" %+v\n", k) - } -} - -func main() { - username := getEnv("STATUSCAKE_USERNAME") - apikey := getEnv("STATUSCAKE_APIKEY") - - if len(os.Args) < 2 { - usage() - os.Exit(1) - } - - var err error - - c, err := statuscake.New(statuscake.Auth{Username: username, Apikey: apikey}) - if err != nil { - log.Fatal(err) - } - - if cmd, ok := commands[os.Args[1]]; ok { - err = cmd(c, os.Args[2:]...) - } else { - err = fmt.Errorf("Unknown command `%s`", os.Args[1]) - } - - if err != nil { - log.Fatalf("Error running command `%s`: %s", os.Args[1], err.Error()) - } -} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json deleted file mode 100644 index 4f14be5..0000000 --- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "ErrNo": 0, - "Error": "Can not access account. Was both Username and API Key provided?" -} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json deleted file mode 100644 index 81a913d..0000000 --- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "TestID": 100, - "Paused": false, - "TestType": "HTTP", - "WebsiteName": "www 1", - "ContactGroup": null, - "ContactID": "1", - "Status": "Up", - "Uptime": 100 - }, - { - "TestID": 101, - "Paused": true, - "TestType": "HTTP", - "WebsiteName": "www 2", - "ContactGroup": null, - "ContactID": "2", - "Status": "Down", - "Uptime": 0 - } -] diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json deleted file mode 100644 index 6fad58e..0000000 --- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Success": false, - "Error": "this is an error" -} - diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json deleted file mode 100644 index 0dd279b..0000000 --- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "TestID": 6735, - "Affected": 1, - "Success": true, - "Message": "This Check Has Been Deleted. It can not be recovered." -} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json deleted file mode 100644 index 9754aa2..0000000 --- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "TestID": 6735, - "TestType": "HTTP", - "Paused": false, - "WebsiteName": "NL", - "CustomHeader": "{\"some\":{\"json\": [\"value\"]}}", - "UserAgent": "product/version (comment)", - "ContactGroup": "StatusCake Alerts", - "ContactID": "536", - "Status": "Up", - "Uptime": 0, - "CheckRate": 60, - "Timeout": 40, - "LogoImage": "", - "WebsiteHost": "Various", - "NodeLocations": [ - "UK", - "JP", - "SG1", - "SLC" - ], - "FindString": "", - "DoNotFind": false, - "LastTested": "2013-01-20 14:38:18", - "NextLocation": "USNY", - "Processing": false, - "ProcessingState": "Pretest", - "ProcessingOn": "dalas.localdomain", - "DownTimes": "0", - "UseJar": 0, - "PostRaw": "", - "FinalEndpoint": "", - "FollowRedirect": false -} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json deleted file mode 100644 index a76c5eb..0000000 --- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Issues": { - "WebsiteName": "issue a", - "WebsiteURL": "issue b", - "CheckRate": "issue c" - }, - "Success": false, - "Message": "Required Data is Missing." -} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json deleted file mode 100644 index 02e98eb..0000000 --- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Issues": ["hello", "world"], - "Success": false, - "Message": "Required Data is Missing." -} diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json deleted file mode 100644 index 7c2dee2..0000000 --- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Issues": {}, - "Success": true, - "Message": "", - "InsertID": 1234 -} diff --git a/vendor/vendor.json b/vendor/vendor.json index d2bc87c..61dd8f3 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -4,10 +4,9 @@ "package": [ { "checksumSHA1": "6Fo7YzTT+MDviHOsqg6dNw8WrV4=", - "origin": "github.com/matschaffer/statuscake", "path": "github.com/DreamItGetIT/statuscake", - "revision": "24c596002b80d84cf3bfb0f714e880c1b2e9af16", - "revisionTime": "2018-01-16T08:09:52Z" + "revision": "f69198f958d7326f3c110dd9be1c21abbd8a87a7", + "revisionTime": "2018-01-30T22:14:43Z" }, { "checksumSHA1": "FIL83loX9V9APvGQIjJpbxq53F0=", -- cgit v1.2.3 From 7d96831373ec571cf0d7bcd930fd6118dc509fc2 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 22:53:16 +0900 Subject: Move template interpolation deeper into acceptance tests Since it was failing `make test` on travis. Must be a better way to go about this, but I couldn't come up with a better way that defaulting the value to avoid the error when running non-acceptance tests. --- statuscake/provider_test.go | 15 --------------- statuscake/resource_statuscaketest_test.go | 20 +++++++++++++++++--- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/statuscake/provider_test.go b/statuscake/provider_test.go index 81d5888..83045d0 100644 --- a/statuscake/provider_test.go +++ b/statuscake/provider_test.go @@ -1,9 +1,7 @@ package statuscake import ( - "fmt" "os" - "strconv" "testing" "github.com/hashicorp/terraform/helper/schema" @@ -12,25 +10,12 @@ import ( var testAccProviders map[string]terraform.ResourceProvider var testAccProvider *schema.Provider -var testContactGroupId int func init() { testAccProvider = Provider().(*schema.Provider) testAccProviders = map[string]terraform.ResourceProvider{ "statuscake": testAccProvider, } - - if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v == "" { - fmt.Println("STATUSCAKE_TEST_CONTACT_GROUP_ID must be set for acceptance tests") - os.Exit(1) - } else { - id, err := strconv.Atoi(v) - if err != nil { - fmt.Println("STATUSCAKE_TEST_CONTACT_GROUP_ID must be a valid int") - os.Exit(1) - } - testContactGroupId = id - } } func TestProvider(t *testing.T) { diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index da3a349..8bcbb36 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -2,6 +2,7 @@ package statuscake import ( "fmt" + "os" "strconv" "testing" @@ -19,7 +20,7 @@ func TestAccStatusCake_basic(t *testing.T) { CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId), + Config: interpolateTerraformTemplate(testAccTestConfig_basic), Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), testAccTestCheckAttributes("statuscake_test.google", &test), @@ -38,7 +39,7 @@ func TestAccStatusCake_tcp(t *testing.T) { CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testAccTestConfig_tcp, testContactGroupId), + Config: interpolateTerraformTemplate(testAccTestConfig_tcp), Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), testAccTestCheckAttributes("statuscake_test.google", &test), @@ -57,7 +58,7 @@ func TestAccStatusCake_withUpdate(t *testing.T) { CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId), + Config: interpolateTerraformTemplate(testAccTestConfig_basic), Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), ), @@ -212,6 +213,19 @@ func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc { } } +func interpolateTerraformTemplate(template string) string { + testContactGroupId := 43402 + + if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v != "" { + id, err := strconv.Atoi(v) + if err == nil { + testContactGroupId = id + } + } + + return fmt.Sprintf(template, testContactGroupId) +} + const testAccTestConfig_basic = ` resource "statuscake_test" "google" { website_name = "google.com" -- cgit v1.2.3