|
| 1 | +# Copyright (c) HashiCorp, Inc. |
| 2 | +# SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +rules: |
| 5 | + - id: use-acctest-test |
| 6 | + languages: [go] |
| 7 | + message: "Use acctest.Test instead of resource.Test for VCR-compatible acceptance testing" |
| 8 | + severity: WARNING |
| 9 | + pattern: | |
| 10 | + resource.Test($T, $TC) |
| 11 | + fix: | |
| 12 | + acctest.Test(ctx, $T, $TC) |
| 13 | + paths: |
| 14 | + include: |
| 15 | + - "**/*_test.go" |
| 16 | + |
| 17 | + - id: use-acctest-paralleltest |
| 18 | + languages: [go] |
| 19 | + message: "Use acctest.ParallelTest instead of resource.ParallelTest for VCR-compatible acceptance testing" |
| 20 | + severity: WARNING |
| 21 | + pattern: | |
| 22 | + resource.ParallelTest($T, $TC) |
| 23 | + fix: | |
| 24 | + acctest.ParallelTest(ctx, $T, $TC) |
| 25 | + paths: |
| 26 | + include: |
| 27 | + - "**/*_test.go" |
| 28 | + |
| 29 | + - id: use-acctest-randomwithprefix |
| 30 | + languages: [go] |
| 31 | + message: "Use acctest.RandomWithPrefix instead of sdkacctest.RandomWithPrefix for VCR-compatible acceptance testing" |
| 32 | + severity: WARNING |
| 33 | + pattern: | |
| 34 | + sdkacctest.RandomWithPrefix($P) |
| 35 | + fix: | |
| 36 | + acctest.RandomWithPrefix(t, $P) |
| 37 | + paths: |
| 38 | + include: |
| 39 | + - "**/*_test.go" |
| 40 | + |
| 41 | + - id: use-acctest-randint |
| 42 | + languages: [go] |
| 43 | + message: "Use acctest.RandInt instead of sdkacctest.RandInt for VCR-compatible acceptance testing" |
| 44 | + severity: WARNING |
| 45 | + pattern: | |
| 46 | + sdkacctest.RandInt() |
| 47 | + fix: | |
| 48 | + acctest.RandInt(t) |
| 49 | + paths: |
| 50 | + include: |
| 51 | + - "**/*_test.go" |
| 52 | + |
| 53 | + - id: use-acctest-providermeta |
| 54 | + languages: [go] |
| 55 | + message: "Use acctest.ProviderMeta instead of acctest.Provider.Meta for VCR-compatible acceptance testing" |
| 56 | + severity: WARNING |
| 57 | + pattern: | |
| 58 | + acctest.Provider.Meta().(*conns.AWSClient).$C(ctx) |
| 59 | + fix: | |
| 60 | + acctest.ProviderMeta(ctx, t).$C(ctx) |
| 61 | + paths: |
| 62 | + include: |
| 63 | + - "**/*_test.go" |
| 64 | + |
| 65 | + - id: add-testing-t-to-destroy-testcheckfunc |
| 66 | + languages: [go] |
| 67 | + message: "Add a testing.T argument into destroy TestCheckFunc helpers for VCR-compatible acceptance testing" |
| 68 | + severity: WARNING |
| 69 | + patterns: |
| 70 | + - pattern: | |
| 71 | + func $F(ctx context.Context) resource.TestCheckFunc |
| 72 | + - metavariable-regex: |
| 73 | + metavariable: $F |
| 74 | + regex: (testAccCheck.*Destroy.*) |
| 75 | + fix: | |
| 76 | + func $F(ctx context.Context, t *testing.T) resource.TestCheckFunc |
| 77 | + paths: |
| 78 | + include: |
| 79 | + - "**/*_test.go" |
| 80 | + |
| 81 | + - id: add-testing-t-to-exists-testcheckfunc |
| 82 | + languages: [go] |
| 83 | + message: "Add a testing.T argument into exists TestCheckFunc helpers for VCR-compatible acceptance testing" |
| 84 | + severity: WARNING |
| 85 | + patterns: |
| 86 | + - pattern: | |
| 87 | + func $F(ctx context.Context, $...ARGS) resource.TestCheckFunc |
| 88 | + - pattern-not: | |
| 89 | + func $F(ctx context.Context) resource.TestCheckFunc |
| 90 | + - pattern-not: | |
| 91 | + func $F(..., t *testing.T, ...) resource.TestCheckFunc |
| 92 | + - metavariable-regex: |
| 93 | + metavariable: $F |
| 94 | + regex: (testAccCheck.*Exists$) |
| 95 | + fix: | |
| 96 | + func $F(ctx context.Context, t *testing.T, $...ARGS) resource.TestCheckFunc |
| 97 | + paths: |
| 98 | + include: |
| 99 | + - "**/*_test.go" |
| 100 | + |
| 101 | + # NOTE: because this matched pattern is inside another section which is replaced by a previous rule, |
| 102 | + # autofix may need to be run twice in order to apply this change. |
| 103 | + - id: pass-testing-t-to-destroy-testcheckfunc |
| 104 | + languages: [go] |
| 105 | + message: "Pass testing.T argument into destroy TestCheckFunc helpers for VCR-compatible acceptance testing" |
| 106 | + severity: WARNING |
| 107 | + patterns: |
| 108 | + - pattern-inside: "resource.TestCase{ ... }" |
| 109 | + - pattern: | |
| 110 | + $F(ctx) |
| 111 | + - metavariable-regex: |
| 112 | + metavariable: $F |
| 113 | + regex: (testAccCheck.*Destroy.*) |
| 114 | + fix: | |
| 115 | + $F(ctx, t) |
| 116 | + paths: |
| 117 | + include: |
| 118 | + - "**/*_test.go" |
| 119 | + |
| 120 | + # NOTE: because this matched pattern is inside another section which is replaced by a previous rule, |
| 121 | + # autofix may need to be run twice in order to apply this change. |
| 122 | + - id: pass-testing-t-to-exists-testcheckfunc |
| 123 | + languages: [go] |
| 124 | + message: "Pass testing.T argument into exists TestCheckFunc helpers for VCR-compatible acceptance testing" |
| 125 | + severity: WARNING |
| 126 | + patterns: |
| 127 | + - pattern-either: |
| 128 | + - pattern-inside: "Check: resource.ComposeTestCheckFunc( ... )" |
| 129 | + - pattern-inside: "Check: resource.ComposeAggregateTestCheckFunc( ... )" |
| 130 | + - pattern: | |
| 131 | + $F(ctx, $...ARGS) |
| 132 | + - pattern-not: | |
| 133 | + $F(ctx) |
| 134 | + - pattern-not: | |
| 135 | + $F(..., t, ...) |
| 136 | + - metavariable-regex: |
| 137 | + metavariable: $F |
| 138 | + regex: (testAccCheck.*Exists$) |
| 139 | + fix: | |
| 140 | + $F(ctx, t, $...ARGS) |
| 141 | + paths: |
| 142 | + include: |
| 143 | + - "**/*_test.go" |
0 commit comments