]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/DreamItGetIT/statuscake/tests.go
Merge pull request #35 from ivanschwarz/feat/ssl-validation-2
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / DreamItGetIT / statuscake / tests.go
index c6e6dd2d14f4e1ea309dfecda5bf696403ba177c..2a2383d550be493609a5c9f5d5da0b2177ccdaed 100644 (file)
@@ -42,7 +42,7 @@ type Test struct {
        // Current status at last test
        Status string `json:"Status"`
 
-       // 7 Day Uptime
+       // 1 Day Uptime
        Uptime float64 `json:"Uptime"`
 
        // Any test locations seperated by a comma (using the Node Location IDs)
@@ -75,7 +75,7 @@ type Test struct {
        Branding int `json:"Branding" querystring:"Branding"`
 
        // Used internally by the statuscake API
-       WebsiteHost string `json:"WebsiteHost"`
+       WebsiteHost string `json:"WebsiteHost" querystring:"WebsiteHost"`
 
        // Enable virus checking or not. 1 to enable
        Virus int `json:"Virus" querystring:"Virus"`
@@ -110,6 +110,9 @@ type Test struct {
        // Use to specify the expected Final URL in the testing process
        FinalEndpoint string `json:"FinalEndpoint" querystring:"FinalEndpoint"`
 
+       // Use to enable SSL validation
+       EnableSSLAlert bool `json:"EnableSSLAlert" querystring:"EnableSSLAlert"`
+
        // Use to specify whether redirects should be followed
        FollowRedirect bool `json:"FollowRedirect" querystring:"FollowRedirect"`
 }
@@ -166,9 +169,11 @@ func (t *Test) Validate() error {
                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 t.CustomHeader != "" {
+               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 {
@@ -244,6 +249,7 @@ func valueToQueryStringValue(v reflect.Value) string {
 // Tests is a client that implements the `Tests` API.
 type Tests interface {
        All() ([]*Test, error)
+       AllWithFilter(url.Values) ([]*Test, error)
        Detail(int) (*Test, error)
        Update(*Test) (*Test, error)
        Delete(TestID int) error
@@ -272,6 +278,19 @@ func (tt *tests) All() ([]*Test, error) {
        return tests, err
 }
 
+func (tt *tests) AllWithFilter(filterOptions url.Values) ([]*Test, error) {
+       resp, err := tt.client.get("/Tests", filterOptions)
+       if err != nil {
+               return nil, err
+       }
+       defer resp.Body.Close()
+
+       var tests []*Test
+       err = json.NewDecoder(resp.Body).Decode(&tests)
+
+       return tests, err
+}
+
 func (tt *tests) Update(t *Test) (*Test, error) {
        resp, err := tt.client.put("/Tests/Update", t.ToURLValues())
        if err != nil {