github.com/kcburge/terraform@v0.11.12-beta1/backend/legacy/backend_test.go (about)

     1  package legacy
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/hashicorp/terraform/backend"
    10  	"github.com/hashicorp/terraform/config"
    11  	"github.com/hashicorp/terraform/state"
    12  	"github.com/hashicorp/terraform/terraform"
    13  )
    14  
    15  func TestBackend_impl(t *testing.T) {
    16  	var _ backend.Backend = new(Backend)
    17  }
    18  
    19  func TestBackend(t *testing.T) {
    20  	td, err := ioutil.TempDir("", "tf")
    21  	if err != nil {
    22  		t.Fatalf("err: %s", err)
    23  	}
    24  	defer os.RemoveAll(td)
    25  
    26  	b := &Backend{Type: "local"}
    27  	conf := terraform.NewResourceConfig(config.TestRawConfig(t, map[string]interface{}{
    28  		"path": filepath.Join(td, "data"),
    29  	}))
    30  
    31  	// Config
    32  	if err := b.Configure(conf); err != nil {
    33  		t.Fatalf("err: %s", err)
    34  	}
    35  
    36  	// Grab state
    37  	s, err := b.State(backend.DefaultStateName)
    38  	if err != nil {
    39  		t.Fatalf("err: %s", err)
    40  	}
    41  	if s == nil {
    42  		t.Fatalf("state is nil")
    43  	}
    44  
    45  	// Test it
    46  	s.WriteState(state.TestStateInitial())
    47  	s.PersistState()
    48  	state.TestState(t, s)
    49  }