diff options
author | Caidan Williams <caidan@internet.dev> | 2025-08-25 15:28:09 -0700 |
---|---|---|
committer | Caidan Williams <caidan@internet.dev> | 2025-08-25 16:04:45 -0700 |
commit | 685650b2964ffa5e86c122a410e4b9713c01dcf7 (patch) | |
tree | 38fad34883650097f193e732fc982098e2f64041 /bskyweb | |
parent | f9118b2729ccfe6a651e9a1b3f033ebca2251c6d (diff) | |
download | voidsky-685650b2964ffa5e86c122a410e4b9713c01dcf7.tar.zst |
test: add comprehensive coverage for canonical URL filter
- Verify clean URL passthrough behavior - Test query parameter removal functionality - Test fragment removal functionality - Test combined query params and fragments handling - Ensure graceful degradation for malformed URLs
Diffstat (limited to 'bskyweb')
-rw-r--r-- | bskyweb/cmd/bskyweb/filters_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/bskyweb/cmd/bskyweb/filters_test.go b/bskyweb/cmd/bskyweb/filters_test.go new file mode 100644 index 000000000..2a3fc5b86 --- /dev/null +++ b/bskyweb/cmd/bskyweb/filters_test.go @@ -0,0 +1,61 @@ +package main + +import ( + "testing" + + "github.com/flosch/pongo2/v6" +) + +func TestCanonicalFilter(t *testing.T) { + tests := []struct { + name string + input string + expected string + }{ + { + name: "clean URL", + input: "https://bsky.app/profile/user", + expected: "https://bsky.app/profile/user", + }, + { + name: "URL with query params", + input: "https://bsky.app/profile/user?utm_source=test", + expected: "https://bsky.app/profile/user", + }, + { + name: "URL with multiple params", + input: "https://bsky.app/profile/user?utm_source=twitter&utm_campaign=test", + expected: "https://bsky.app/profile/user", + }, + { + name: "URL with fragment", + input: "https://bsky.app/profile/user#section", + expected: "https://bsky.app/profile/user", + }, + { + name: "URL with both params and fragment", + input: "https://bsky.app/profile/user?param=1#section", + expected: "https://bsky.app/profile/user", + }, + { + name: "malformed URL", + input: "not-a-url", + expected: "not-a-url", // Should return original on error + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + inputValue := pongo2.AsValue(tt.input) + result, err := filterCanonical(inputValue, nil) + if err != nil { + t.Errorf("filterCanonical() error = %v", err) + return + } + + if result.String() != tt.expected { + t.Errorf("filterCanonical() = %v, want %v", result.String(), tt.expected) + } + }) + } +} |