Skip to content
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

Implement minSize/maxSize thresholds. #58

Merged
merged 7 commits into from
Feb 4, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor tests.
thushan committed Feb 4, 2024
commit 9d2a33fde5462f0d006a142dcdb50fadf01dd463
146 changes: 75 additions & 71 deletions pkg/slicer/slicer_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint

Check failure on line 1 in pkg/slicer/slicer_test.go

GitHub Actions / golangci

directive `// nolint` should be written without leading space as `//nolint` (nolintlint)
package slicer

import (
@@ -7,7 +7,6 @@
"encoding/hex"
"github.com/thushan/smash/internal/algorithms"
"io"
"io/fs"
"os"
"reflect"
"strings"
@@ -232,87 +231,92 @@
})
}
}
func TestSliceFS_New_FileSystemTestFile_TestWordPdf_WithSlicing(t *testing.T) {
func TestSliceFS_SliceFS_WithDisabledOptions_ReturnsValidHash(t *testing.T) {
fsys := os.DirFS("./artefacts")
filename := "test.pdf"
algorithm := algorithms.Xxhash
expected := "bedd0999e968547e"
options := Options{
DisableSlicing: false,
DisableMeta: false,
DisableAutoText: false,
}
runHashCheckTestsForFileSystemFile_WithSliceFS(fsys, filename, algorithm, &options, expected, t)
}
func TestSliceFS_New_FileSystemTestFile_TestAdobePdf_WithSlicing(t *testing.T) {
fsys := os.DirFS("./artefacts")
filename := "test-adobe.pdf"
algorithm := algorithms.Xxhash
expected := "41d4d0a83d10e962"
options := Options{
DisableSlicing: false,
DisableMeta: false,
DisableAutoText: false,
}
runHashCheckTestsForFileSystemFile_WithSliceFS(fsys, filename, algorithm, &options, expected, t)
}
func TestSliceFS_New_FileSystemTestFile_Test1mb_WithSlicing(t *testing.T) {
fsys := os.DirFS("./artefacts")
filename := "test.1mb"
algorithm := algorithms.Xxhash
expected := "bb83f43630ee546f"
options := Options{
DisableSlicing: false,
DisableMeta: false,
DisableAutoText: false,
}
runHashCheckTestsForFileSystemFile_WithSliceFS(fsys, filename, algorithm, &options, expected, t)
}
func TestSliceFS_New_FileSystemTestFile_Test1mb_WithoutMeta(t *testing.T) {
fsys := os.DirFS("./artefacts")
filename := "test.1mb"
algorithm := algorithms.Xxhash
expected := "913c30543271faaf"
options := Options{
DisableSlicing: false,
DisableMeta: true,
DisableAutoText: false,
}
runHashCheckTestsForFileSystemFile_WithSliceFS(fsys, filename, algorithm, &options, expected, t)
}
func TestSliceFS_New_FileSystemTestFile_TestManipulated1mb_WithSlicing(t *testing.T) {
fsys := os.DirFS("./artefacts")
filename := "test-manipulated.1mb"
algorithm := algorithms.Xxhash
expected := "4f595576799edcd9"
options := Options{
DisableSlicing: false,
DisableMeta: false,
DisableAutoText: false,

tests := []struct {
name string
filename string
options Options
expected string
}{
{
name: "FileSystemTestFile_TestWordPdf_WithSlicing",
filename: "test.pdf",
options: Options{
DisableSlicing: false,
DisableMeta: false,
DisableAutoText: false,
},
expected: "bedd0999e968547e",
},
{
name: "FileSystemTestFile_TestAdobePdf_WithSlicing",
filename: "test-adobe.pdf",
options: Options{
DisableSlicing: false,
DisableMeta: false,
DisableAutoText: false,
},
expected: "41d4d0a83d10e962",
},
{
name: "FileSystemTestFile_Test1mb_WithSlicing",
filename: "test.1mb",
options: Options{
DisableSlicing: false,
DisableMeta: false,
DisableAutoText: false,
},
expected: "bb83f43630ee546f",
},
{
name: "FileSystemTestFile_Test1mb_WithoutMeta",
filename: "test.1mb",
options: Options{
DisableSlicing: false,
DisableMeta: true,
DisableAutoText: false,
},
expected: "913c30543271faaf",
},
{
name: "FileSystemTestFile_TestManipulated1mb_WithSlicing",
filename: "test-manipulated.1mb",
options: Options{
DisableSlicing: false,
DisableMeta: false,
DisableAutoText: false,
},
expected: "4f595576799edcd9",
},
// Add other test cases here...
}
runHashCheckTestsForFileSystemFile_WithSliceFS(fsys, filename, algorithm, &options, expected, t)
}

func runHashCheckTestsForFileSystemFile_WithSliceFS(fs fs.FS, filename string, algorithm algorithms.Algorithm, options *Options, expected string, t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

slicer := New(algorithm)
slicer := New(algorithm)

if stats, err := slicer.SliceFS(fs, filename, options); err != nil {
t.Errorf("Unexpected Slicer error %v", err)
} else {
if stats, err := slicer.SliceFS(fsys, tt.filename, &tt.options); err != nil {
t.Errorf("Unexpected Slicer error %v", err)
} else {

actual := hex.EncodeToString(stats.Hash)
actual := hex.EncodeToString(stats.Hash)

if len(expected) != len(actual) {
t.Errorf("hash length expected %d, got %d", len(expected), len(actual))
}
if len(tt.expected) != len(actual) {
t.Errorf("hash length expected %d, got %d", len(tt.expected), len(actual))
}

if !strings.EqualFold(actual, expected) {
t.Errorf("expected hash %s, got %s for %s", expected, actual, filename)
}
if !strings.EqualFold(actual, tt.expected) {
t.Errorf("expected hash %s, got %s for %s", tt.expected, actual, tt.filename)
}
}
})
}

}

func TestSlice_New_Hash_xxHash_With1KbBlob(t *testing.T) {
runHashAlgorithmTest(algorithms.Xxhash, t)
}

Unchanged files with check annotations Beta

stats, err := sl.SliceFS(*file.FileSystem, file.Path, slo)
elapsedMs := time.Now().UnixMilli() - startTime
if err != nil {

Check failure on line 161 in internal/smash/app.go

GitHub Actions / golangci

ifElseChain: rewrite if-else to switch statement (gocritic)
if isVerbose {
theme.WarnSkipWithContext(file.FullName, err)
}