github.com/lelinu/go-google-charts@v1.0.5/src/services/org_chart_service_test.go (about)

     1  package services
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"github.com/lelinu/go-google-charts/src/utils"
     7  	"github.com/stretchr/testify/assert"
     8  	"os"
     9  	"path"
    10  	"runtime"
    11  	"testing"
    12  )
    13  
    14  var (
    15  	renderName      = "org-chart"
    16  	orgChartService IOrgChartService
    17  )
    18  
    19  func TestMain(m *testing.M) {
    20  	orgChartService = NewOrgChartService()
    21  
    22  	_, filename, _, _ := runtime.Caller(0)
    23  	dir := path.Join(path.Dir(filename), "../")
    24  	fmt.Printf("dir is %v", dir)
    25  	err := os.Chdir(dir)
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  
    30  	os.Exit(m.Run())
    31  }
    32  
    33  func TestRenderToWriterValidBytes(t *testing.T) {
    34  
    35  	data, err := utils.BuildJson()
    36  	assert.Nil(t, err)
    37  	assert.NotNil(t, data)
    38  
    39  	var buf bytes.Buffer
    40  	obj := map[string]string{"jsonData": data}
    41  	err = orgChartService.RenderToWriter(obj, renderName, &buf)
    42  
    43  	assert.Nil(t, err)
    44  	assert.NotNil(t, buf)
    45  	assert.NotNil(t, buf.Bytes())
    46  	assert.Greater(t, len(buf.Bytes()), 0)
    47  }
    48