|
| 1 | +package stringfunc_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 7 | + |
| 8 | + provider "github.com/mschuchard/terraform-provider-stdlib/stdlib" |
| 9 | +) |
| 10 | + |
| 11 | +func TestAccCut(test *testing.T) { |
| 12 | + // invoke test |
| 13 | + resource.ParallelTest(test, resource.TestCase{ |
| 14 | + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, |
| 15 | + Steps: []resource.TestStep{ |
| 16 | + // test basic string cut |
| 17 | + { |
| 18 | + Config: `data "stdlib_cut" "test" { |
| 19 | + param = "foobarbaz" |
| 20 | + separator = "bar" |
| 21 | + }`, |
| 22 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 23 | + // verify input param is stored correctly |
| 24 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "param", "foobarbaz"), |
| 25 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "separator", "bar"), |
| 26 | + // verify before, after, and found are stored correctly |
| 27 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "before", "foo"), |
| 28 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "after", "baz"), |
| 29 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "found", "true"), |
| 30 | + // verify id stored correctly |
| 31 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "id", "foobarbaz"), |
| 32 | + ), |
| 33 | + }, |
| 34 | + // test basic string cut absent separator |
| 35 | + { |
| 36 | + Config: `data "stdlib_cut" "test" { |
| 37 | + param = "foobarbaz" |
| 38 | + separator = "pizza" |
| 39 | + }`, |
| 40 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 41 | + // verify input param is stored correctly |
| 42 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "param", "foobarbaz"), |
| 43 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "separator", "pizza"), |
| 44 | + // verify before, after, and found are stored correctly |
| 45 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "before", "foobarbaz"), |
| 46 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "after", ""), |
| 47 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "found", "false"), |
| 48 | + // verify id stored correctly |
| 49 | + resource.TestCheckResourceAttr("data.stdlib_cut.test", "id", "foobarbaz"), |
| 50 | + ), |
| 51 | + }, |
| 52 | + }, |
| 53 | + }) |
| 54 | +} |
0 commit comments