aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/meta_test.go
blob: 04ad22bd1887c6e406920b2f164ee107a23ae465 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package feed

import (
  "bytes"
  "encoding/json"
  "testing"
)

// test data
const testMeta = `lastModifiedDate:2022-01-29T03:01:16-05:00
size:73202582
zipSize:3753799
gzSize:3753663
sha256:B86258D5D9861507A1894A7B92011764803D7267787B1487539E240EA2405440
`

// Test meta parser
func TestNewMeta(t *testing.T) {
  t.Run("NewMeta", func(t *testing.T) {
    // create buffer
    buf := bytes.NewBufferString(testMeta)

    // decode meta, check for error
    _, err := NewMeta(buf)
    if err != nil {
      t.Error(err)
    }
  })

  t.Run("JsonEncode", func(t *testing.T) {
    // create buffer
    buf := bytes.NewBufferString(testMeta)

    // decode meta, check for error
    meta, err := NewMeta(buf)
    if err != nil {
      t.Error(err)
    }

    // create destination buffer
    var dst bytes.Buffer

    // create json encoder
    e := json.NewEncoder(&dst)
    if err := e.Encode(meta); err != nil {
      t.Error(err)
    }
  })
}