github.com/go-chef/chef@v0.30.1/reader_test.go (about)

     1  package chef
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  	"testing"
     7  )
     8  
     9  type TestEncoder struct {
    10  	Name       string
    11  	Awesome    []string
    12  	OtherStuff map[string]string
    13  }
    14  
    15  func TestEncoderJSONReader(t *testing.T) {
    16  	f, err := os.CreateTemp("test/", "reader")
    17  	if err != nil {
    18  		t.Error(err)
    19  	}
    20  
    21  	defer f.Close()
    22  	defer os.Remove(f.Name())
    23  
    24  	tr := &TestEncoder{
    25  		Name:    "Test Reader",
    26  		Awesome: []string{"foo", "bar", "baz"},
    27  		OtherStuff: map[string]string{
    28  			"foo": "bar",
    29  			"baz": "banana",
    30  		},
    31  	}
    32  
    33  	// Generate body
    34  	body, err := JSONReader(tr)
    35  	if err != nil {
    36  		t.Error(err)
    37  	}
    38  
    39  	t.Log(body)
    40  
    41  	_, err = io.Copy(f, body)
    42  	if err != nil {
    43  		t.Error(err)
    44  	}
    45  }