package import_svc

import (
	"context"
	"errors"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/tidbcloud/pkgv2/bizerr"
	"github.com/tidbcloud/serverless-service/internal/errorcode"
)

func TestImportFailureMessage(t *testing.T) {
	t.Run("keeps actionable message without error internals", func(t *testing.T) {
		err := bizerr.New(bizerr.ErrCodeParams, "invalid storage URI")

		got := importFailureMessage(context.Background(), err)

		assert.Equal(t, "invalid storage URI", got)
		assert.NotContains(t, got, "code=")
	})

	t.Run("redacts internal details", func(t *testing.T) {
		err := errors.New("credential secret at 10.0.0.1")

		got := importFailureMessage(context.Background(), err)

		assert.Equal(t, errorcode.InternalErrorMessage, got)
		assert.NotContains(t, got, "secret")
		assert.NotContains(t, got, "10.0.0.1")
	})
}
