-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator_test.go
47 lines (40 loc) · 1.35 KB
/
generator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"io/ioutil"
"testing"
)
const testKey1, testValue1 = "TESTING_KEY_1", "TESTING_VALUE_1"
const testKey2, testValue2 = "TESTING_KEY_2", "TESTING_VALUE_2"
var generator *GoltGenerator
func init() {
testingMap := make(map[string]string)
testingMap[testKey1] = testValue1
testingMap[testKey2] = testValue2
generator = &GoltGenerator{
RegexMap: testingMap,
}
}
func TestBuildRequest(t *testing.T) {
regexHeader := "test"
headerValue := fmt.Sprintf("$(%s)", testKey2)
regexRequest := GoltRequest{
Payload: fmt.Sprintf("$(%s)", testKey1),
Headers: map[string]*string{regexHeader: &headerValue},
}
httpRequest := generator.BuildRequest(true, regexRequest)
regexBody, _ := ioutil.ReadAll(httpRequest.Body)
if string(regexBody) != testValue1 || httpRequest.Header.Get(regexHeader) != testValue2 {
t.Error("Regex request returned is not valid")
}
testHeaderKey, testHeaderValue, testPayload := "headerKey", "headerValue", "payload"
request := GoltRequest{
Payload: testPayload,
Headers: map[string]*string{testHeaderKey: &testHeaderValue},
}
generatedRequest := generator.BuildRequest(false, request)
generatedBody, _ := ioutil.ReadAll(generatedRequest.Body)
if string(generatedBody) != testPayload || generatedRequest.Header.Get(testHeaderKey) != testHeaderValue {
t.Error("Regular request returned is not valid")
}
}