@@ -3,12 +3,9 @@ package mongodbflex_test
33import (
44 "context"
55 "fmt"
6- "net/http"
7- "regexp"
86 "strings"
97 "testing"
108
11- "github.com/google/uuid"
129 "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1310 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1411 "github.com/hashicorp/terraform-plugin-testing/terraform"
@@ -299,161 +296,6 @@ func TestAccMongoDBFlexFlexResource(t *testing.T) {
299296 })
300297}
301298
302- // slow test, delete has a 30s sleep...
303- func TestMongoDBInstanceSavesIDsOnError (t * testing.T ) {
304- var (
305- projectId = uuid .NewString ()
306- instanceId = uuid .NewString ()
307- )
308- const (
309- name = "instance-test"
310- region = "eu01"
311- )
312- s := testutil .NewMockServer (t )
313- defer s .Server .Close ()
314- tfConfig := fmt .Sprintf (`
315- provider "stackit" {
316- mongodbflex_custom_endpoint = "%s"
317- service_account_token = "mock-server-needs-no-auth"
318- }
319-
320- resource "stackit_mongodbflex_instance" "instance" {
321- project_id = "%s"
322- name = "%s"
323- options = {
324- type = "Replica"
325- snapshot_retention_days = 1
326- daily_snapshot_retention_days = 1
327- point_in_time_window_hours = 1
328- }
329- storage = {
330- class = "premium-perf2-mongodb"
331- size = 10
332- }
333- replicas = 1
334- acl = ["192.168.0.0/16"]
335- flavor = {
336- cpu =2
337- ram =4
338- }
339- version = "7.0"
340- backup_schedule = "00 6 * * *"
341- }
342- ` , s .Server .URL , projectId , name )
343-
344- resource .UnitTest (t , resource.TestCase {
345- ProtoV6ProviderFactories : testutil .TestAccProtoV6ProviderFactories ,
346- Steps : []resource.TestStep {
347- {
348- PreConfig : func () {
349- s .Reset (
350- testutil.MockResponse {
351- Description : "ListFlavors" ,
352- ToJsonBody : & mongodbflex.ListFlavorsResponse {Flavors : & []mongodbflex.InstanceFlavor {
353- {
354- Description : utils .Ptr ("flava-flav" ),
355- Cpu : utils .Ptr (int64 (2 )),
356- Id : utils .Ptr ("flavor-id" ),
357- Memory : utils .Ptr (int64 (4 )),
358- },
359- }},
360- },
361- testutil.MockResponse {
362- Description : "create instance" ,
363- ToJsonBody : & mongodbflex.CreateInstanceResponse {Id : utils .Ptr (instanceId )},
364- },
365- testutil.MockResponse {Description : "create waiter" , StatusCode : http .StatusInternalServerError },
366- )
367- },
368- Config : tfConfig ,
369- ExpectError : regexp .MustCompile ("Error creating instance.*" ),
370- },
371- {
372- PreConfig : func () {
373- s .Reset (
374- testutil.MockResponse {
375- Description : "refresh" ,
376- Handler : func (w http.ResponseWriter , req * http.Request ) {
377- expected := fmt .Sprintf ("/v2/projects/%s/regions/%s/instances/%s" , projectId , region , instanceId )
378- if req .URL .Path != expected {
379- t .Errorf ("expected request to %s, got %s" , expected , req .URL .Path )
380- }
381- w .WriteHeader (http .StatusInternalServerError )
382- },
383- },
384- testutil.MockResponse {Description : "delete" },
385- testutil.MockResponse {Description : "delete waiter" , StatusCode : http .StatusNotFound },
386- )
387- },
388- RefreshState : true ,
389- ExpectError : regexp .MustCompile ("Error reading instance.*" ),
390- },
391- },
392- })
393- }
394-
395- func TestMongoDBUserSavesIDsOnError (t * testing.T ) {
396- projectId := uuid .NewString ()
397- instanceId := uuid .NewString ()
398- userId := uuid .NewString ()
399- const region = "eu01"
400- s := testutil .NewMockServer (t )
401- defer s .Server .Close ()
402- tfConfig := fmt .Sprintf (`
403- provider "stackit" {
404- mongodbflex_custom_endpoint = "%s"
405- service_account_token = "mock-server-needs-no-auth"
406- }
407-
408- resource "stackit_mongodbflex_user" "user" {
409- project_id = "%s"
410- instance_id = "%s"
411- username = "username"
412- roles = ["read"]
413- database = "db-name"
414- }
415- ` , s .Server .URL , projectId , instanceId )
416-
417- resource .UnitTest (t , resource.TestCase {
418- ProtoV6ProviderFactories : testutil .TestAccProtoV6ProviderFactories ,
419- Steps : []resource.TestStep {
420- {
421- PreConfig : func () {
422- s .Reset (
423- testutil.MockResponse {
424- Description : "create user" ,
425- ToJsonBody : & mongodbflex.CreateUserResponse {Item : & mongodbflex.User {Id : utils .Ptr (userId )}},
426- },
427- testutil.MockResponse {Description : "failing waiter" , StatusCode : http .StatusInternalServerError },
428- )
429- },
430- Config : tfConfig ,
431- ExpectError : regexp .MustCompile ("Error creating user.*" ),
432- },
433- {
434- PreConfig : func () {
435- s .Reset (
436- testutil.MockResponse {
437- Description : "refresh user" ,
438- Handler : func (w http.ResponseWriter , req * http.Request ) {
439- expected := fmt .Sprintf ("/v2/projects/%s/regions/%s/instances/%s/users/%s" , projectId , region , instanceId , userId )
440- if req .URL .Path != expected {
441- t .Errorf ("expected request to %s, got %s" , expected , req .URL .Path )
442- }
443- w .WriteHeader (http .StatusInternalServerError )
444- },
445- },
446- testutil.MockResponse {Description : "delete user" },
447- testutil.MockResponse {Description : "delete user waiter" , StatusCode : http .StatusNotFound },
448- )
449- },
450- RefreshState : true ,
451- ExpectError : regexp .MustCompile ("Error reading user.*" ),
452- },
453- },
454- })
455- }
456-
457299func testAccCheckMongoDBFlexDestroy (s * terraform.State ) error {
458300 ctx := context .Background ()
459301 var client * mongodbflex.APIClient
0 commit comments