Skip to content

Commit

Permalink
comments 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 Apr 9, 2024
1 parent ee21635 commit 5441dbb
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions asset/boltdb_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,40 +219,12 @@ func TestFailedExpand(t *testing.T) {
t.Log("expected error, got nil")
t.Fail()
}

// Create a temporary directory for testing
//if -- dbName == "" true
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) {
t.Parallel()

tmpFile, err := ioutil.TempFile(os.TempDir(), "asset_test_get_invalid_asset.db")
tmpDir := os.TempDir()
tmpFile, err := ioutil.TempFile(tmpDir, "asset_test_get_invalid_asset.db")
if err != nil {
t.Fatalf("unable to create test boltdb file: %v", err)
}
Expand Down Expand Up @@ -281,6 +253,21 @@ func TestSuccessfulGetAsset(t *testing.T) {
URL: "path",
}

tempAssetFile, err := os.CreateTemp(tmpDir, "asset.db")
if err != nil {
t.Logf("error creating the asset file as %v", err)
}
fi, err := tempAssetFile.Stat()

Check failure on line 260 in asset/boltdb_manager_test.go

View workflow job for this annotation

GitHub Actions / staticcheck (project)

this value of err is never used (SA4006)
if fi.Size() == 0 {
t.Log("asset.db got created corruptly")
err = os.RemoveAll(filepath.Join(tmpDir, a.Sha512))
if err != nil {
t.Logf("issue in deleting the assetSHA due to %v", err)
} else {
t.Log("assetSHA got deleted successfully and now asset will be properly downloaded.")
}
}

runtimeAsset, err := manager.Get(context.TODO(), a)
if err != nil {
t.Logf("expected no error, got: %v", err)
Expand Down

0 comments on commit 5441dbb

Please sign in to comment.