Approval-based snapshot testing library for Go (mirror)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: code cleanup

+228 -290
+1 -2
__snapshots__/test_combined_ignore_and_scrub.snap __snapshots__/test_combined_ignore_and_scrub.snap.new
··· 1 1 --- 2 2 title: Combined Ignore and Scrub 3 3 test_name: TestCombinedIgnoreAndScrub 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_complex_json_structure.snap __snapshots__/test_complex_json_structure.snap.new
··· 1 1 --- 2 2 title: Complex JSON Structure 3 3 test_name: TestComplexJsonStructure 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_complex_nested_structure.snap __snapshots__/test_complex_nested_structure.snap.new
··· 1 1 --- 2 2 title: Complex Nested Structure 3 3 test_name: TestComplexNestedStructure 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 freeze_test.Post{
+1 -2
__snapshots__/test_complex_real_world_example.snap __snapshots__/test_complex_real_world_example.snap.new
··· 1 1 --- 2 2 title: Real World API Response 3 3 test_name: TestComplexRealWorldExample 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_credit_card_scrubbing.snap __snapshots__/test_credit_card_scrubbing.snap.new
··· 1 1 --- 2 2 title: Scrubbed Credit Cards 3 3 test_name: TestCreditCardScrubbing 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_custom_ignore.snap __snapshots__/test_custom_ignore.snap.new
··· 1 1 --- 2 2 title: Custom Ignore Function 3 3 test_name: TestCustomIgnore 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_custom_scrubber.snap __snapshots__/test_custom_scrubber.snap.new
··· 1 1 --- 2 2 title: Custom Scrubber 3 3 test_name: TestCustomScrubber 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 hello world! this is a test.
+1 -2
__snapshots__/test_deeply_nested_json.snap __snapshots__/test_deeply_nested_json.snap.new
··· 1 1 --- 2 2 title: Deeply Nested JSON 3 3 test_name: TestDeeplyNestedJson 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_exact_match_scrubber.snap __snapshots__/test_exact_match_scrubber.snap.new
··· 1 1 --- 2 2 title: Exact Match Scrubber 3 3 test_name: TestExactMatchScrubber 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 The secret password is '<PASSWORD>' and should be hidden.
+1 -2
__snapshots__/test_go_struct_marshalled_to_json.snap __snapshots__/test_go_struct_marshalled_to_json.snap.new
··· 1 1 --- 2 2 title: Go Struct Marshalled to JSON 3 3 test_name: TestGoStructMarshalledToJson 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_ignore_empty_values.snap __snapshots__/test_ignore_empty_values.snap.new
··· 1 1 --- 2 2 title: Ignore Empty Values 3 3 test_name: TestIgnoreEmptyValues 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_ignore_in_arrays.snap __snapshots__/test_ignore_in_arrays.snap.new
··· 1 1 --- 2 2 title: Ignore in Arrays 3 3 test_name: TestIgnoreInArrays 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_ignore_key_pattern.snap __snapshots__/test_ignore_key_pattern.snap.new
··· 1 1 --- 2 2 title: Ignore Key Pattern 3 3 test_name: TestIgnoreKeyPattern 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_ignore_key_value.snap __snapshots__/test_ignore_key_value.snap.new
··· 1 1 --- 2 2 title: Ignore Password Field 3 3 test_name: TestIgnoreKeyValue 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_ignore_keys.snap __snapshots__/test_ignore_keys.snap.new
··· 1 1 --- 2 2 title: Ignore Multiple Keys 3 3 test_name: TestIgnoreKeys 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_ignore_keys_matching.snap __snapshots__/test_ignore_keys_matching.snap.new
··· 1 1 --- 2 2 title: Ignore Keys Matching Pattern 3 3 test_name: TestIgnoreKeysMatching 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_ignore_null_values.snap __snapshots__/test_ignore_null_values.snap.new
··· 1 1 --- 2 2 title: Ignore Null Values 3 3 test_name: TestIgnoreNullValues 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_ignore_sensitive_keys.snap __snapshots__/test_ignore_sensitive_keys.snap.new
··· 1 1 --- 2 2 title: Ignore Sensitive Keys 3 3 test_name: TestIgnoreSensitiveKeys 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_ignore_values.snap __snapshots__/test_ignore_values.snap.new
··· 1 1 --- 2 2 title: Ignore Specific Values 3 3 test_name: TestIgnoreValues 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_json_array_of_objects.snap __snapshots__/test_json_array_of_objects.snap.new
··· 1 1 --- 2 2 title: JSON Array of Objects 3 3 test_name: TestJsonArrayOfObjects 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 []interface{}{
+1 -2
__snapshots__/test_json_numbers.snap __snapshots__/test_json_numbers.snap.new
··· 1 1 --- 2 2 title: JSON Numbers 3 3 test_name: TestJsonNumbers 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_json_object.snap __snapshots__/test_json_object.snap.new
··· 1 1 --- 2 2 title: JSON Object 3 3 test_name: TestJsonObject 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_json_with_mixed_arrays.snap __snapshots__/test_json_with_mixed_arrays.snap.new
··· 1 1 --- 2 2 title: JSON with Mixed Arrays 3 3 test_name: TestJsonWithMixedArrays 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_json_with_special_characters.snap __snapshots__/test_json_with_special_characters.snap.new
··· 1 1 --- 2 2 title: JSON with Special Characters 3 3 test_name: TestJsonWithSpecialCharacters 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_json_with_various_types.snap __snapshots__/test_json_with_various_types.snap.new
··· 1 1 --- 2 2 title: JSON with Various Types 3 3 test_name: TestJsonWithVariousTypes 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_large_json.snap __snapshots__/test_large_json.snap.new
··· 1 1 --- 2 2 title: Large JSON Structure 3 3 test_name: TestLargeJson 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_map.snap __snapshots__/test_map.snap.new
··· 1 1 --- 2 2 title: Map Test 3 3 test_name: TestMap 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_multiple_complex_structures.snap __snapshots__/test_multiple_complex_structures.snap.new
··· 1 1 --- 2 2 title: Multiple Complex Structures 3 3 test_name: TestMultipleComplexStructures 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 []freeze_test.User{
+1 -2
__snapshots__/test_multiple_scrubbers.snap __snapshots__/test_multiple_scrubbers.snap.new
··· 1 1 --- 2 2 title: Multiple Scrubbers 3 3 test_name: TestMultipleScrubbers 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_nested_ignore_patterns.snap __snapshots__/test_nested_ignore_patterns.snap.new
··· 1 1 --- 2 2 title: Nested Ignore Patterns 3 3 test_name: TestNestedIgnorePatterns 4 - file_path: 5 - func_name: 4 + file_name: ignore_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_nested_maps_and_slices.snap __snapshots__/test_nested_maps_and_slices.snap.new
··· 1 1 --- 2 2 title: Nested Maps and Slices 3 3 test_name: TestNestedMapsAndSlices 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_regex_scrubber.snap __snapshots__/test_regex_scrubber.snap.new
··· 1 1 --- 2 2 title: Custom Regex Scrubber 3 3 test_name: TestRegexScrubber 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_scrub_a_p_i_keys.snap __snapshots__/test_scrub_a_p_i_keys.snap.new
··· 1 1 --- 2 2 title: Scrubbed API Keys 3 3 test_name: TestScrubAPIKeys 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_scrub_dates.snap __snapshots__/test_scrub_dates.snap.new
··· 1 1 --- 2 2 title: Scrubbed Dates 3 3 test_name: TestScrubDates 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_scrub_emails.snap __snapshots__/test_scrub_emails.snap.new
··· 1 1 --- 2 2 title: Scrubbed Emails 3 3 test_name: TestScrubEmails 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_scrub_i_p_addresses.snap __snapshots__/test_scrub_i_p_addresses.snap.new
··· 1 1 --- 2 2 title: Scrubbed IPs 3 3 test_name: TestScrubIPAddresses 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_scrub_j_w_ts.snap __snapshots__/test_scrub_j_w_ts.snap.new
··· 1 1 --- 2 2 title: Scrubbed JWTs 3 3 test_name: TestScrubJWTs 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_scrub_timestamps.snap __snapshots__/test_scrub_timestamps.snap.new
··· 1 1 --- 2 2 title: Scrubbed Timestamps 3 3 test_name: TestScrubTimestamps 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_scrub_u_u_i_ds.snap __snapshots__/test_scrub_u_u_i_ds.snap.new
··· 1 1 --- 2 2 title: Scrubbed UUIDs 3 3 test_name: TestScrubUUIDs 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_scrub_with_snap_function.snap __snapshots__/test_scrub_with_snap_function.snap.new
··· 1 1 --- 2 2 title: Scrub With Snap 3 3 test_name: TestScrubWithSnapFunction 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 map[string]interface{}{
+1 -2
__snapshots__/test_snap_custom_type.snap __snapshots__/test_snap_custom_type.snap.new
··· 1 1 --- 2 2 title: Custom Type Test 3 3 test_name: TestSnapCustomType 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 freeze_test.CustomStruct{
+1 -2
__snapshots__/test_snap_json_array_of_objects.snap __snapshots__/test_snap_json_array_of_objects.snap.new
··· 1 1 --- 2 2 title: SnapJSON Array of Objects 3 3 test_name: TestSnapJsonArrayOfObjects 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 [
+1 -2
__snapshots__/test_snap_json_basic.snap __snapshots__/test_snap_json_basic.snap.new
··· 1 1 --- 2 2 title: SnapJSON Basic Object 3 3 test_name: TestSnapJsonBasic 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_json_compact_format.snap __snapshots__/test_snap_json_compact_format.snap.new
··· 1 1 --- 2 2 title: SnapJSON Compact Format 3 3 test_name: TestSnapJsonCompactFormat 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {"id":1,"name":"Product","price":99.99,"in_stock":true,"tags":["electronics","gadgets"]}
+1 -2
__snapshots__/test_snap_json_complex_a_p_i.snap __snapshots__/test_snap_json_complex_a_p_i.snap.new
··· 1 1 --- 2 2 title: SnapJSON Complex API Response 3 3 test_name: TestSnapJsonComplexAPI 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_json_empty_structures.snap __snapshots__/test_snap_json_empty_structures.snap.new
··· 1 1 --- 2 2 title: SnapJSON Empty Structures 3 3 test_name: TestSnapJsonEmptyStructures 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_json_large_nested_structure.snap __snapshots__/test_snap_json_large_nested_structure.snap.new
··· 1 1 --- 2 2 title: SnapJSON Large Nested Structure 3 3 test_name: TestSnapJsonLargeNestedStructure 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_json_mixed_types.snap __snapshots__/test_snap_json_mixed_types.snap.new
··· 1 1 --- 2 2 title: SnapJSON Mixed Types 3 3 test_name: TestSnapJsonMixedTypes 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_json_real_world_example.snap __snapshots__/test_snap_json_real_world_example.snap.new
··· 1 1 --- 2 2 title: SnapJSON Real World Example 3 3 test_name: TestSnapJsonRealWorldExample 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_json_simple_array.snap __snapshots__/test_snap_json_simple_array.snap.new
··· 1 1 --- 2 2 title: SnapJSON Simple Array 3 3 test_name: TestSnapJsonSimpleArray 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 [
+1 -2
__snapshots__/test_snap_json_with_nested_objects.snap __snapshots__/test_snap_json_with_nested_objects.snap.new
··· 1 1 --- 2 2 title: SnapJSON Nested Objects 3 3 test_name: TestSnapJsonWithNestedObjects 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_json_with_nulls.snap __snapshots__/test_snap_json_with_nulls.snap.new
··· 1 1 --- 2 2 title: SnapJSON With Nulls 3 3 test_name: TestSnapJsonWithNulls 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_json_with_numbers.snap __snapshots__/test_snap_json_with_numbers.snap.new
··· 1 1 --- 2 2 title: SnapJSON With Numbers 3 3 test_name: TestSnapJsonWithNumbers 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_json_with_special_characters.snap __snapshots__/test_snap_json_with_special_characters.snap.new
··· 1 1 --- 2 2 title: SnapJSON With Special Characters 3 3 test_name: TestSnapJsonWithSpecialCharacters 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+1 -2
__snapshots__/test_snap_multiple.snap __snapshots__/test_snap_multiple.snap.new
··· 1 1 --- 2 2 title: Multiple Values Test 3 3 test_name: TestSnapMultiple 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 "value1"
+1 -2
__snapshots__/test_snap_string.snap __snapshots__/test_snap_string.snap.new
··· 1 1 --- 2 2 title: Simple String Test 3 3 test_name: TestSnapString 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 hello world
+1 -2
__snapshots__/test_structure_with_empty_values.snap __snapshots__/test_structure_with_empty_values.snap.new
··· 1 1 --- 2 2 title: Structure with Empty Values 3 3 test_name: TestStructureWithEmptyValues 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 []freeze_test.Container{
+1 -2
__snapshots__/test_structure_with_interface.snap __snapshots__/test_structure_with_interface.snap.new
··· 1 1 --- 2 2 title: Structure with Interface Fields 3 3 test_name: TestStructureWithInterface 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 []freeze_test.Response{
+1 -2
__snapshots__/test_structure_with_pointers.snap __snapshots__/test_structure_with_pointers.snap.new
··· 1 1 --- 2 2 title: Structure with Pointers 3 3 test_name: TestStructureWithPointers 4 - file_path: 5 - func_name: 4 + file_name: freeze_test.go 6 5 version: 0.1.0 7 6 --- 8 7 freeze_test.Person{
+1 -2
__snapshots__/test_unix_timestamp_scrubbing.snap __snapshots__/test_unix_timestamp_scrubbing.snap.new
··· 1 1 --- 2 2 title: Scrubbed Unix Timestamps 3 3 test_name: TestUnixTimestampScrubbing 4 - file_path: 5 - func_name: 4 + file_name: scrubbers_test.go 6 5 version: 0.1.0 7 6 --- 8 7 {
+26 -6
freeze.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 + "path/filepath" 6 + "runtime" 5 7 6 8 "github.com/kortschak/utter" 7 9 "github.com/ptdewey/freeze/internal/diff" ··· 87 89 func snap(t testingT, title string, content string) { 88 90 t.Helper() 89 91 testName := t.Name() 90 - snapWithTitle(t, title, testName, content) 92 + 93 + // Capture the caller's file name by walking up the call stack 94 + // to find the first file that's not freeze.go TODO: does this actually work for all cases? 95 + fileName := "unknown" 96 + for i := 1; i < 10; i++ { 97 + _, file, _, ok := runtime.Caller(i) 98 + if !ok { 99 + break 100 + } 101 + baseName := filepath.Base(file) 102 + // Skip frames within freeze.go to get to the actual test file 103 + if baseName != "freeze.go" { 104 + fileName = baseName 105 + break 106 + } 107 + } 108 + 109 + snapWithTitle(t, title, testName, fileName, content) 91 110 } 92 111 93 - func snapWithTitle(t testingT, title string, testName string, content string) { 112 + func snapWithTitle(t testingT, title string, testName string, fileName string, content string) { 94 113 t.Helper() 95 114 96 115 snapshot := &files.Snapshot{ 97 - Title: title, 98 - Name: testName, 99 - Content: content, 100 - Version: version, 116 + Title: title, 117 + Test: testName, 118 + FileName: fileName, 119 + Content: content, 120 + Version: version, 101 121 } 102 122 103 123 accepted, err := files.ReadAccepted(testName)
+43 -39
freeze_test.go
··· 46 46 47 47 func TestSerializeDeserialize(t *testing.T) { 48 48 snap := &freeze.Snapshot{ 49 - Title: "My Test Title", 50 - Name: "TestExample", 51 - Content: "test content\nmultiline", 49 + Title: "My Test Title", 50 + Test: "TestExample", 51 + FileName: "test_file.go", 52 + Content: "test content\nmultiline", 52 53 } 53 54 54 55 serialized := snap.Serialize() 55 - expected := "---\ntitle: My Test Title\ntest_name: TestExample\nfile_path: \nfunc_name: \nversion: \n---\ntest content\nmultiline" 56 + expected := "---\ntitle: My Test Title\ntest_name: TestExample\nfile_name: test_file.go\nversion: \n---\ntest content\nmultiline" 56 57 if serialized != expected { 57 58 t.Errorf("expected:\n%s\ngot:\n%s", expected, serialized) 58 59 } ··· 65 66 if deserialized.Title != snap.Title { 66 67 t.Errorf("title mismatch: %s != %s", deserialized.Title, snap.Title) 67 68 } 68 - if deserialized.Name != snap.Name { 69 - t.Errorf("test name mismatch: %s != %s", deserialized.Name, snap.Name) 69 + if deserialized.Test != snap.Test { 70 + t.Errorf("test name mismatch: %s != %s", deserialized.Test, snap.Test) 71 + } 72 + if deserialized.FileName != snap.FileName { 73 + t.Errorf("file name mismatch: %s != %s", deserialized.FileName, snap.FileName) 70 74 } 71 75 if deserialized.Content != snap.Content { 72 76 t.Errorf("content mismatch: %s != %s", deserialized.Content, snap.Content) ··· 76 80 func TestFileOperations(t *testing.T) { 77 81 snap := &freeze.Snapshot{ 78 82 Title: "File Ops Title", 79 - Name: "TestFileOps", 83 + Test: "TestFileOps", 80 84 Content: "file test content", 81 85 } 82 86 ··· 156 160 func TestDiffSnapshotBox(t *testing.T) { 157 161 old := &freeze.Snapshot{ 158 162 Title: "Diff Test Title", 159 - Name: "TestDiff", 163 + Test: "TestDiff", 160 164 Content: "old content", 161 165 } 162 166 163 167 new := &freeze.Snapshot{ 164 168 Title: "Diff Test Title", 165 - Name: "TestDiff", 169 + Test: "TestDiff", 166 170 Content: "new content", 167 171 } 168 172 ··· 179 183 func TestNewSnapshotBox(t *testing.T) { 180 184 snap := &freeze.Snapshot{ 181 185 Title: "New Test Title", 182 - Name: "TestNew", 186 + Test: "TestNew", 183 187 Content: "test content", 184 188 } 185 189 ··· 221 225 Active bool 222 226 CreatedAt time.Time 223 227 Roles []string 224 - Metadata map[string]interface{} 228 + Metadata map[string]any 225 229 } 226 230 227 231 type Post struct { ··· 252 256 Active: true, 253 257 CreatedAt: time.Date(2023, 1, 15, 10, 30, 0, 0, time.UTC), 254 258 Roles: []string{"admin", "moderator", "user"}, 255 - Metadata: map[string]interface{}{ 259 + Metadata: map[string]any{ 256 260 "theme": "dark", 257 261 "notifications": true, 258 262 "language": "en", 259 - "preferences": map[string]interface{}{ 263 + "preferences": map[string]any{ 260 264 "email_frequency": "weekly", 261 265 "notifications": true, 262 266 }, ··· 311 315 Email: "alice@example.com", 312 316 Active: true, 313 317 Roles: []string{"user", "moderator"}, 314 - Metadata: map[string]interface{}{ 318 + Metadata: map[string]any{ 315 319 "verified": true, 316 320 "badge": "verified", 317 321 }, ··· 322 326 Email: "bob@example.com", 323 327 Active: false, 324 328 Roles: []string{"user"}, 325 - Metadata: map[string]interface{}{ 329 + Metadata: map[string]any{ 326 330 "verified": false, 327 331 "avatar": "https://example.com/bob.jpg", 328 332 }, ··· 333 337 Email: "charlie@example.com", 334 338 Active: true, 335 339 Roles: []string{"user", "admin"}, 336 - Metadata: map[string]interface{}{ 340 + Metadata: map[string]any{ 337 341 "verified": true, 338 342 "account_age_days": 365, 339 343 }, ··· 347 351 type Response struct { 348 352 Status string 349 353 Message string 350 - Data interface{} 351 - Meta map[string]interface{} 354 + Data any 355 + Meta map[string]any 352 356 } 353 357 354 358 responses := []Response{ ··· 361 365 Email: "john@example.com", 362 366 Active: true, 363 367 }, 364 - Meta: map[string]interface{}{ 368 + Meta: map[string]any{ 365 369 "request_id": "req-123", 366 370 "timestamp": "2023-01-20T10:30:00Z", 367 371 }, ··· 370 374 Status: "error", 371 375 Message: "User not found", 372 376 Data: nil, 373 - Meta: map[string]interface{}{ 377 + Meta: map[string]any{ 374 378 "error_code": 404, 375 379 "error_type": "NOT_FOUND", 376 380 }, ··· 385 389 Published: true, 386 390 }, 387 391 }, 388 - Meta: map[string]interface{}{ 392 + Meta: map[string]any{ 389 393 "total_count": 10, 390 394 "page": 1, 391 395 "per_page": 20, ··· 397 401 } 398 402 399 403 func TestNestedMapsAndSlices(t *testing.T) { 400 - complexData := map[string]interface{}{ 401 - "users": map[string]interface{}{ 402 - "active": []map[string]interface{}{ 404 + complexData := map[string]any{ 405 + "users": map[string]any{ 406 + "active": []map[string]any{ 403 407 { 404 408 "id": 1, 405 409 "name": "Alice", ··· 411 415 "verified": false, 412 416 }, 413 417 }, 414 - "inactive": []map[string]interface{}{ 418 + "inactive": []map[string]any{ 415 419 { 416 420 "id": 3, 417 421 "name": "Charlie", 418 422 }, 419 423 }, 420 424 }, 421 - "posts": map[string]interface{}{ 425 + "posts": map[string]any{ 422 426 "published": 42, 423 427 "drafts": 5, 424 428 "categories": []string{"tech", "lifestyle", "news"}, 425 429 }, 426 - "stats": map[string]interface{}{ 427 - "daily": map[string]interface{}{ 430 + "stats": map[string]any{ 431 + "daily": map[string]any{ 428 432 "views": 1500, 429 433 "clicks": 320, 430 - "conversions": map[string]interface{}{ 434 + "conversions": map[string]any{ 431 435 "total": 45, 432 436 "by_source": map[string]int{ 433 437 "organic": 25, ··· 543 547 "message": null 544 548 }` 545 549 546 - var data interface{} 550 + var data any 547 551 if err := json.Unmarshal([]byte(jsonStr), &data); err != nil { 548 552 t.Fatalf("failed to unmarshal json: %v", err) 549 553 } ··· 611 615 } 612 616 }` 613 617 614 - var data interface{} 618 + var data any 615 619 if err := json.Unmarshal([]byte(jsonStr), &data); err != nil { 616 620 t.Fatalf("failed to unmarshal json: %v", err) 617 621 } ··· 649 653 } 650 654 ]` 651 655 652 - var data interface{} 656 + var data any 653 657 if err := json.Unmarshal([]byte(jsonStr), &data); err != nil { 654 658 t.Fatalf("failed to unmarshal json: %v", err) 655 659 } ··· 675 679 "escaped_string": "line1\nline2\ttab" 676 680 }` 677 681 678 - var data interface{} 682 + var data any 679 683 if err := json.Unmarshal([]byte(jsonStr), &data); err != nil { 680 684 t.Fatalf("failed to unmarshal json: %v", err) 681 685 } ··· 703 707 } 704 708 }` 705 709 706 - var data interface{} 710 + var data any 707 711 if err := json.Unmarshal([]byte(jsonStr), &data); err != nil { 708 712 t.Fatalf("failed to unmarshal json: %v", err) 709 713 } ··· 723 727 "backslash": "path\\to\\file" 724 728 }` 725 729 726 - var data interface{} 730 + var data any 727 731 if err := json.Unmarshal([]byte(jsonStr), &data); err != nil { 728 732 t.Fatalf("failed to unmarshal json: %v", err) 729 733 } ··· 767 771 t.Fatalf("failed to marshal json: %v", err) 768 772 } 769 773 770 - var data interface{} 774 + var data any 771 775 if err := json.Unmarshal(jsonBytes, &data); err != nil { 772 776 t.Fatalf("failed to unmarshal json: %v", err) 773 777 } ··· 807 811 t.Fatalf("failed to marshal json: %v", err) 808 812 } 809 813 810 - var data interface{} 814 + var data any 811 815 if err := json.Unmarshal(jsonBytes, &data); err != nil { 812 816 t.Fatalf("failed to unmarshal json: %v", err) 813 817 } ··· 883 887 t.Fatalf("failed to marshal json: %v", err) 884 888 } 885 889 886 - var data interface{} 890 + var data any 887 891 if err := json.Unmarshal(jsonBytes, &data); err != nil { 888 892 t.Fatalf("failed to unmarshal json: %v", err) 889 893 } ··· 914 918 ] 915 919 }` 916 920 917 - var data interface{} 921 + var data any 918 922 if err := json.Unmarshal([]byte(jsonStr), &data); err != nil { 919 923 t.Fatalf("failed to unmarshal json: %v", err) 920 924 }
+3 -12
ignore.go
··· 2 2 3 3 import ( 4 4 "regexp" 5 + "slices" 5 6 "strings" 6 7 ) 7 8 ··· 64 65 } 65 66 66 67 func (k *keyOnlyIgnore) ShouldIgnore(key, value string) bool { 67 - for _, ignoreKey := range k.keys { 68 - if ignoreKey == key { 69 - return true 70 - } 71 - } 72 - return false 68 + return slices.Contains(k.keys, key) 73 69 } 74 70 75 71 // IgnoreKeys creates an ignore pattern that ignores the specified keys ··· 118 114 } 119 115 120 116 func (v *valueOnlyIgnore) ShouldIgnore(key, value string) bool { 121 - for _, ignoreValue := range v.values { 122 - if ignoreValue == value { 123 - return true 124 - } 125 - } 126 - return false 117 + return slices.Contains(v.values, value) 127 118 } 128 119 129 120 // IgnoreValues creates an ignore pattern that ignores the specified values
+1 -2
internal/files/__snapshots__/test_accept.snap
··· 1 1 --- 2 2 title: Accept Title 3 3 test_name: TestAccept 4 - file_path: 5 - func_name: 4 + file_name: 6 5 version: 7 6 --- 8 7 new content to accept
+11 -14
internal/files/files.go
··· 9 9 ) 10 10 11 11 type Snapshot struct { 12 + Version string 12 13 Title string 13 - Name string 14 - FilePath string 15 - FuncName string 16 - Version string 14 + Test string 15 + FileName string 17 16 Content string 18 17 } 19 18 20 19 func (s *Snapshot) Serialize() string { 21 20 header := fmt.Sprintf( 22 - "---\ntitle: %s\ntest_name: %s\nfile_path: %s\nfunc_name: %s\nversion: %s\n---\n", 23 - s.Title, s.Name, s.FilePath, s.FuncName, s.Version, 21 + "---\ntitle: %s\ntest_name: %s\nfile_name: %s\nversion: %s\n---\n", 22 + s.Title, s.Test, s.FileName, s.Version, 24 23 ) 25 24 return header + s.Content 26 25 } ··· 54 53 case "title": 55 54 snap.Title = value 56 55 case "test_name": 57 - snap.Name = value 58 - case "file_path": 59 - snap.FilePath = value 60 - case "func_name": 61 - snap.FuncName = value 56 + snap.Test = value 57 + case "file_name": 58 + snap.FileName = value 62 59 case "version": 63 60 snap.Version = value 64 61 } ··· 128 125 var fileName string 129 126 switch state { 130 127 case "accepted": 131 - fileName = SnapshotFileName(snap.Name) + ".snap" 128 + fileName = SnapshotFileName(snap.Test) + ".snap" 132 129 case "new": 133 - fileName = SnapshotFileName(snap.Name) + ".snap.new" 130 + fileName = SnapshotFileName(snap.Test) + ".snap.new" 134 131 default: 135 - fileName = SnapshotFileName(snap.Name) + "." + state 132 + fileName = SnapshotFileName(snap.Test) + "." + state 136 133 } 137 134 filePath := filepath.Join(snapshotDir, fileName) 138 135
+12 -28
internal/files/files_test.go
··· 35 35 func TestSerializeDeserialize(t *testing.T) { 36 36 snap := &files.Snapshot{ 37 37 Title: "Example Title", 38 - Name: "TestExample", 39 - FilePath: "/path/to/test.go", 38 + Test: "TestExample", 39 + FileName: "example_test.go", 40 40 Version: "1.0.0", 41 41 Content: "test content\nmultiline", 42 42 } 43 43 44 44 serialized := snap.Serialize() 45 - expected := "---\ntitle: Example Title\ntest_name: TestExample\nfile_path: /path/to/test.go\nfunc_name: \nversion: 1.0.0\n---\ntest content\nmultiline" 45 + expected := "---\ntitle: Example Title\ntest_name: TestExample\nfile_name: example_test.go\nversion: 1.0.0\n---\ntest content\nmultiline" 46 46 if serialized != expected { 47 47 t.Errorf("Serialize():\nexpected:\n%s\n\ngot:\n%s", expected, serialized) 48 48 } ··· 55 55 if deserialized.Title != snap.Title { 56 56 t.Errorf("Title mismatch: %s != %s", deserialized.Title, snap.Title) 57 57 } 58 - if deserialized.Name != snap.Name { 59 - t.Errorf("Name mismatch: %s != %s", deserialized.Name, snap.Name) 58 + if deserialized.Test != snap.Test { 59 + t.Errorf("Name mismatch: %s != %s", deserialized.Test, snap.Test) 60 60 } 61 - if deserialized.FilePath != snap.FilePath { 62 - t.Errorf("FilePath mismatch: %s != %s", deserialized.FilePath, snap.FilePath) 61 + if deserialized.FileName != snap.FileName { 62 + t.Errorf("FileName mismatch: %s != %s", deserialized.FileName, snap.FileName) 63 63 } 64 64 if deserialized.Version != snap.Version { 65 65 t.Errorf("Version mismatch: %s != %s", deserialized.Version, snap.Version) ··· 122 122 "", 123 123 "line1\nline2\nline3", 124 124 }, 125 - { 126 - "with extra fields", 127 - "---\ntitle: Extra Title\ntest_name: Test\nfile_path: /path\nfunc_name: \nextra: ignored\n---\ncontent", 128 - "Extra Title", 129 - "Test", 130 - "", 131 - "content", 132 - }, 133 - { 134 - "backward compatibility - no title", 135 - "---\ntest_name: Test\nfile_path: /path\nfunc_name: \n---\ncontent", 136 - "", 137 - "Test", 138 - "", 139 - "content", 140 - }, 141 125 } 142 126 143 127 for _, tt := range tests { ··· 149 133 if snap.Title != tt.wantTitle { 150 134 t.Errorf("Title = %s, want %s", snap.Title, tt.wantTitle) 151 135 } 152 - if snap.Name != tt.wantTest { 153 - t.Errorf("Name = %s, want %s", snap.Name, tt.wantTest) 136 + if snap.Test != tt.wantTest { 137 + t.Errorf("Name = %s, want %s", snap.Test, tt.wantTest) 154 138 } 155 139 if snap.Version != tt.wantVersion { 156 140 t.Errorf("Version = %s, want %s", snap.Version, tt.wantVersion) ··· 165 149 func TestSaveAndReadSnapshot(t *testing.T) { 166 150 snap := &files.Snapshot{ 167 151 Title: "Save Read Title", 168 - Name: "TestSaveRead", 152 + Test: "TestSaveRead", 169 153 Content: "saved content", 170 154 } 171 155 ··· 195 179 func TestAcceptSnapshot(t *testing.T) { 196 180 newSnap := &files.Snapshot{ 197 181 Title: "Accept Title", 198 - Name: "TestAccept", 182 + Test: "TestAccept", 199 183 Content: "new content to accept", 200 184 } 201 185 ··· 227 211 func TestRejectSnapshot(t *testing.T) { 228 212 snap := &files.Snapshot{ 229 213 Title: "Reject Title", 230 - Name: "TestReject", 214 + Test: "TestReject", 231 215 Content: "content to reject", 232 216 } 233 217
+53 -50
internal/pretty/boxes.go
··· 23 23 DiffNew 24 24 ) 25 25 26 - func newSnapshotBoxInternal(snap *files.Snapshot) string { 27 - width := TerminalWidth() 28 - snapshotFileName := files.SnapshotFileName(snap.Name) + ".snap.new" 29 - 30 - var sb strings.Builder 31 - sb.WriteString("─── " + "New Snapshot " + strings.Repeat("─", width-15) + "\n\n") 32 - 33 - if snap.Title != "" { 34 - sb.WriteString(fmt.Sprintf(" title: %s\n", Blue(snap.Title))) 35 - } 36 - if snap.Name != "" { 37 - sb.WriteString(fmt.Sprintf(" test: %s\n", Blue(snap.Name))) 38 - } 39 - // TODO: maybe put this on the "new snapshot row"? (or only show on the diff view) 40 - if snapshotFileName != "" { 41 - sb.WriteString(fmt.Sprintf(" file: %s\n", Gray(snapshotFileName))) 42 - } 43 - sb.WriteString("\n") 44 - 45 - lines := strings.Split(snap.Content, "\n") 46 - numLines := len(lines) 47 - lineNumWidth := len(strconv.Itoa(numLines)) 48 - 49 - topBar := strings.Repeat("─", lineNumWidth+3) + "┬" + 50 - strings.Repeat("─", width-lineNumWidth-2) + "\n" 51 - sb.WriteString(topBar) 52 - 53 - for i, line := range lines { 54 - lineNum := fmt.Sprintf("%*d", lineNumWidth, i+1) 55 - prefix := fmt.Sprintf("%s %s", Green(lineNum), Green("+")) 56 - 57 - if len(line) > width-len(prefix)-4 { 58 - line = line[:width-len(prefix)-7] + "..." 59 - } 60 - 61 - display := fmt.Sprintf("%s %s", prefix, Green(line)) 62 - sb.WriteString(fmt.Sprintf(" %s\n", display)) 63 - } 64 - 65 - bottomBar := strings.Repeat("─", lineNumWidth+3) + "┴" + 66 - strings.Repeat("─", width-lineNumWidth-2) + "\n" 67 - sb.WriteString(bottomBar) 68 - 69 - return sb.String() 70 - } 71 - 72 26 func NewSnapshotBox(snap *files.Snapshot) string { 73 27 return newSnapshotBoxInternal(snap) 74 28 } 75 29 76 30 func DiffSnapshotBox(old, new *files.Snapshot, diffLines []DiffLine) string { 77 31 width := TerminalWidth() 78 - snapshotFileName := files.SnapshotFileName(new.Name) + ".snap" 32 + snapshotFileName := files.SnapshotFileName(new.Test) + ".snap" 79 33 80 34 var sb strings.Builder 81 35 sb.WriteString(strings.Repeat("─", width) + "\n") 36 + // TODO: maybe make helper functions for this, swap coloring between the key and the value 37 + // TODO: maybe show the snapshot file name in gray next to the "a/r/s" options 38 + // (i.e. "a accept -> snap_file_name.snap", "reject" w/strikethrough?, skip, keeps "*snap.new") 82 39 sb.WriteString(fmt.Sprintf(" file: %s\n", Gray(snapshotFileName))) 83 40 sb.WriteString(fmt.Sprintf(" %s\n", Blue("Snapshot Diff"))) 84 41 if new.Title != "" { 85 42 sb.WriteString(fmt.Sprintf(" title: %s\n", Blue("\""+new.Title+"\""))) 86 43 } 87 - sb.WriteString(fmt.Sprintf(" test: %s\n", Blue("\""+new.Name+"\""))) 44 + sb.WriteString(fmt.Sprintf(" test: %s\n", Blue("\""+new.Test+"\""))) 88 45 sb.WriteString(strings.Repeat("─", width) + "\n") 89 46 90 47 // Calculate max line numbers for proper spacing 91 - maxOldNum := 0 92 - maxNewNum := 0 48 + maxOldNum, maxNewNum := 0, 0 93 49 for _, dl := range diffLines { 94 50 if dl.OldNumber > maxOldNum { 95 51 maxOldNum = dl.OldNumber ··· 139 95 sb.WriteString(strings.Repeat("─", width) + "\n") 140 96 return sb.String() 141 97 } 98 + 99 + func newSnapshotBoxInternal(snap *files.Snapshot) string { 100 + width := TerminalWidth() 101 + 102 + var sb strings.Builder 103 + sb.WriteString("─── " + "New Snapshot " + strings.Repeat("─", width-15) + "\n\n") 104 + 105 + if snap.Title != "" { 106 + sb.WriteString(Blue(" title: ") + snap.Title + "\n") 107 + // sb.WriteString(fmt.Sprintf(" title: %s\n", Blue(snap.Title))) 108 + } 109 + if snap.Test != "" { 110 + // sb.WriteString(fmt.Sprintf(" test: %s\n", Blue(snap.Test))) 111 + sb.WriteString(Blue(" test: ") + snap.Test + "\n") 112 + } 113 + if snap.FileName != "" { 114 + // sb.WriteString(fmt.Sprintf(" file: %s\n", Gray(snap.FileName))) 115 + sb.WriteString(Blue(" file: ") + snap.FileName + "\n") 116 + } 117 + sb.WriteString("\n") 118 + 119 + lines := strings.Split(snap.Content, "\n") 120 + numLines := len(lines) 121 + lineNumWidth := len(strconv.Itoa(numLines)) 122 + 123 + topBar := strings.Repeat("─", lineNumWidth+3) + "┬" + 124 + strings.Repeat("─", width-lineNumWidth-2) + "\n" 125 + sb.WriteString(topBar) 126 + 127 + for i, line := range lines { 128 + lineNum := fmt.Sprintf("%*d", lineNumWidth, i+1) 129 + prefix := fmt.Sprintf("%s %s", Green(lineNum), Green("+")) 130 + 131 + if len(line) > width-len(prefix)-4 { 132 + line = line[:width-len(prefix)-7] + "..." 133 + } 134 + 135 + display := fmt.Sprintf("%s %s", prefix, Green(line)) 136 + sb.WriteString(fmt.Sprintf(" %s\n", display)) 137 + } 138 + 139 + bottomBar := strings.Repeat("─", lineNumWidth+3) + "┴" + 140 + strings.Repeat("─", width-lineNumWidth-2) + "\n" 141 + sb.WriteString(bottomBar) 142 + 143 + return sb.String() 144 + }
+11 -11
internal/transform/transform.go
··· 36 36 return jsonStr, nil 37 37 } 38 38 39 - var data interface{} 39 + var data any 40 40 if err := json.Unmarshal([]byte(jsonStr), &data); err != nil { 41 41 return "", fmt.Errorf("failed to unmarshal JSON: %w", err) 42 42 } ··· 61 61 } 62 62 63 63 // walkAndFilter recursively walks the data structure and filters out ignored fields. 64 - func walkAndFilter(data interface{}, ignorePatterns []IgnorePattern) interface{} { 64 + func walkAndFilter(data any, ignorePatterns []IgnorePattern) any { 65 65 switch v := data.(type) { 66 - case map[string]interface{}: 66 + case map[string]any: 67 67 return filterMap(v, ignorePatterns) 68 - case []interface{}: 68 + case []any: 69 69 return filterSlice(v, ignorePatterns) 70 70 default: 71 71 return data ··· 73 73 } 74 74 75 75 // filterMap filters a map, removing entries that match ignore patterns. 76 - func filterMap(m map[string]interface{}, ignorePatterns []IgnorePattern) map[string]interface{} { 77 - result := make(map[string]interface{}) 76 + func filterMap(m map[string]any, ignorePatterns []IgnorePattern) map[string]any { 77 + result := make(map[string]any) 78 78 for key, value := range m { 79 79 // Convert value to string for comparison 80 80 valueStr := valueToString(value) 81 - 81 + 82 82 // Check if this key-value pair should be ignored 83 83 shouldIgnore := false 84 84 for _, pattern := range ignorePatterns { ··· 87 87 break 88 88 } 89 89 } 90 - 90 + 91 91 if !shouldIgnore { 92 92 // Recursively filter nested structures 93 93 result[key] = walkAndFilter(value, ignorePatterns) ··· 97 97 } 98 98 99 99 // filterSlice filters a slice, recursively processing each element. 100 - func filterSlice(s []interface{}, ignorePatterns []IgnorePattern) []interface{} { 101 - result := make([]interface{}, len(s)) 100 + func filterSlice(s []any, ignorePatterns []IgnorePattern) []any { 101 + result := make([]any, len(s)) 102 102 for i, item := range s { 103 103 result[i] = walkAndFilter(item, ignorePatterns) 104 104 } ··· 106 106 } 107 107 108 108 // valueToString converts various value types to string for comparison. 109 - func valueToString(value interface{}) string { 109 + func valueToString(value any) string { 110 110 switch v := value.(type) { 111 111 case string: 112 112 return v
+7 -7
scrubbers.go
··· 50 50 } 51 51 52 52 // Common regex patterns for scrubbing 53 + // TODO: review these 53 54 var ( 54 - uuidPattern = regexp.MustCompile(`[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`) 55 - iso8601Pattern = regexp.MustCompile(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?`) 56 - emailPattern = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`) 57 - unixTsPattern = regexp.MustCompile(`\b\d{10,13}\b`) 58 - ipv4Pattern = regexp.MustCompile(`\b(?:\d{1,3}\.){3}\d{1,3}\b`) 55 + uuidPattern = regexp.MustCompile(`[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`) 56 + iso8601Pattern = regexp.MustCompile(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?`) 57 + emailPattern = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`) 58 + unixTsPattern = regexp.MustCompile(`\b\d{10,13}\b`) 59 + ipv4Pattern = regexp.MustCompile(`\b(?:\d{1,3}\.){3}\d{1,3}\b`) 59 60 creditCardPattern = regexp.MustCompile(`\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b`) 60 - jwtPattern = regexp.MustCompile(`eyJ[a-zA-Z0-9_-]*\.eyJ[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*`) 61 + jwtPattern = regexp.MustCompile(`eyJ[a-zA-Z0-9_-]*\.eyJ[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*`) 61 62 ) 62 63 63 64 // ScrubUUIDs replaces all UUIDs with "<UUID>". ··· 136 137 }) 137 138 } 138 139 139 - // customScrubber allows users to provide a custom scrubbing function. 140 140 type customScrubber struct { 141 141 scrubFunc func(string) string 142 142 }
+1 -1
scrubbers_test.go
··· 141 141 } 142 142 143 143 func TestScrubWithSnapFunction(t *testing.T) { 144 - data := map[string]interface{}{ 144 + data := map[string]any{ 145 145 "user_id": "550e8400-e29b-41d4-a716-446655440000", 146 146 "email": "user@example.com", 147 147 "created_at": "2023-01-15T10:30:00Z",