Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/templates/templates_test.go
2070 views
1
package templates
2
3
import (
4
"os"
5
"testing"
6
7
"github.com/projectdiscovery/nuclei/v3/pkg/utils/json"
8
"github.com/stretchr/testify/require"
9
"gopkg.in/yaml.v2"
10
)
11
12
func TestTemplateStruct(t *testing.T) {
13
templatePath := "./tests/match-1.yaml"
14
bin, err := os.ReadFile(templatePath)
15
require.Nil(t, err, "failed to load example template")
16
var yamlTemplate Template
17
err = yaml.Unmarshal(bin, &yamlTemplate)
18
require.Nil(t, err, "failed to unmarshal yaml template")
19
jsonBin, err := json.Marshal(yamlTemplate)
20
require.Nil(t, err, "failed to marshal template to json")
21
var jsonTemplate Template
22
err = json.Unmarshal(jsonBin, &jsonTemplate)
23
require.Nil(t, err, "failed to unmarshal json template")
24
25
templatePath = "./tests/json-template.json"
26
bin, err = os.ReadFile(templatePath)
27
require.Nil(t, err, "failed to load example template")
28
jsonTemplate = Template{}
29
err = json.Unmarshal(bin, &jsonTemplate)
30
require.Nil(t, err, "failed to unmarshal json template")
31
yamlBin, err := yaml.Marshal(jsonTemplate)
32
require.Nil(t, err, "failed to marshal template to yaml")
33
yamlTemplate = Template{}
34
err = yaml.Unmarshal(yamlBin, &yamlTemplate)
35
require.Nil(t, err, "failed to unmarshal yaml template")
36
}
37
38