-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Fix trimming for non-space whitespace (#10)
Previously, trimming would only happen at the first space, which is an issue when the operation name is separated by another whitespace character like a newline.
- Loading branch information
Showing
2 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package otelpgx | ||
|
||
import "testing" | ||
|
||
func TestSqlOperationName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
query string | ||
expName string | ||
}{ | ||
{ | ||
name: "Spaces only", | ||
query: "SELECT * FROM users", | ||
expName: "SELECT", | ||
}, | ||
{ | ||
name: "Newline and tab", | ||
query: "UPDATE\n\tfoo", | ||
expName: "UPDATE", | ||
}, | ||
{ | ||
name: "Additional whitespace", | ||
query: " \n SELECT\n\t * FROM users ", | ||
expName: "SELECT", | ||
}, | ||
{ | ||
name: "Whitespace-only query", | ||
query: " \n\t", | ||
expName: "UNKNOWN", | ||
}, | ||
{ | ||
name: "Empty query", | ||
query: "", | ||
expName: "UNKNOWN", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
name := sqlOperationName(tt.query) | ||
if name != tt.expName { | ||
t.Errorf("Got name %q, expected %q", name, tt.expName) | ||
} | ||
}) | ||
} | ||
} |