-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dwi Siswanto <[email protected]>
- Loading branch information
1 parent
d04c788
commit 726f43b
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package vardump | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDumpVariables(t *testing.T) { | ||
// Enable var dump for testing | ||
EnableVarDump = true | ||
|
||
// Test case | ||
testVars := variables{ | ||
"string": "test", | ||
"int": 42, | ||
"bool": true, | ||
"slice": []string{"a", "b", "c"}, | ||
} | ||
|
||
result := DumpVariables(testVars) | ||
|
||
// Assertions | ||
assert.NotEmpty(t, result) | ||
assert.Contains(t, result, "string") | ||
assert.Contains(t, result, "test") | ||
assert.Contains(t, result, "int") | ||
assert.Contains(t, result, "42") | ||
assert.Contains(t, result, "bool") | ||
assert.Contains(t, result, "true") | ||
assert.Contains(t, result, "slice") | ||
assert.Contains(t, result, "a") | ||
assert.Contains(t, result, "b") | ||
assert.Contains(t, result, "c") | ||
|
||
// Test with EnableVarDump set to false | ||
EnableVarDump = false | ||
result = DumpVariables(testVars) | ||
assert.Empty(t, result) | ||
} | ||
|
||
func TestProcess(t *testing.T) { | ||
testVars := variables{ | ||
"short": "short string", | ||
"long": strings.Repeat("a", 300), | ||
"number": 42, | ||
} | ||
|
||
processed := process(testVars, 255) | ||
|
||
assert.Equal(t, "short string", processed["short"]) | ||
assert.Equal(t, strings.Repeat("a", 255)+" [...]", processed["long"]) | ||
assert.Equal(t, "42", processed["number"]) | ||
} |