Do not remove the functionality to print log in test

Signed-off-by: Benoit Tigeot <benoit.tigeot@lifen.fr>
pull/30708/head
Benoit Tigeot 5 months ago
parent b6adbbb227
commit baa597c567
No known key found for this signature in database
GPG Key ID: 8E6D4FC8AEBDA62C

@ -16,9 +16,11 @@ limitations under the License.
package action
import (
"flag"
"fmt"
"io"
"log/slog"
"os"
"testing"
"github.com/stretchr/testify/assert"
@ -37,6 +39,24 @@ import (
func actionConfigFixture(t *testing.T) *Configuration {
t.Helper()
var verbose = flag.Bool("test.log", false, "enable test logging (debug by default)")
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
if *verbose {
// Create a handler that removes timestamps
handler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
// Remove the time attribute
if a.Key == slog.TimeKey {
return slog.Attr{}
}
return a
},
})
logger = slog.New(handler)
}
registryClient, err := registry.NewClient()
if err != nil {
t.Fatal(err)
@ -47,7 +67,7 @@ func actionConfigFixture(t *testing.T) *Configuration {
KubeClient: &kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}},
Capabilities: chartutil.DefaultCapabilities,
RegistryClient: registryClient,
Log: slog.New(slog.NewTextHandler(io.Discard, nil)), // TODO: permit to log in test as before with `var verbose = flag.Bool("test.log", false, "enable test logging")``
Log: logger,
}
}

Loading…
Cancel
Save