Skip to content

Commit

Permalink
Adding tests to verify that a refresh-only terraform apply mutates th…
Browse files Browse the repository at this point in the history
…e state for ready_for_renewal and maintains the requires replace behaviour for terraform apply (#268)
  • Loading branch information
bendbennett committed Oct 3, 2022
1 parent b6550b9 commit 9115ea8
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
54 changes: 54 additions & 0 deletions internal/provider/resource_locally_signed_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,60 @@ func TestResourceLocallySignedCert_DetectExpiringAndExpired(t *testing.T) {
overridableTimeFunc = oldNow
}

func TestResourceLocallySignedCert_DetectExpiring_Refresh(t *testing.T) {
oldNow := overridableTimeFunc
r.UnitTest(t, r.TestCase{
ProtoV5ProviderFactories: protoV5ProviderFactories(),
PreCheck: setTimeForTest("2019-06-14T12:00:00Z"),
Steps: []r.TestStep{
{
Config: locallySignedCertConfig(10, 2),
Check: r.TestCheckResourceAttr("tls_locally_signed_cert.test", "ready_for_renewal", "false"),
},
{
PreConfig: setTimeForTest("2019-06-14T21:30:00Z"),
Config: locallySignedCertConfig(10, 2),
RefreshState: true,
Check: r.TestCheckResourceAttr("tls_locally_signed_cert.test", "ready_for_renewal", "true"),
},
{
PreConfig: setTimeForTest("2019-06-14T21:30:00Z"),
Config: locallySignedCertConfig(10, 2),
PlanOnly: true,
ExpectNonEmptyPlan: true,
},
},
})
overridableTimeFunc = oldNow
}

func TestResourceLocallySignedCert_DetectExpired_Refresh(t *testing.T) {
oldNow := overridableTimeFunc
r.UnitTest(t, r.TestCase{
ProtoV5ProviderFactories: protoV5ProviderFactories(),
PreCheck: setTimeForTest("2019-06-14T12:00:00Z"),
Steps: []r.TestStep{
{
Config: locallySignedCertConfig(10, 2),
Check: r.TestCheckResourceAttr("tls_locally_signed_cert.test", "ready_for_renewal", "false"),
},
{
PreConfig: setTimeForTest("2019-06-14T23:30:00Z"),
Config: locallySignedCertConfig(10, 2),
RefreshState: true,
Check: r.TestCheckResourceAttr("tls_locally_signed_cert.test", "ready_for_renewal", "true"),
},
{
PreConfig: setTimeForTest("2019-06-14T23:30:00Z"),
Config: locallySignedCertConfig(10, 2),
PlanOnly: true,
ExpectNonEmptyPlan: true,
},
},
})
overridableTimeFunc = oldNow
}

func TestResourceLocallySignedCert_RecreatesAfterExpired(t *testing.T) {
oldNow := overridableTimeFunc
var previousCert string
Expand Down
54 changes: 54 additions & 0 deletions internal/provider/resource_self_signed_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,60 @@ func TestResourceSelfSignedCert_DetectExpiringAndExpired(t *testing.T) {
overridableTimeFunc = oldNow
}

func TestResourceSelfSignedCert_DetectExpiring_Refresh(t *testing.T) {
oldNow := overridableTimeFunc
r.UnitTest(t, r.TestCase{
ProtoV5ProviderFactories: protoV5ProviderFactories(),
PreCheck: setTimeForTest("2019-06-14T12:00:00Z"),
Steps: []r.TestStep{
{
Config: selfSignedCertConfig(10, 2),
Check: r.TestCheckResourceAttr("tls_self_signed_cert.test1", "ready_for_renewal", "false"),
},
{
PreConfig: setTimeForTest("2019-06-14T21:30:00Z"),
Config: selfSignedCertConfig(10, 2),
RefreshState: true,
Check: r.TestCheckResourceAttr("tls_self_signed_cert.test1", "ready_for_renewal", "true"),
},
{
PreConfig: setTimeForTest("2019-06-14T21:30:00Z"),
Config: selfSignedCertConfig(10, 2),
PlanOnly: true,
ExpectNonEmptyPlan: true,
},
},
})
overridableTimeFunc = oldNow
}

func TestResourceSelfSignedCert_DetectExpired_Refresh(t *testing.T) {
oldNow := overridableTimeFunc
r.UnitTest(t, r.TestCase{
ProtoV5ProviderFactories: protoV5ProviderFactories(),
PreCheck: setTimeForTest("2019-06-14T12:00:00Z"),
Steps: []r.TestStep{
{
Config: selfSignedCertConfig(10, 2),
Check: r.TestCheckResourceAttr("tls_self_signed_cert.test1", "ready_for_renewal", "false"),
},
{
PreConfig: setTimeForTest("2019-06-14T23:30:00Z"),
Config: selfSignedCertConfig(10, 2),
RefreshState: true,
Check: r.TestCheckResourceAttr("tls_self_signed_cert.test1", "ready_for_renewal", "true"),
},
{
PreConfig: setTimeForTest("2019-06-14T23:30:00Z"),
Config: selfSignedCertConfig(10, 2),
PlanOnly: true,
ExpectNonEmptyPlan: true,
},
},
})
overridableTimeFunc = oldNow
}

func TestResourceSelfSignedCert_RecreatesAfterExpired(t *testing.T) {
oldNow := overridableTimeFunc
var previousCert string
Expand Down

0 comments on commit 9115ea8

Please sign in to comment.