support ledger file append
This commit is contained in:
71
upload_test.go
Normal file
71
upload_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"local/storage"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestUploadLedger(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
transaction Transaction
|
||||
}{
|
||||
"simple": {
|
||||
transaction: Transaction{
|
||||
ID: uuid.New().String(),
|
||||
Bank: Chase,
|
||||
Amount: "1.10",
|
||||
Account: "account",
|
||||
Date: "today",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, d := range cases {
|
||||
c := d
|
||||
t.Run(name, func(t *testing.T) {
|
||||
config := Config{
|
||||
TodoAddr: path.Join(t.TempDir(), name),
|
||||
Uploader: UploaderLedger,
|
||||
Storage: storage.NewMap(),
|
||||
}
|
||||
if err := uploadLedger(config, &c.transaction); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := ioutil.ReadFile(config.TodoAddr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("\n%s", b)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatGMailDate(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
"ok": {
|
||||
input: "[Tue, 20 Jul 2021 23:46:00 -0400 (EDT)]",
|
||||
want: "2021-07-20",
|
||||
},
|
||||
"bad": {
|
||||
input: "2021-07-20",
|
||||
want: "2021-07-20",
|
||||
},
|
||||
}
|
||||
|
||||
for name, d := range cases {
|
||||
c := d
|
||||
t.Run(name, func(t *testing.T) {
|
||||
got := formatGMailDate(c.input)
|
||||
if got != c.want {
|
||||
t.Fatal(c.input, c.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user