github.com/profects/terraform@v0.9.0-beta1.0.20170227135739-92d4809db30d/state/state_test.go (about)

     1  package state
     2  
     3  import (
     4  	"encoding/json"
     5  	"flag"
     6  	"io/ioutil"
     7  	"log"
     8  	"os"
     9  	"testing"
    10  
    11  	"github.com/hashicorp/terraform/helper/logging"
    12  )
    13  
    14  func TestMain(m *testing.M) {
    15  	flag.Parse()
    16  	if testing.Verbose() {
    17  		// if we're verbose, use the logging requested by TF_LOG
    18  		logging.SetOutput()
    19  	} else {
    20  		// otherwise silence all logs
    21  		log.SetOutput(ioutil.Discard)
    22  	}
    23  	os.Exit(m.Run())
    24  }
    25  
    26  func TestNewLockInfo(t *testing.T) {
    27  	info1 := NewLockInfo()
    28  	info2 := NewLockInfo()
    29  
    30  	if info1.ID == "" {
    31  		t.Fatal("LockInfo missing ID")
    32  	}
    33  
    34  	if info1.Version == "" {
    35  		t.Fatal("LockInfo missing version")
    36  	}
    37  
    38  	if info1.Created.IsZero() {
    39  		t.Fatal("LockInfo missing Created")
    40  	}
    41  
    42  	if info1.ID == info2.ID {
    43  		t.Fatal("multiple LockInfo with identical IDs")
    44  	}
    45  
    46  	// test the JSON output is valid
    47  	newInfo := &LockInfo{}
    48  	err := json.Unmarshal(info1.Marshal(), newInfo)
    49  	if err != nil {
    50  		t.Fatal(err)
    51  	}
    52  }