command: remove unused method on pluginSHA256LockFile (#26402)
* tmp is haunted * remove unused code
This commit is contained in:
parent
85e83608fc
commit
fc94c819e5
|
@ -22,11 +22,15 @@ func TestFmt(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "terraform-fmt-test")
|
||||
td, err := ioutil.TempDir("", "terraform-fmt-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
tmpDir, err := filepath.EvalSymlinks(td)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(td)
|
||||
|
||||
for _, info := range entries {
|
||||
if info.IsDir() {
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
|
@ -62,25 +61,3 @@ func (pf *pluginSHA256LockFile) Read() map[string][]byte {
|
|||
|
||||
return digests
|
||||
}
|
||||
|
||||
// Write persists lock information to disk, where it will be retrieved by
|
||||
// future calls to Read. This entirely replaces any previous lock information,
|
||||
// so the given map must be comprehensive.
|
||||
func (pf *pluginSHA256LockFile) Write(digests map[string][]byte) error {
|
||||
strDigests := map[string]string{}
|
||||
for name, digest := range digests {
|
||||
strDigests[name] = fmt.Sprintf("%x", digest)
|
||||
}
|
||||
|
||||
buf, err := json.MarshalIndent(strDigests, "", " ")
|
||||
if err != nil {
|
||||
// should never happen
|
||||
return fmt.Errorf("failed to serialize plugin lock as JSON: %s", err)
|
||||
}
|
||||
|
||||
os.MkdirAll(
|
||||
filepath.Dir(pf.Filename), os.ModePerm,
|
||||
) // ignore error since WriteFile below will generate a better one anyway
|
||||
|
||||
return ioutil.WriteFile(pf.Filename, buf, os.ModePerm)
|
||||
}
|
||||
|
|
|
@ -2,18 +2,18 @@ package command
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPluginSHA256LockFile(t *testing.T) {
|
||||
func TestPluginSHA256LockFile_Read(t *testing.T) {
|
||||
f, err := ioutil.TempFile(testingDir, "tf-pluginsha1lockfile-test-")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temporary file: %s", err)
|
||||
}
|
||||
f.Close()
|
||||
//defer os.Remove(f.Name())
|
||||
t.Logf("working in %s", f.Name())
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
plf := &pluginSHA256LockFile{
|
||||
Filename: f.Name(),
|
||||
|
@ -24,17 +24,4 @@ func TestPluginSHA256LockFile(t *testing.T) {
|
|||
if !reflect.DeepEqual(digests, map[string][]byte{}) {
|
||||
t.Errorf("wrong initial content %#v; want empty map", digests)
|
||||
}
|
||||
|
||||
digests = map[string][]byte{
|
||||
"test": []byte("hello world"),
|
||||
}
|
||||
err = plf.Write(digests)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to write lock file: %s", err)
|
||||
}
|
||||
|
||||
got := plf.Read()
|
||||
if !reflect.DeepEqual(got, digests) {
|
||||
t.Errorf("wrong content %#v after write; want %#v", got, digests)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue