From 90db3fb0ba1aff53f83ece8f5d62f56943ed090e Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Wed, 15 Feb 2017 23:29:05 +0000 Subject: [PATCH] provider/statuscake: Add support for Port in statuscake_test (#11966) Fixes: #11923 This required the upstream library to have a PR accepted --- resource_statuscaketest.go | 28 ++++++++++++++++-------- resource_statuscaketest_test.go | 38 ++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/resource_statuscaketest.go b/resource_statuscaketest.go index bc05364..dbc15c9 100644 --- a/resource_statuscaketest.go +++ b/resource_statuscaketest.go @@ -18,50 +18,55 @@ func resourceStatusCakeTest() *schema.Resource { Read: ReadTest, Schema: map[string]*schema.Schema{ - "test_id": &schema.Schema{ + "test_id": { Type: schema.TypeString, Computed: true, }, - "website_name": &schema.Schema{ + "website_name": { Type: schema.TypeString, Required: true, }, - "website_url": &schema.Schema{ + "website_url": { Type: schema.TypeString, Required: true, }, - "contact_id": &schema.Schema{ + "contact_id": { Type: schema.TypeInt, Optional: true, }, - "check_rate": &schema.Schema{ + "check_rate": { Type: schema.TypeInt, Optional: true, Default: 300, }, - "test_type": &schema.Schema{ + "test_type": { Type: schema.TypeString, Required: true, }, - "paused": &schema.Schema{ + "paused": { Type: schema.TypeBool, Optional: true, Default: false, }, - "timeout": &schema.Schema{ + "timeout": { Type: schema.TypeInt, Optional: true, Default: 40, }, - "confirmations": &schema.Schema{ + "confirmations": { + Type: schema.TypeInt, + Optional: true, + }, + + "port": { Type: schema.TypeInt, Optional: true, }, @@ -81,6 +86,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { Timeout: d.Get("timeout").(int), ContactID: d.Get("contact_id").(int), Confirmation: d.Get("confirmations").(int), + Port: d.Get("port").(int), } log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) @@ -144,6 +150,7 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { d.Set("timeout", testResp.Timeout) d.Set("contact_id", testResp.ContactID) d.Set("confirmations", testResp.Confirmation) + d.Set("port", testResp.Port) return nil } @@ -183,5 +190,8 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { if v, ok := d.GetOk("confirmations"); ok { test.Confirmation = v.(int) } + if v, ok := d.GetOk("port"); ok { + test.Port = v.(int) + } return test } diff --git a/resource_statuscaketest_test.go b/resource_statuscaketest_test.go index 1def4e3..17940ed 100644 --- a/resource_statuscaketest_test.go +++ b/resource_statuscaketest_test.go @@ -18,7 +18,7 @@ func TestAccStatusCake_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccTestConfig_basic, Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), @@ -29,6 +29,25 @@ func TestAccStatusCake_basic(t *testing.T) { }) } +func TestAccStatusCake_tcp(t *testing.T) { + var test statuscake.Test + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccTestCheckDestroy(&test), + Steps: []resource.TestStep{ + { + Config: testAccTestConfig_tcp, + Check: resource.ComposeTestCheckFunc( + testAccTestCheckExists("statuscake_test.google", &test), + testAccTestCheckAttributes("statuscake_test.google", &test), + ), + }, + }, + }) +} + func TestAccStatusCake_withUpdate(t *testing.T) { var test statuscake.Test @@ -37,14 +56,14 @@ func TestAccStatusCake_withUpdate(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccTestCheckDestroy(&test), Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccTestConfig_basic, Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), ), }, - resource.TestStep{ + { Config: testAccTestConfig_update, Check: resource.ComposeTestCheckFunc( testAccTestCheckExists("statuscake_test.google", &test), @@ -163,3 +182,16 @@ resource "statuscake_test" "google" { paused = true } ` + +const testAccTestConfig_tcp = ` +resource "statuscake_test" "google" { + website_name = "google.com" + website_url = "www.google.com" + test_type = "TCP" + check_rate = 300 + timeout = 10 + contact_id = 12345 + confirmations = 1 + port = 80 +} +` -- 2.41.0