command: remove unused method on pluginSHA256LockFile (#26402)

* tmp is haunted
* remove unused code
This commit is contained in:
Kristin Laemmert 2020-09-29 08:46:51 -04:00 committed by GitHub
parent 85e83608fc
commit fc94c819e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 41 deletions

View File

@ -22,11 +22,15 @@ func TestFmt(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
tmpDir, err := ioutil.TempDir("", "terraform-fmt-test") td, err := ioutil.TempDir("", "terraform-fmt-test")
if err != nil { if err != nil {
t.Fatal(err) 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 { for _, info := range entries {
if info.IsDir() { if info.IsDir() {

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"path/filepath" "path/filepath"
) )
@ -62,25 +61,3 @@ func (pf *pluginSHA256LockFile) Read() map[string][]byte {
return digests 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)
}

View File

@ -2,18 +2,18 @@ package command
import ( import (
"io/ioutil" "io/ioutil"
"os"
"reflect" "reflect"
"testing" "testing"
) )
func TestPluginSHA256LockFile(t *testing.T) { func TestPluginSHA256LockFile_Read(t *testing.T) {
f, err := ioutil.TempFile(testingDir, "tf-pluginsha1lockfile-test-") f, err := ioutil.TempFile(testingDir, "tf-pluginsha1lockfile-test-")
if err != nil { if err != nil {
t.Fatalf("failed to create temporary file: %s", err) t.Fatalf("failed to create temporary file: %s", err)
} }
f.Close() f.Close()
//defer os.Remove(f.Name()) defer os.Remove(f.Name())
t.Logf("working in %s", f.Name())
plf := &pluginSHA256LockFile{ plf := &pluginSHA256LockFile{
Filename: f.Name(), Filename: f.Name(),
@ -24,17 +24,4 @@ func TestPluginSHA256LockFile(t *testing.T) {
if !reflect.DeepEqual(digests, map[string][]byte{}) { if !reflect.DeepEqual(digests, map[string][]byte{}) {
t.Errorf("wrong initial content %#v; want empty map", digests) 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)
}
} }