github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/backend/remote-state/swift/backend_test.go (about) 1 package swift 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 "time" 8 9 "github.com/hashicorp/terraform/backend" 10 ) 11 12 // verify that we are doing ACC tests or the Swift tests specifically 13 func testACC(t *testing.T) { 14 skip := os.Getenv("TF_ACC") == "" && os.Getenv("TF_SWIFT_TEST") == "" 15 if skip { 16 t.Log("swift backend tests require setting TF_ACC or TF_SWIFT_TEST") 17 t.Skip() 18 } 19 t.Log("swift backend acceptance tests enabled") 20 } 21 22 func TestBackend_impl(t *testing.T) { 23 var _ backend.Backend = new(Backend) 24 } 25 26 func testAccPreCheck(t *testing.T) { 27 v := os.Getenv("OS_AUTH_URL") 28 if v == "" { 29 t.Fatal("OS_AUTH_URL must be set for acceptance tests") 30 } 31 } 32 33 func TestBackendConfig(t *testing.T) { 34 testACC(t) 35 36 // Build config 37 container := fmt.Sprintf("terraform-state-swift-testconfig-%x", time.Now().Unix()) 38 archiveContainer := fmt.Sprintf("%s_archive", container) 39 40 config := map[string]interface{}{ 41 "archive_container": archiveContainer, 42 "container": container, 43 } 44 45 b := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(config)).(*Backend) 46 47 if b.container != container { 48 t.Fatal("Incorrect container was provided.") 49 } 50 if b.archiveContainer != archiveContainer { 51 t.Fatal("Incorrect archive_container was provided.") 52 } 53 } 54 55 func TestBackend(t *testing.T) { 56 testACC(t) 57 58 container := fmt.Sprintf("terraform-state-swift-testbackend-%x", time.Now().Unix()) 59 60 be0 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ 61 "container": container, 62 })).(*Backend) 63 64 be1 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ 65 "container": container, 66 })).(*Backend) 67 68 client := &RemoteClient{ 69 client: be0.client, 70 container: be0.container, 71 } 72 73 defer client.deleteContainer() 74 75 backend.TestBackendStates(t, be0) 76 backend.TestBackendStateLocks(t, be0, be1) 77 backend.TestBackendStateForceUnlock(t, be0, be1) 78 } 79 80 func TestBackendArchive(t *testing.T) { 81 testACC(t) 82 83 container := fmt.Sprintf("terraform-state-swift-testarchive-%x", time.Now().Unix()) 84 archiveContainer := fmt.Sprintf("%s_archive", container) 85 86 be0 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ 87 "archive_container": archiveContainer, 88 "container": container, 89 })).(*Backend) 90 91 be1 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ 92 "archive_container": archiveContainer, 93 "container": container, 94 })).(*Backend) 95 96 defer func() { 97 client := &RemoteClient{ 98 client: be0.client, 99 container: be0.container, 100 } 101 102 aclient := &RemoteClient{ 103 client: be0.client, 104 container: be0.archiveContainer, 105 } 106 107 defer client.deleteContainer() 108 client.deleteContainer() 109 aclient.deleteContainer() 110 }() 111 112 backend.TestBackendStates(t, be0) 113 backend.TestBackendStateLocks(t, be0, be1) 114 backend.TestBackendStateForceUnlock(t, be0, be1) 115 }