Skip to content

Replace magic strings with constants in hash_test.go for better maintainability #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changes/unreleased/improved_test_structure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: changed
body: Improved test structure by replacing magic strings with constants for better maintainability in hash_test.go
custom:
Issue: 826
11 changes: 8 additions & 3 deletions internal/helpers/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,29 @@ import (
func TestUnitCalculateSHA256(t *testing.T) {
t.Parallel()

const (
sameContent = "same"
differentContent = "different"
)

tdir := t.TempDir()
file1 := tdir + "/test.txt"
file2 := tdir + "/test2.txt"
file3 := tdir + "/test3.txt"
file4 := tdir + "/test4.txt"
file5 := tdir + "/test5"

err := os.WriteFile(file1, []byte("same"), 0644)
err := os.WriteFile(file1, []byte(sameContent), 0644)
if err != nil {
t.Fatal(err)
}

err = os.WriteFile(file2, []byte("same"), 0644)
err = os.WriteFile(file2, []byte(sameContent), 0644)
if err != nil {
t.Fatal(err)
}

err = os.WriteFile(file3, []byte("different"), 0644)
err = os.WriteFile(file3, []byte(differentContent), 0644)
if err != nil {
t.Fatal(err)
}
Expand Down