Skip to content

Commit

Permalink
test(vardump): add test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Dwi Siswanto <[email protected]>
  • Loading branch information
dwisiswant0 committed Sep 30, 2024
1 parent d04c788 commit 726f43b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/protocols/common/utils/vardump/dump_test.go
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"])
}

0 comments on commit 726f43b

Please sign in to comment.