2021-06-30 18:39:01 +05:30
|
|
|
package loader
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestLoadTemplates(t *testing.T) {
|
|
|
|
|
store, err := New(&Config{
|
|
|
|
|
Templates: []string{"cves/CVE-2021-21315.yaml"},
|
|
|
|
|
})
|
|
|
|
|
require.Nil(t, err, "could not load templates")
|
|
|
|
|
require.Equal(t, []string{"cves/CVE-2021-21315.yaml"}, store.finalTemplates, "could not get correct templates")
|
|
|
|
|
|
2021-07-02 15:46:42 +05:30
|
|
|
templatesDirectory := "/test"
|
2021-06-30 18:39:01 +05:30
|
|
|
t.Run("blank", func(t *testing.T) {
|
|
|
|
|
store, err := New(&Config{
|
2021-07-02 15:46:42 +05:30
|
|
|
TemplatesDirectory: templatesDirectory,
|
2021-06-30 18:39:01 +05:30
|
|
|
})
|
|
|
|
|
require.Nil(t, err, "could not load templates")
|
2021-07-02 15:46:42 +05:30
|
|
|
require.Equal(t, []string{templatesDirectory}, store.finalTemplates, "could not get correct templates")
|
2021-06-30 18:39:01 +05:30
|
|
|
})
|
|
|
|
|
t.Run("only-tags", func(t *testing.T) {
|
|
|
|
|
store, err := New(&Config{
|
|
|
|
|
Tags: []string{"cves"},
|
2021-07-02 15:46:42 +05:30
|
|
|
TemplatesDirectory: templatesDirectory,
|
2021-06-30 18:39:01 +05:30
|
|
|
})
|
|
|
|
|
require.Nil(t, err, "could not load templates")
|
2021-07-02 15:46:42 +05:30
|
|
|
require.Equal(t, []string{templatesDirectory}, store.finalTemplates, "could not get correct templates")
|
2021-06-30 18:39:01 +05:30
|
|
|
})
|
|
|
|
|
t.Run("tags-with-path", func(t *testing.T) {
|
|
|
|
|
store, err := New(&Config{
|
|
|
|
|
Tags: []string{"cves"},
|
2021-07-02 15:46:42 +05:30
|
|
|
TemplatesDirectory: templatesDirectory,
|
2021-06-30 18:39:01 +05:30
|
|
|
})
|
|
|
|
|
require.Nil(t, err, "could not load templates")
|
2021-07-02 15:46:42 +05:30
|
|
|
require.Equal(t, []string{templatesDirectory}, store.finalTemplates, "could not get correct templates")
|
2021-06-30 18:39:01 +05:30
|
|
|
})
|
|
|
|
|
}
|