github.com/d-luu/terraform@v0.11.12-beta1/command/plugins_lock_test.go (about)

     1  package command
     2  
     3  import (
     4  	"io/ioutil"
     5  	"reflect"
     6  	"testing"
     7  )
     8  
     9  func TestPluginSHA256LockFile(t *testing.T) {
    10  	f, err := ioutil.TempFile(testingDir, "tf-pluginsha1lockfile-test-")
    11  	if err != nil {
    12  		t.Fatalf("failed to create temporary file: %s", err)
    13  	}
    14  	f.Close()
    15  	//defer os.Remove(f.Name())
    16  	t.Logf("working in %s", f.Name())
    17  
    18  	plf := &pluginSHA256LockFile{
    19  		Filename: f.Name(),
    20  	}
    21  
    22  	// Initially the file is invalid, so we should get an empty map.
    23  	digests := plf.Read()
    24  	if !reflect.DeepEqual(digests, map[string][]byte{}) {
    25  		t.Errorf("wrong initial content %#v; want empty map", digests)
    26  	}
    27  
    28  	digests = map[string][]byte{
    29  		"test": []byte("hello world"),
    30  	}
    31  	err = plf.Write(digests)
    32  	if err != nil {
    33  		t.Fatalf("failed to write lock file: %s", err)
    34  	}
    35  
    36  	got := plf.Read()
    37  	if !reflect.DeepEqual(got, digests) {
    38  		t.Errorf("wrong content %#v after write; want %#v", got, digests)
    39  	}
    40  }