From 3f7ec27430a4d6465288a435f1cbe9f65cde759a Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Mon, 26 Sep 2022 17:38:39 -0700 Subject: [PATCH] Try removing our directory manually. Signed-off-by: Ville Aikas --- client/client_test.go | 12 +++++++++++- client/file_store.go | 1 - client/file_store_test.go | 5 +++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 87665c96..a848d104 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -38,6 +38,8 @@ type ClientSuite struct { expiredTime time.Time keyIDs map[string][]string useFileStore bool + // Only used with FileStore + tmpDir string } var _ = Suite(&ClientSuite{useFileStore: false}) @@ -181,7 +183,7 @@ func (s *ClientSuite) SetUpTest(c *C) { // create a remote store containing valid repo files if s.useFileStore { - s.remote, err = newTestFileStore() + s.remote, s.tmpDir, err = newTestFileStore() if err != nil { c.Fatalf("failed to create new FileStore: %v", err) } @@ -196,6 +198,14 @@ func (s *ClientSuite) SetUpTest(c *C) { s.expiredTime = time.Now().Add(time.Hour) } +func (s *ClientSuite) TearDownTest(c *C) { + if s.tmpDir != "" { + // Just ignore the errors, we're done anyways, and this can cause + // grief in windows. + os.RemoveAll(s.tmpDir) + } +} + func (s *ClientSuite) genKey(c *C, role string) []string { ids, err := s.repo.GenKey(role) c.Assert(err, IsNil) diff --git a/client/file_store.go b/client/file_store.go index d5bdff5f..78d87871 100644 --- a/client/file_store.go +++ b/client/file_store.go @@ -20,7 +20,6 @@ type FileStoreOptions struct { // is useful for example in air-gapped environments where there's no // possibility to make outbound network connections. // If targetsDir is "", metadataDir/targets is used. -// func NewFileRemoteStore(metadataDir, targetsDir string) (RemoteStore, error) { func NewFileRemoteStore(metadataDir, targetsDir string) (*FileRemoteStore, error) { if metadataDir == "" { return nil, errors.New("metadataDir can't be empty") diff --git a/client/file_store_test.go b/client/file_store_test.go index 01bd0e0c..91dc17ac 100644 --- a/client/file_store_test.go +++ b/client/file_store_test.go @@ -91,12 +91,13 @@ func (f *FileRemoteStore) deleteTarget(name string) error { return os.Remove(filepath.Join(f.targetsDir, name)) } -func newTestFileStore() (*FileRemoteStore, error) { +func newTestFileStore() (*FileRemoteStore, string, error) { tmpDir := os.TempDir() tufDir := filepath.Join(tmpDir, "tuf-file-store-test") // Clean it in case there is cruft left around os.RemoveAll(tufDir) os.Mkdir(tufDir, os.ModePerm) os.Mkdir(filepath.Join(tufDir, "targets"), os.ModePerm) - return NewFileRemoteStore(tufDir, "") + fs, err := NewFileRemoteStore(tufDir, "") + return fs, tufDir, err }