-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: allow callers to directly set logfile location (#2545)
Changes `message.UseLogFile` to accept an `f *os.File` and wrap it in a `*message.PausableWriter`. Adds unit tests for `PausableWriter`. ## Related Issue Fixes #2524 ## Checklist before merging - [x] Test, docs, adr added or updated as needed - [x] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow) followed --------- Signed-off-by: razzle <[email protected]>
- Loading branch information
Showing
5 changed files
with
76 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
package message | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPausableWriter(t *testing.T) { | ||
var buf bytes.Buffer | ||
|
||
pw := NewPausableWriter(&buf) | ||
|
||
n, err := pw.Write([]byte("foo")) | ||
require.NoError(t, err) | ||
require.Equal(t, 3, n) | ||
|
||
require.Equal(t, "foo", buf.String()) | ||
|
||
pw.Pause() | ||
|
||
n, err = pw.Write([]byte("bar")) | ||
require.NoError(t, err) | ||
require.Equal(t, 3, n) | ||
|
||
require.Equal(t, "foo", buf.String()) | ||
|
||
pw.Resume() | ||
|
||
n, err = pw.Write([]byte("baz")) | ||
require.NoError(t, err) | ||
require.Equal(t, 3, n) | ||
|
||
require.Equal(t, "foobaz", buf.String()) | ||
} |