Skip to content

Commit 37ea565

Browse files
authored
Add and use acctest.SkipTestUntil (GoogleCloudPlatform#16559)
1 parent df11fa4 commit 37ea565

5 files changed

Lines changed: 60 additions & 0 deletions

File tree

docs/content/test/test.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,40 @@ If you skip a test in VCR mode, include a code comment explaining the reason for
553553
{{< /tab >}}
554554
{{% /tabs %}}
555555

556+
## Time-based skips {#skip-until-time}
557+
558+
Acceptance tests can be marked to be skipped until a certain future date, such as the projected date of a launch or
559+
rollout. This should generally be added after coordinating with your reviewer to capture a successful test run such as
560+
through a local run with an allowlisted project, against staging, etc.
561+
562+
Please include a comment with context where the skip is defined.
563+
564+
{{% tabs "skipping-tests-until-time" %}}
565+
{{< tab "Skip a generated test" >}}
566+
Skipping acceptance tests that are generated from example files can be achieved by adding `skip_func: acctest.SkipTestUntil(t, "YYYY-MM-DD")` in the example's YAML:
567+
568+
```yaml
569+
examples:
570+
- name: 'compute_address_basic'
571+
...
572+
skip_func: acctest.SkipTestUntil(t, "2026-01-31") # waiting for rollout
573+
```
574+
575+
{{< /tab >}}
576+
{{< tab "Skip a handwritten test" >}}
577+
Skipping acceptance tests that are handwritten can be achieved by adding `acctest.SkipTestUntil(t, "YYYY-MM-DD")` at the start of the test:
578+
579+
```go
580+
func TestAccPubsubTopic_update(t *testing.T) {
581+
acctest.SkipTestUntil(t, "2026-01-31") // b/1234567890
582+
acctest.VcrTest(t, resource.TestCase{ ... })
583+
}
584+
```
585+
586+
{{< /tab >}}
587+
{{% /tabs %}}
588+
589+
556590
### Reasons that tests are skipped in VCR replaying mode
557591

558592
| Problem | How to fix/Other info | Skip in VCR replaying? |

mmv1/api/resource/examples.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ type Examples struct {
164164
// unskipping the test. If this is not empty, the test will be skipped.
165165
SkipTest string `yaml:"skip_test,omitempty"`
166166

167+
// SkipFunc is a function call to a custom skip check
168+
SkipFunc string `yaml:"skip_func,omitempty"`
169+
167170
// Specify which external providers are needed for the testcase.
168171
// Think before adding as there is latency and adds an external dependency to
169172
// your test so avoid if you can.

mmv1/products/iamworkforcepool/WorkforcePoolProvider.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ examples:
107107
test_env_vars:
108108
org_id: ORG_ID
109109
- name: iam_workforce_pool_provider_extra_attributes_display_name_oauth2_config_client_basic
110+
skip_func: acctest.SkipTestUntil(t, "2026-03-05") # waiting for rollout
110111
primary_resource_id: example
111112
vars:
112113
workforce_pool_id: example-pool
@@ -117,6 +118,7 @@ examples:
117118
- oidc.0.client_secret.0.value.0.plain_text
118119
- extra_attributes_oauth2_client.0.client_secret.0.value.0.plain_text
119120
- name: iam_workforce_pool_provider_extra_attributes_display_name_oauth2_config_client_full
121+
skip_func: acctest.SkipTestUntil(t, "2026-03-05") # waiting for rollout
120122
primary_resource_id: example
121123
vars:
122124
workforce_pool_id: example-pool

mmv1/templates/terraform/examples/base_configs/test_file.go.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func TestAcc{{ $e.TestSlug $.Res.ProductMetadata.Name $.Res.Name }}(t *testing.T
5656
t.Skip("{{$e.SkipTest}}")
5757
{{- end }}
5858

59+
{{- if $e.SkipFunc }}
60+
{{$e.SkipFunc}}
61+
{{- end}}
62+
5963
{{- if $e.SkipVcr }}
6064
acctest.SkipIfVcr(t)
6165
{{- end }}

mmv1/third_party/terraform/acctest/test_utils.go.tmpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"strings"
1414
"testing"
15+
"time"
1516

1617
"github.com/hashicorp/terraform-plugin-framework/providerserver"
1718
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
@@ -157,6 +158,22 @@ func RandIntRange(t *testing.T, minInt int, maxInt int) int {
157158
return rand.New(s.source).Intn(maxInt-minInt) + minInt
158159
}
159160

161+
// SkipTestUntil skips a test until a given date, specified in YYYY-MM-DD.
162+
// You can bypass this skip by setting DISABLE_SKIP_TEST_UNTIL to "true"
163+
func SkipTestUntil(t *testing.T, enableDate string) {
164+
format := "2006-01-02" // go string for YYYY-MM-DD.
165+
enableDateTime, err := time.Parse(format, enableDate) // With no timezone we will use local time rather than UTC or a fixed TZ.
166+
if err != nil {
167+
t.Fatalf("failed to parse SkipTestUntil: %q, err: %v", enableDate, err)
168+
}
169+
170+
if time.Now().Before(enableDateTime) {
171+
if v := os.Getenv("DISABLE_SKIP_TEST_UNTIL"); v != "true" {
172+
t.Skipf("skipping test until %v", enableDate)
173+
}
174+
}
175+
}
176+
160177
// ProtoV5ProviderFactories returns a muxed ProviderServer that uses the provider code from this repo (SDK and plugin-framework).
161178
// Used to set ProtoV5ProviderFactories in a resource.TestStep within an acceptance test.
162179
func ProtoV5ProviderFactories(t *testing.T) map[string]func() (tfprotov5.ProviderServer, error) {

0 commit comments

Comments
 (0)