-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: various small tests & optimizations
Signed-off-by: Jakob Möller <jmoller@redhat.com>
- Loading branch information
1 parent
ba4f9ac
commit 8298e9e
Showing
14 changed files
with
86 additions
and
38 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
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
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
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,57 @@ | ||
package lvm2go_test | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"log/slog" | ||
"testing" | ||
|
||
. "github.com/jakobmoellerdev/lvm2go" | ||
) | ||
|
||
func TestNewContextPropagatingSlogHandler(t *testing.T) { | ||
SkipOrFailTestIfNotRoot(t) | ||
stdout := &bytes.Buffer{} | ||
var loggingHandler slog.Handler | ||
loggingHandler = slog.NewJSONHandler(stdout, &slog.HandlerOptions{ | ||
Level: slog.LevelDebug, | ||
AddSource: true, | ||
}) | ||
loggingHandler = NewContextPropagatingSlogHandler(loggingHandler) | ||
slog.SetDefault(slog.New(loggingHandler)) | ||
ctx := context.Background() | ||
|
||
lvm := NewClient() | ||
if _, err := lvm.Version(ctx); err != nil { | ||
t.Errorf("Error: %v", err) | ||
} | ||
|
||
lineReader := bufio.NewScanner(stdout) | ||
var lines []map[string]any | ||
for lineReader.Scan() { | ||
line := make(map[string]any) | ||
if err := json.NewDecoder(bytes.NewReader(lineReader.Bytes())).Decode(&line); err != nil { | ||
t.Errorf("Error: %v", err) | ||
} | ||
lines = append(lines, line) | ||
} | ||
if err := lineReader.Err(); err != nil { | ||
t.Errorf("Error: %v", err) | ||
} | ||
if len(lines) == 0 { | ||
t.Errorf("Expected output in logger, got nothing") | ||
} | ||
|
||
foundcommand := false | ||
for _, line := range lines { | ||
if line["command"] != nil && line["msg"] != nil { | ||
foundcommand = true | ||
break | ||
} | ||
} | ||
if !foundcommand { | ||
t.Errorf("Expected command in logger output, got nothing") | ||
} | ||
} |
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
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