|
| 1 | +package kubernetes |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 9 | +) |
| 10 | + |
| 11 | +// TestAccKubernetesDataSourceConfigMap_basic tests that the data source is able to read |
| 12 | +// plaintext data, binary data, annotation, label, and name of the config map resource. |
| 13 | +func TestAccKubernetesDataSourceConfigMap_basic(t *testing.T) { |
| 14 | + name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) |
| 15 | + |
| 16 | + resource.Test(t, resource.TestCase{ |
| 17 | + PreCheck: func() { testAccPreCheck(t) }, |
| 18 | + Providers: testAccProviders, |
| 19 | + Steps: []resource.TestStep{ |
| 20 | + { |
| 21 | + Config: testAccKubernetesDataSourceConfigMapConfig_basic(name), |
| 22 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 23 | + resource.TestCheckResourceAttr("data.kubernetes_config_map.test", "metadata.0.name", name), |
| 24 | + resource.TestCheckResourceAttr("data.kubernetes_config_map.test", "metadata.0.annotations.TestAnnotationOne", "one"), |
| 25 | + resource.TestCheckResourceAttr("data.kubernetes_config_map.test", "metadata.0.labels.TestLabelOne", "one"), |
| 26 | + resource.TestCheckResourceAttr("data.kubernetes_config_map.test", "data.one", "first"), |
| 27 | + resource.TestCheckResourceAttr("data.kubernetes_config_map.test", "binary_data.raw", "UmF3IGRhdGEgc2hvdWxkIGNvbWUgYmFjayBhcyBpcyBpbiB0aGUgcG9k"), |
| 28 | + ), |
| 29 | + }, |
| 30 | + }, |
| 31 | + }) |
| 32 | +} |
| 33 | + |
| 34 | +// testAccKubernetesDataSourceConfigMapConfig_basic provides the terraform config |
| 35 | +// used to test basic functionality of the config_map data source. |
| 36 | +func testAccKubernetesDataSourceConfigMapConfig_basic(name string) string { |
| 37 | + return fmt.Sprintf(` |
| 38 | +resource "kubernetes_config_map" "test" { |
| 39 | + metadata { |
| 40 | + annotations = { |
| 41 | + TestAnnotationOne = "one" |
| 42 | + } |
| 43 | +
|
| 44 | + labels = { |
| 45 | + TestLabelOne = "one" |
| 46 | + } |
| 47 | +
|
| 48 | + name = "%s" |
| 49 | + } |
| 50 | +
|
| 51 | + data = { |
| 52 | + one = "first" |
| 53 | + } |
| 54 | +
|
| 55 | + binary_data = { |
| 56 | + raw = "${base64encode("Raw data should come back as is in the pod")}" |
| 57 | + } |
| 58 | +} |
| 59 | +
|
| 60 | +data "kubernetes_config_map" "test" { |
| 61 | + metadata { |
| 62 | + name = "${kubernetes_config_map.test.metadata.0.name}" |
| 63 | + } |
| 64 | + }`, name) |
| 65 | +} |
0 commit comments