package pijul
import (
"reflect"
"testing"
"time"
)
var changeHeaderTests = []struct {
toml string
parsed ChangeHeader
}{
{
`message = ''
timestamp = '2023-03-24T17:52:08.476452868Z'
authors = []
`,
ChangeHeader{
Timestamp: time.Date(2023, 3, 24, 17, 52, 8, 476452868, time.UTC),
Authors: []map[string]string{},
},
},
{
`message = 'Add some gibberish'
timestamp = '2023-03-24T17:52:08.476298107Z'
[[authors]]
key = 'BCEXYuKWaQ96btsk8UyBZWHLjn1Brhykv8tuZGPRjzFn'`,
ChangeHeader{
Message: "Add some gibberish",
Timestamp: time.Date(2023, 3, 24, 17, 52, 8, 476298107, time.UTC),
Authors: []map[string]string{
{
"key": "BCEXYuKWaQ96btsk8UyBZWHLjn1Brhykv8tuZGPRjzFn",
},
},
},
},
}
func TestChangeHeaderParsing(t *testing.T) {
for i, c := range changeHeaderTests {
parsed, err := ParseChangeHeader([]byte(c.toml))
if err != nil {
t.Fatalf("Error parsing case %d: %v", i, err)
}
if !reflect.DeepEqual(parsed, c.parsed) {
t.Fatalf("got %#v, want %#v", parsed, c.parsed)
}
}
}