-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the Enterprise enhanced remote backend
- Loading branch information
Sander van Harmelen
committed
Aug 3, 2018
1 parent
eada447
commit 1a67f7f
Showing
37 changed files
with
2,341 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package init | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
|
||
backendLocal "github.com/hashicorp/terraform/backend/local" | ||
) | ||
|
||
func TestInit_backend(t *testing.T) { | ||
// Initialize the backends map | ||
Init(nil) | ||
|
||
backends := []struct { | ||
Name string | ||
Type string | ||
}{ | ||
{ | ||
"local", | ||
"*local.Local", | ||
}, { | ||
"remote", | ||
"*remote.Remote", | ||
}, { | ||
"atlas", | ||
"*atlas.Backend", | ||
}, { | ||
"azurerm", | ||
"*azure.Backend", | ||
}, { | ||
"consul", | ||
"*consul.Backend", | ||
}, { | ||
"etcdv3", | ||
"*etcd.Backend", | ||
}, { | ||
"gcs", | ||
"*gcs.Backend", | ||
}, { | ||
"inmem", | ||
"*inmem.Backend", | ||
}, { | ||
"manta", | ||
"*manta.Backend", | ||
}, { | ||
"s3", | ||
"*s3.Backend", | ||
}, { | ||
"swift", | ||
"*swift.Backend", | ||
}, { | ||
"azure", | ||
"init.deprecatedBackendShim", | ||
}, | ||
} | ||
|
||
// Make sure we get the requested backend | ||
for _, b := range backends { | ||
f := Backend(b.Name) | ||
bType := reflect.TypeOf(f()).String() | ||
|
||
if bType != b.Type { | ||
t.Fatalf("expected backend %q to be %q, got: %q", b.Name, b.Type, bType) | ||
} | ||
} | ||
} | ||
|
||
func TestInit_forceLocalBackend(t *testing.T) { | ||
// Initialize the backends map | ||
Init(nil) | ||
|
||
enhancedBackends := []struct { | ||
Name string | ||
Type string | ||
}{ | ||
{ | ||
"local", | ||
"nil", | ||
}, { | ||
"remote", | ||
"*remote.Remote", | ||
}, | ||
} | ||
|
||
// Set the TF_FORCE_LOCAL_BACKEND flag so all enhanced backends will | ||
// return a local.Local backend with themselves as embedded backend. | ||
if err := os.Setenv("TF_FORCE_LOCAL_BACKEND", "1"); err != nil { | ||
t.Fatalf("error setting environment variable TF_FORCE_LOCAL_BACKEND: %v", err) | ||
} | ||
|
||
// Make sure we always get the local backend. | ||
for _, b := range enhancedBackends { | ||
f := Backend(b.Name) | ||
|
||
local, ok := f().(*backendLocal.Local) | ||
if !ok { | ||
t.Fatalf("expected backend %q to be \"*local.Local\", got: %T", b.Name, f()) | ||
} | ||
|
||
bType := "nil" | ||
if local.Backend != nil { | ||
bType = reflect.TypeOf(local.Backend).String() | ||
} | ||
|
||
if bType != b.Type { | ||
t.Fatalf("expected local.Backend to be %s, got: %s", b.Type, bType) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.