Skip to content

Commit

Permalink
Try removing our directory manually.
Browse files Browse the repository at this point in the history
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
  • Loading branch information
vaikas committed Sep 27, 2022
1 parent a5c24e4 commit 3f7ec27
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion client/file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions client/file_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3f7ec27

Please sign in to comment.