nuclei/pkg/templates/templates_test.go

37 lines
1.1 KiB
Go
Raw Normal View History

package templates
2023-02-21 20:54:45 +00:00
import (
"encoding/json"
"os"
"testing"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)
func TestTemplateStruct(t *testing.T) {
2023-02-27 09:55:37 +00:00
templatePath := "./tests/match-1.yaml"
2023-02-21 20:54:45 +00:00
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")
2023-02-27 09:55:37 +00:00
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")
2023-02-21 20:54:45 +00:00
}