File: reader_test.go

package info (click to toggle)
golang-github-go-chef-chef 0.0.1%2Bgit20161023.60.deb8c38-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 332 kB
  • ctags: 290
  • sloc: sh: 14; makefile: 7
file content (46 lines) | stat: -rw-r--r-- 660 bytes parent folder | download | duplicates (3)
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
package chef

import (
	"io"
	"io/ioutil"
	"os"
	"testing"
)

type TestEncoder struct {
	Name       string
	Awesome    []string
	OtherStuff map[string]string
}

func TestEncoderJSONReader(t *testing.T) {
	f, err := ioutil.TempFile("test/", "reader")
	if err != nil {
		t.Error(err)
	}

	defer f.Close()
	defer os.Remove(f.Name())

	tr := &TestEncoder{
		Name:    "Test Reader",
		Awesome: []string{"foo", "bar", "baz"},
		OtherStuff: map[string]string{
			"foo": "bar",
			"baz": "banana",
		},
	}

	// Generate body
	body, err := JSONReader(tr)
	if err != nil {
		t.Error(err)
	}

	t.Log(body)

	_, err = io.Copy(f, body)
	if err != nil {
		t.Error(err)
	}
}