1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/deprecate/deprecate_test.go
Carlos Alexandro Becker f544c5ce69
test: testctx pkg (#3807)
alternative to #3806 

the idea is that both `context.New` and `context.Context{}` are never
used in tests.

not sure yet how much I like it, so far code does look a bit more
readable though.

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2023-03-02 00:01:11 -03:00

44 lines
922 B
Go

package deprecate
import (
"bytes"
"testing"
"github.com/caarlos0/log"
"github.com/charmbracelet/lipgloss"
"github.com/goreleaser/goreleaser/internal/golden"
"github.com/goreleaser/goreleaser/internal/testctx"
"github.com/muesli/termenv"
"github.com/stretchr/testify/require"
)
func TestNotice(t *testing.T) {
lipgloss.SetColorProfile(termenv.Ascii)
var w bytes.Buffer
log.Log = log.New(&w)
log.Info("first")
ctx := testctx.New()
Notice(ctx, "foo.bar.whatever: foobar")
log.Info("last")
require.True(t, ctx.Deprecated)
golden.RequireEqualTxt(t, w.Bytes())
}
func TestNoticeCustom(t *testing.T) {
lipgloss.SetColorProfile(termenv.Ascii)
var w bytes.Buffer
log.Log = log.New(&w)
log.Info("first")
ctx := testctx.New()
NoticeCustom(ctx, "something-else", "some custom template with a url {{ .URL }}")
log.Info("last")
require.True(t, ctx.Deprecated)
golden.RequireEqualTxt(t, w.Bytes())
}