-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathtemplates_test.go
36 lines (32 loc) · 1.17 KB
/
templates_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
package templates
import (
"os"
"testing"
"github.com/projectdiscovery/nuclei/v3/pkg/utils/json"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)
func TestTemplateStruct(t *testing.T) {
templatePath := "./tests/match-1.yaml"
bin, err := os.ReadFile(templatePath)
require.Nil(t, err, "failed to load example template")
var yamlTemplate Template
err = yaml.Unmarshal(bin, &yamlTemplate)
require.Nil(t, err, "failed to unmarshal yaml template")
jsonBin, err := json.Marshal(yamlTemplate)
require.Nil(t, err, "failed to marshal template to json")
var jsonTemplate Template
err = json.Unmarshal(jsonBin, &jsonTemplate)
require.Nil(t, err, "failed to unmarshal json template")
templatePath = "./tests/json-template.json"
bin, err = os.ReadFile(templatePath)
require.Nil(t, err, "failed to load example template")
jsonTemplate = Template{}
err = json.Unmarshal(bin, &jsonTemplate)
require.Nil(t, err, "failed to unmarshal json template")
yamlBin, err := yaml.Marshal(jsonTemplate)
require.Nil(t, err, "failed to marshal template to yaml")
yamlTemplate = Template{}
err = yaml.Unmarshal(yamlBin, &yamlTemplate)
require.Nil(t, err, "failed to unmarshal yaml template")
}