github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/backend/init/init_test.go (about)

     1  package init
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestInit_backend(t *testing.T) {
     9  	// Initialize the backends map
    10  	Init(nil)
    11  
    12  	backends := []struct {
    13  		Name string
    14  		Type string
    15  	}{
    16  		{"local", "*local.Local"},
    17  		{"remote", "*remote.Remote"},
    18  		{"atlas", "*atlas.Backend"},
    19  		{"azurerm", "*azure.Backend"},
    20  		{"consul", "*consul.Backend"},
    21  		{"cos", "*cos.Backend"},
    22  		{"etcdv3", "*etcd.Backend"},
    23  		{"gcs", "*gcs.Backend"},
    24  		{"inmem", "*inmem.Backend"},
    25  		{"manta", "*manta.Backend"},
    26  		{"pg", "*pg.Backend"},
    27  		{"s3", "*s3.Backend"},
    28  		{"swift", "*swift.Backend"},
    29  		{"azure", "init.deprecatedBackendShim"},
    30  	}
    31  
    32  	// Make sure we get the requested backend
    33  	for _, b := range backends {
    34  		t.Run(b.Name, func(t *testing.T) {
    35  			f := Backend(b.Name)
    36  			if f == nil {
    37  				t.Fatalf("backend %q is not present; should be", b.Name)
    38  			}
    39  			bType := reflect.TypeOf(f()).String()
    40  			if bType != b.Type {
    41  				t.Fatalf("expected backend %q to be %q, got: %q", b.Name, b.Type, bType)
    42  			}
    43  		})
    44  	}
    45  }