-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2023 The go-ethereum Authors | ||
// This file is part of go-ethereum. | ||
// | ||
// go-ethereum is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// go-ethereum is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/docker/docker/pkg/reexec" | ||
) | ||
|
||
func runSelf(args ...string) ([]byte, error) { | ||
cmd := &exec.Cmd{ | ||
Path: reexec.Self(), | ||
Args: append([]string{"geth-test"}, args...), | ||
} | ||
return cmd.CombinedOutput() | ||
} | ||
|
||
func split(input io.Reader) []string { | ||
var output []string | ||
scanner := bufio.NewScanner(input) | ||
scanner.Split(bufio.ScanLines) | ||
for scanner.Scan() { | ||
output = append(output, scanner.Text()) | ||
} | ||
return output | ||
} | ||
|
||
func censor(input string, start, end int) string { | ||
if len(input) < end { | ||
return input | ||
} | ||
return input[:start] + strings.Repeat("X", end-start) + input[end:] | ||
} | ||
|
||
func TestLogging(t *testing.T) { | ||
testConsoleLogging(t, "terminal", 6, 24) | ||
testConsoleLogging(t, "logfmt", 2, 26) | ||
} | ||
|
||
func testConsoleLogging(t *testing.T, format string, tStart, tEnd int) { | ||
haveB, err := runSelf("--log.format", format, "logtest") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
readFile, err := os.Open(fmt.Sprintf("testdata/logging/logtest-%v.txt", format)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
wantLines := split(readFile) | ||
haveLines := split(bytes.NewBuffer(haveB)) | ||
for i, want := range wantLines { | ||
if i > len(haveLines)-1 { | ||
t.Fatalf("format %v, line %d missing, want:%v", format, i, want) | ||
} | ||
have := haveLines[i] | ||
// Black out the timestamp | ||
have = censor(have, tStart, tEnd) | ||
want = censor(want, tStart, tEnd) | ||
if have != want { | ||
t.Fatalf("format %v, line %d\nhave %v\nwant %v", format, i, have, want) | ||
} | ||
} | ||
if len(haveLines) != len(wantLines) { | ||
t.Errorf("format %v, want %d lines, have %d", format, len(haveLines), len(wantLines)) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
t=2023-10-18T11:29:46+0200 lvl=info msg="Output testing started" big.Int=111,222,333,444,555,678,999 -big.Int=-111,222,333,444,555,678,999 big.Int=11,122,233,344,455,567,899,900 -big.Int=-11,122,233,344,455,567,899,900 | ||
t=2023-10-18T11:29:46+0200 lvl=info msg="Testing uint256" uint256.Int=111,222,333,444,555,678,999 uint256.Int=11,122,233,344,455,567,899,900 | ||
t=2023-10-18T11:29:46+0200 lvl=info msg="Special chars" "special \r\n\t chars"="special \r\n\t chars" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
INFO [XXXXXXXXXXXXXXXXXX] Output testing started big.Int=111,222,333,444,555,678,999 -big.Int=-111,222,333,444,555,678,999 big.Int=11,122,233,344,455,567,899,900 -big.Int=-11,122,233,344,455,567,899,900 | ||
INFO [XXXXXXXXXXXXXXXXXX] Testing uint256 uint256.Int=111,222,333,444,555,678,999 uint256.Int=11,122,233,344,455,567,899,900 | ||
INFO [XXXXXXXXXXXXXXXXXX] Special chars "special \r\n\t chars"="special \r\n\t chars" |