|
| 1 | +package streamconnection_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 10 | + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" |
| 11 | +) |
| 12 | + |
| 13 | +func TestAccStreamDSStreamConnection_kafkaPlaintext(t *testing.T) { |
| 14 | + var ( |
| 15 | + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") |
| 16 | + projectName = acctest.RandomWithPrefix("test-acc-stream") |
| 17 | + instanceName = acctest.RandomWithPrefix("test-acc-instance") |
| 18 | + dataSourceName = "data.mongodbatlas_stream_connection.test" |
| 19 | + ) |
| 20 | + resource.ParallelTest(t, resource.TestCase{ |
| 21 | + PreCheck: func() { acc.PreCheckBetaFlag(t); acc.PreCheckBasic(t) }, |
| 22 | + ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, |
| 23 | + CheckDestroy: CheckDestroyStreamConnection, |
| 24 | + Steps: []resource.TestStep{ |
| 25 | + { |
| 26 | + Config: streamConnectionDataSourceConfig(kafkaStreamConnectionConfig(orgID, projectName, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", false)), |
| 27 | + Check: kafkaStreamConnectionAttributeChecks(dataSourceName, orgID, projectName, instanceName, "user", "rawpassword", "localhost:9092,localhost:9092", "earliest", false, false), |
| 28 | + }, |
| 29 | + }, |
| 30 | + }) |
| 31 | +} |
| 32 | + |
| 33 | +func TestAccStreamDSStreamConnection_kafkaSSL(t *testing.T) { |
| 34 | + var ( |
| 35 | + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") |
| 36 | + projectName = acctest.RandomWithPrefix("test-acc-stream") |
| 37 | + instanceName = acctest.RandomWithPrefix("test-acc-instance") |
| 38 | + dataSourceName = "data.mongodbatlas_stream_connection.test" |
| 39 | + ) |
| 40 | + resource.ParallelTest(t, resource.TestCase{ |
| 41 | + PreCheck: func() { acc.PreCheckBetaFlag(t); acc.PreCheckBasic(t) }, |
| 42 | + ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, |
| 43 | + CheckDestroy: CheckDestroyStreamConnection, |
| 44 | + Steps: []resource.TestStep{ |
| 45 | + { |
| 46 | + Config: streamConnectionDataSourceConfig(kafkaStreamConnectionConfig(orgID, projectName, instanceName, "user", "rawpassword", "localhost:9092", "earliest", true)), |
| 47 | + Check: kafkaStreamConnectionAttributeChecks(dataSourceName, orgID, projectName, instanceName, "user", "rawpassword", "localhost:9092", "earliest", true, false), |
| 48 | + }, |
| 49 | + }, |
| 50 | + }) |
| 51 | +} |
| 52 | + |
| 53 | +func TestAccStreamDSStreamConnection_cluster(t *testing.T) { |
| 54 | + var ( |
| 55 | + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") |
| 56 | + clusterInfo = acc.GetClusterInfo(orgID) |
| 57 | + instanceName = acctest.RandomWithPrefix("test-acc-name") |
| 58 | + dataSourceName = "data.mongodbatlas_stream_connection.test" |
| 59 | + ) |
| 60 | + resource.ParallelTest(t, resource.TestCase{ |
| 61 | + PreCheck: func() { acc.PreCheckBetaFlag(t); acc.PreCheckBasic(t) }, |
| 62 | + ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, |
| 63 | + CheckDestroy: CheckDestroyStreamConnection, |
| 64 | + Steps: []resource.TestStep{ |
| 65 | + { |
| 66 | + Config: streamConnectionDataSourceConfig(clusterStreamConnectionConfig(clusterInfo.ProjectIDStr, instanceName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr)), |
| 67 | + Check: clusterStreamConnectionAttributeChecks(dataSourceName, clusterInfo.ClusterName), |
| 68 | + }, |
| 69 | + }, |
| 70 | + }) |
| 71 | +} |
| 72 | + |
| 73 | +func streamConnectionDataSourceConfig(streamConnectionConfig string) string { |
| 74 | + return fmt.Sprintf(` |
| 75 | + %s |
| 76 | +
|
| 77 | + data "mongodbatlas_stream_connection" "test" { |
| 78 | + project_id = mongodbatlas_stream_connection.test.project_id |
| 79 | + instance_name = mongodbatlas_stream_connection.test.instance_name |
| 80 | + connection_name = mongodbatlas_stream_connection.test.connection_name |
| 81 | + } |
| 82 | + `, streamConnectionConfig) |
| 83 | +} |
0 commit comments