Skip to content

Commit

Permalink
resolved
Browse files Browse the repository at this point in the history
Signed-off-by: SudhanshuBawane <sudhanshu.bawane.ctr@sumologic.com>
  • Loading branch information
SudhanshuBawane committed Mar 19, 2024
1 parent 001844f commit 357ac9f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 35 deletions.
2 changes: 1 addition & 1 deletion asset/boltdb_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (b *boltDBAssetManager) expandWithDuration(tmpFile *os.File, asset *corev2.
CacheDir := viper.GetString(FlagCacheDir)
fullPath := filepath.Join(CacheDir, assetSHA)

if err := CleanUp(fullPath); err != nil {
if err := os.RemoveAll(fullPath); err != nil {
logger.WithField("assetSHA path", fullPath).WithError(err).
Error("error cleaning up the assetSHA")
}
Expand Down
28 changes: 28 additions & 0 deletions asset/boltdb_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"

bolt "go.etcd.io/bbolt"
Expand Down Expand Up @@ -218,6 +219,33 @@ func TestFailedExpand(t *testing.T) {
t.Log("expected error, got nil")
t.Fail()
}

// Create a temporary directory for testing
tmpDir := t.TempDir()

// Define the SHA and file name
SHAName := "shaAsset.tar"
SHAFilePath := filepath.Join(tmpDir, SHAName)

// Create a dummy file inside the temporary directory
SHAFile, err := os.Create(SHAFilePath)
if err != nil {
t.Fatalf("Failed to create dummy file: %v", err)
}
SHAFile.Close()

// Call CleanUp with the SHA of the dummy file and the temporary directory
err = os.RemoveAll(SHAFilePath)
if err != nil {
t.Errorf("CleanUp returned an error: %v", err)
t.Fail()
}

_, err = os.Stat(SHAFilePath)
if !os.IsNotExist(err) {
t.Errorf("CleanUp did not remove the dummy file as expected")
t.Fail()
}
}

func TestSuccessfulGetAsset(t *testing.T) {
Expand Down
10 changes: 4 additions & 6 deletions asset/expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package asset
import (
"errors"
"fmt"
"io"
"os"

archiver "github.com/mholt/archiver/v3"
"io"

filetype "gopkg.in/h2non/filetype.v1"
filetype_types "gopkg.in/h2non/filetype.v1/types"
Expand Down Expand Up @@ -93,6 +91,6 @@ func sniffType(f io.ReadSeeker) (filetype_types.Type, error) {
}

// cleanup of the assetSHA when cache dir gets force deleted
func CleanUp(fullPath string) error {
return os.RemoveAll(fullPath)
}
//func CleanUp(fullPath string) error {
// return os.RemoveAll(fullPath)
//}
56 changes: 28 additions & 28 deletions asset/expander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,31 +115,31 @@ func TestExpandInvalidArchive(t *testing.T) {
}

// ---Test to check CleanUp
func TestCleanUp(t *testing.T) {
t.Parallel()

// Create a temporary directory for testing
tmpDir := t.TempDir()

// Define the SHA and file name
SHAName := "shaAsset.tar"
SHAFilePath := filepath.Join(tmpDir, SHAName)

// Create a dummy file inside the temporary directory
SHAFile, err := os.Create(SHAFilePath)
if err != nil {
t.Fatalf("Failed to create dummy file: %v", err)
}
SHAFile.Close()

// Call CleanUp with the SHA of the dummy file and the temporary directory
err = CleanUp(SHAFilePath)
if err != nil {
t.Errorf("CleanUp returned an error: %v", err)
}

_, err = os.Stat(SHAFilePath)
if !os.IsNotExist(err) {
t.Errorf("CleanUp did not remove the dummy file as expected")
}
}
//func TestCleanUp(t *testing.T) {
// t.Parallel()
//
// // Create a temporary directory for testing
// tmpDir := t.TempDir()
//
// // Define the SHA and file name
// SHAName := "shaAsset.tar"
// SHAFilePath := filepath.Join(tmpDir, SHAName)
//
// // Create a dummy file inside the temporary directory
// SHAFile, err := os.Create(SHAFilePath)
// if err != nil {
// t.Fatalf("Failed to create dummy file: %v", err)
// }
// SHAFile.Close()
//
// // Call CleanUp with the SHA of the dummy file and the temporary directory
// err = CleanUp(SHAFilePath)
// if err != nil {
// t.Errorf("CleanUp returned an error: %v", err)
// }
//
// _, err = os.Stat(SHAFilePath)
// if !os.IsNotExist(err) {
// t.Errorf("CleanUp did not remove the dummy file as expected")
// }
//}

0 comments on commit 357ac9f

Please sign in to comment.