2019-08-04 22:42:37 +00:00
|
|
|
package main
|
|
|
|
|
2024-01-29 22:53:59 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
2019-08-04 22:42:37 +00:00
|
|
|
|
|
|
|
func TestStoredFileParse(t *testing.T) {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
file string
|
|
|
|
sFile *storedFile
|
|
|
|
)
|
|
|
|
|
|
|
|
// Case: Proper file with header
|
|
|
|
|
|
|
|
file = `
|
|
|
|
---
|
|
|
|
key: value
|
|
|
|
---
|
|
|
|
|
|
|
|
# Header
|
|
|
|
|
|
|
|
content
|
|
|
|
`
|
|
|
|
|
|
|
|
sFile, err = storedFileFromString(file)
|
2024-01-29 22:53:59 +00:00
|
|
|
require.NoError(t, err)
|
2019-08-04 22:42:37 +00:00
|
|
|
|
2024-01-29 22:53:59 +00:00
|
|
|
assert.Equal(t, "# Header\n\ncontent", sFile.Content)
|
|
|
|
assert.Equal(t, map[string]any{"key": "value"}, sFile.Meta)
|
2019-08-04 22:42:37 +00:00
|
|
|
|
|
|
|
// Case: No header
|
|
|
|
|
|
|
|
file = "# Header\n\ncontent"
|
|
|
|
|
|
|
|
sFile, err = storedFileFromString(file)
|
2024-01-29 22:53:59 +00:00
|
|
|
require.NoError(t, err)
|
2019-08-04 22:42:37 +00:00
|
|
|
|
2024-01-29 22:53:59 +00:00
|
|
|
assert.Equal(t, "# Header\n\ncontent", sFile.Content)
|
|
|
|
assert.Len(t, sFile.Meta, 0)
|
2019-08-04 22:42:37 +00:00
|
|
|
}
|