2018-02-17 13:43:29 -02:00
|
|
|
package deprecate
|
|
|
|
|
|
|
|
import (
|
2021-03-01 14:18:57 -03:00
|
|
|
"bytes"
|
2018-02-17 13:43:29 -02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/apex/log/handlers/cli"
|
2018-10-26 18:27:17 -03:00
|
|
|
"github.com/fatih/color"
|
2021-05-30 21:53:40 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/golden"
|
2020-04-12 14:31:35 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2018-10-27 12:59:42 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-02-17 13:43:29 -02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNotice(t *testing.T) {
|
2021-03-01 14:18:57 -03:00
|
|
|
var w bytes.Buffer
|
2018-10-27 13:27:09 -03:00
|
|
|
|
|
|
|
color.NoColor = true
|
2021-03-01 14:18:57 -03:00
|
|
|
log.SetHandler(cli.New(&w))
|
2018-10-27 12:59:42 -03:00
|
|
|
|
2018-02-17 13:43:29 -02:00
|
|
|
log.Info("first")
|
2021-03-01 14:18:57 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2020-04-12 14:31:35 -03:00
|
|
|
Notice(ctx, "foo.bar.whatever")
|
2018-02-17 13:43:29 -02:00
|
|
|
log.Info("last")
|
2020-04-12 14:31:35 -03:00
|
|
|
require.True(t, ctx.Deprecated)
|
2018-02-17 13:43:29 -02:00
|
|
|
|
2021-05-30 21:53:40 -03:00
|
|
|
golden.RequireEqualTxt(t, w.Bytes())
|
2021-03-01 14:18:57 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNoticeCustom(t *testing.T) {
|
|
|
|
var w bytes.Buffer
|
|
|
|
|
|
|
|
color.NoColor = true
|
|
|
|
log.SetHandler(cli.New(&w))
|
|
|
|
|
|
|
|
log.Info("first")
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
NoticeCustom(ctx, "something-else", "some custom template with a url {{ .URL }}")
|
|
|
|
log.Info("last")
|
|
|
|
require.True(t, ctx.Deprecated)
|
|
|
|
|
2021-05-30 21:53:40 -03:00
|
|
|
golden.RequireEqualTxt(t, w.Bytes())
|
2018-02-17 13:43:29 -02:00
|
|
|
}
|
2021-11-13 22:23:11 -03:00
|
|
|
|
|
|
|
func TestWriter(t *testing.T) {
|
|
|
|
var w bytes.Buffer
|
|
|
|
|
|
|
|
color.NoColor = true
|
|
|
|
log.SetHandler(cli.New(&w))
|
|
|
|
|
|
|
|
log.Info("first")
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
ww := NewWriter(ctx)
|
|
|
|
_, err := ww.Write([]byte("foo bar\n"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ctx.Deprecated)
|
|
|
|
|
|
|
|
golden.RequireEqualTxt(t, w.Bytes())
|
|
|
|
}
|