Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/protocols/common/utils/vardump/dump_test.go
2073 views
1
package vardump
2
3
import (
4
"strings"
5
"testing"
6
7
"github.com/stretchr/testify/assert"
8
)
9
10
func TestDumpVariables(t *testing.T) {
11
// Enable var dump for testing
12
EnableVarDump = true
13
14
// Test case
15
testVars := variables{
16
"string": "test",
17
"int": 42,
18
"bool": true,
19
"slice": []string{"a", "b", "c"},
20
}
21
22
result := DumpVariables(testVars)
23
24
// Assertions
25
assert.NotEmpty(t, result)
26
assert.Contains(t, result, "string")
27
assert.Contains(t, result, "test")
28
assert.Contains(t, result, "int")
29
assert.Contains(t, result, "42")
30
assert.Contains(t, result, "bool")
31
assert.Contains(t, result, "true")
32
assert.Contains(t, result, "slice")
33
assert.Contains(t, result, "a")
34
assert.Contains(t, result, "b")
35
assert.Contains(t, result, "c")
36
37
}
38
39
func TestProcess(t *testing.T) {
40
testVars := variables{
41
"short": "short string",
42
"long": strings.Repeat("a", 300),
43
"number": 42,
44
}
45
46
processed := process(testVars, 255)
47
48
assert.Equal(t, "short string", processed["short"])
49
assert.Equal(t, strings.Repeat("a", 255)+" [...]", processed["long"])
50
assert.Equal(t, "42", processed["number"])
51
}
52
53