generated from LinuxSuRen/github-go
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support setting proxy and provider for setup sub-command (#397)
- Loading branch information
1 parent
8f63471
commit 957c061
Showing
4 changed files
with
124 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package log_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"testing" | ||
|
||
"github.com/linuxsuren/http-downloader/pkg/log" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLogger(t *testing.T) { | ||
t.Run("default level", func(t *testing.T) { | ||
logger := log.GetLoggerFromContextOrDefault(&fakeContextAwareObj{}) | ||
assert.Equal(t, 3, logger.GetLevel()) | ||
|
||
logger = log.GetLoggerFromContextOrDefault(&fakeContextAwareObj{ctx: context.Background()}) | ||
assert.Equal(t, 3, logger.GetLevel()) | ||
|
||
ctx := log.NewContextWithLogger(context.Background(), 5) | ||
logger = log.GetLoggerFromContextOrDefault(&fakeContextAwareObj{ctx: ctx}) | ||
assert.Equal(t, 5, logger.GetLevel()) | ||
}) | ||
|
||
t.Run("print in different level", func(t *testing.T) { | ||
buf := new(bytes.Buffer) | ||
logger := log.GetLogger().SetOutput(buf) | ||
|
||
logger.Debug("debug") | ||
logger.Info("info") | ||
|
||
assert.Contains(t, buf.String(), "info") | ||
|
||
logger.SetLevel(7) | ||
logger.Debug("debug") | ||
assert.Contains(t, buf.String(), "debug") | ||
}) | ||
} | ||
|
||
type fakeContextAwareObj struct { | ||
ctx context.Context | ||
} | ||
|
||
func (f *fakeContextAwareObj) Context() context.Context { | ||
return f.ctx | ||
} |