Created
December 29, 2024 12:38
-
-
Save ivankatliarchuk/f29437ffd84032fed41a5b5da92052e2 to your computer and use it in GitHub Desktop.
log-rus-how-to-test-log-Fatalf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"testing" | |
log "github.com/sirupsen/logrus" | |
"github.com/stretchr/testify/assert" | |
) | |
func TestEncryptionFailed(t *testing.T) { | |
defer func() { log.StandardLogger().ExitFunc = nil }() | |
b := new(bytes.Buffer) | |
var fatalCrash bool | |
log.StandardLogger().ExitFunc = func(int) { fatalCrash = true } | |
log.StandardLogger().SetOutput(b) | |
// contains log.log.Fatalf("Failed to encrypt the text %#v ", err) | |
_ = foo.Serialize(false, true, []byte("wrong-key")) | |
suite.True(fatalCrash, "should fail if encryption key is wrong") | |
suite.Contains(b.String(), "Failed to encrypt the text") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment