github.com/zuoyebang/bitalostable@v1.0.1-0.20240229032404-e3b99a834294/internal/metamorphic/history_test.go (about)

     1  // Copyright 2019 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  package metamorphic
     6  
     7  import (
     8  	"bytes"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestHistoryLogger(t *testing.T) {
    15  	var buf bytes.Buffer
    16  	h := newHistory("", &buf)
    17  	h.Infof("hello\nworld\n")
    18  	h.Fatalf("hello\n\nworld")
    19  
    20  	expected := `// INFO: hello
    21  // INFO: world
    22  // FATAL: hello
    23  // FATAL: 
    24  // FATAL: world
    25  `
    26  	if actual := buf.String(); expected != actual {
    27  		t.Fatalf("expected\n%s\nbut found\n%s", expected, actual)
    28  	}
    29  }
    30  
    31  func TestHistoryFail(t *testing.T) {
    32  	var buf bytes.Buffer
    33  	h := newHistory("foo", &buf)
    34  	h.Recordf("bar")
    35  	require.NoError(t, h.Error())
    36  	h.Recordf("foo bar")
    37  	require.EqualError(t, h.Error(), `failure regexp "foo" matched output: foo bar #2`)
    38  }