github.phpd.cn/goreleaser/goreleaser@v0.92.0/internal/deprecate/deprecate_test.go (about)

     1  package deprecate
     2  
     3  import (
     4  	"flag"
     5  	"io/ioutil"
     6  	"testing"
     7  
     8  	"github.com/apex/log"
     9  	"github.com/apex/log/handlers/cli"
    10  	"github.com/fatih/color"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  var update = flag.Bool("update", false, "update .golden files")
    15  
    16  func TestNotice(t *testing.T) {
    17  	f, err := ioutil.TempFile("", "output.txt")
    18  	require.NoError(t, err)
    19  
    20  	color.NoColor = true
    21  	log.SetHandler(cli.New(f))
    22  
    23  	log.Info("first")
    24  	Notice("foo.bar.whatever")
    25  	log.Info("last")
    26  
    27  	require.NoError(t, f.Close())
    28  
    29  	bts, err := ioutil.ReadFile(f.Name())
    30  	require.NoError(t, err)
    31  
    32  	const golden = "testdata/output.txt.golden"
    33  	if *update {
    34  		require.NoError(t, ioutil.WriteFile(golden, bts, 0655))
    35  	}
    36  
    37  	gbts, err := ioutil.ReadFile(golden)
    38  	require.NoError(t, err)
    39  
    40  	require.Equal(t, string(gbts), string(bts))
    41  }