Skip to content

Commit

Permalink
fixed the too less calls in lock.Download go included a missing boole…
Browse files Browse the repository at this point in the history
…an value for the lock.Download call.
  • Loading branch information
777Denoiser committed Dec 5, 2024
1 parent 25dae22 commit 375f243
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cmd/dowload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ func TestRunDownloadFailsIntegrityTest(t *testing.T) {

func TestOptimization(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("test content"))
_, err := w.Write([]byte("test content"))
if err != nil {
return
}
}))
defer ts.Close()

Expand All @@ -147,37 +150,36 @@ func TestOptimization(t *testing.T) {
err = lock.AddResource([]string{testUrl}, internal.RecommendedAlgo, nil, "valid_test.txt")
require.NoError(t, err)

err = lock.Download(tmpDir, nil, nil, "")
// Update the Download call to match the new signature
err = lock.Download(tmpDir, nil, nil, "", false) // Added 'false' for the new boolean argument
require.NoError(t, err)
})

t.Run("Invalid_File_Redownloaded", func(t *testing.T) {
tmpDir := test.TmpDir(t)
testUrl := ts.URL + "/invalid_test.txt"

// Create lock file with specific integrity
lockPath := test.TmpFile(t, "")
lock, err := internal.NewLock(lockPath, true)
require.NoError(t, err)

err = lock.AddResource([]string{testUrl}, internal.RecommendedAlgo, nil, "invalid_test.txt")
require.NoError(t, err)

// Save lock file
err = lock.Save()
require.NoError(t, err)

// Create invalid file
invalidPath := filepath.Join(tmpDir, "invalid_test.txt")
err = os.WriteFile(invalidPath, []byte("corrupted"), 0644)
require.NoError(t, err)

// Try downloading - should fail with integrity mismatch
err = lock.Download(tmpDir, nil, nil, "")
// Update the Download call to match the new signature
err = lock.Download(tmpDir, nil, nil, "", false) // Added 'false' for the new boolean argument
require.Error(t, err)
assert.Contains(t, err.Error(), "integrity mismatch")
})
}

func TestRunDownloadTriesAllUrls(t *testing.T) {
content := `abcdef`
contentIntegrity := getSha256Integrity(content)
Expand Down

0 comments on commit 375f243

Please sign in to comment.