-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
- Loading branch information
1 parent
a8e7c14
commit bef8f20
Showing
3 changed files
with
71 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package journal | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
) | ||
|
||
func TestJournal(t *testing.T) { | ||
type input struct { | ||
msg string | ||
args []any | ||
} | ||
tests := map[string]struct { | ||
want []Entry | ||
inputs []input | ||
}{ | ||
"empty": { | ||
want: []Entry{}, | ||
}, | ||
"single": { | ||
want: []Entry{ | ||
{ | ||
Msg: "one", | ||
Args: map[string]any{"key": "value"}, | ||
Source: slog.Source{ | ||
File: "journal_test.go", | ||
Function: "func1()", | ||
}, | ||
}, | ||
}, | ||
inputs: []input{ | ||
{msg: "one", args: []any{"key", "value"}}, | ||
}, | ||
}, | ||
"non normal key": { | ||
want: []Entry{ | ||
{ | ||
Msg: "msg", | ||
Args: map[string]any{"1.1": "value"}, | ||
Source: slog.Source{ | ||
File: "journal_test.go", | ||
Function: "func1()", | ||
}, | ||
}, | ||
}, | ||
inputs: []input{ | ||
{msg: "msg", args: []any{1.1, "value"}}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
ctx := New(context.Background()) | ||
for _, input := range tc.inputs { | ||
Log(ctx, input.msg, input.args...) | ||
} | ||
got := Journal(ctx) | ||
if diff := cmp.Diff(tc.want, got, cmpopts.IgnoreFields(Entry{}, "Time"), cmpopts.IgnoreFields(slog.Source{}, "Line")); diff != "" { | ||
t.Errorf("unexpected journal (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
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