-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. Improved documentation 3. Added to all facades a `Unwrap() [T]` method.
- Loading branch information
Showing
25 changed files
with
787 additions
and
28 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
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,80 @@ | ||
package value | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/echocat/slf4g/internal/test/assert" | ||
"github.com/echocat/slf4g/native/consumer" | ||
) | ||
|
||
func Test_NewConsumer_setDefaultConsumer(t *testing.T) { | ||
givenTarget := &mockConsumerTarget{} | ||
|
||
instance := NewConsumer(givenTarget) | ||
|
||
assert.ToBeNotNil(t, instance) | ||
assert.ToBeSame(t, consumer.Default, givenTarget.consumer) | ||
assert.ToBeSame(t, givenTarget.consumer, instance.Formatter.Target) | ||
} | ||
|
||
func Test_NewConsumer_setFallbackConsumer(t *testing.T) { | ||
old := consumer.Default | ||
defer func() { | ||
consumer.Default = old | ||
}() | ||
consumer.Default = nil | ||
|
||
givenTarget := &mockConsumerTarget{} | ||
|
||
instance := NewConsumer(givenTarget) | ||
|
||
assert.ToBeNotNil(t, instance) | ||
assert.ToBeEqual(t, consumer.NewWriter(os.Stderr), givenTarget.consumer) | ||
assert.ToBeSame(t, givenTarget.consumer, instance.Formatter.Target) | ||
} | ||
|
||
func Test_NewConsumer_usingExisting(t *testing.T) { | ||
givenConsumer := consumer.NewWriter(os.Stderr) | ||
givenTarget := &mockConsumerTarget{ | ||
consumer: givenConsumer, | ||
} | ||
|
||
instance := NewConsumer(givenTarget) | ||
|
||
assert.ToBeNotNil(t, instance) | ||
assert.ToBeSame(t, givenConsumer, givenTarget.consumer) | ||
assert.ToBeSame(t, givenTarget.consumer, instance.Formatter.Target) | ||
} | ||
|
||
func Test_NewConsumer_customize(t *testing.T) { | ||
givenTarget := &mockConsumerTarget{} | ||
instance := NewConsumer(givenTarget, func(c *Consumer) { | ||
c.Formatter.Codec = NoopFormatterCodec() | ||
}) | ||
|
||
assert.ToBeNotNil(t, instance) | ||
assert.ToBeSame(t, NoopFormatterCodec(), instance.Formatter.Codec) | ||
} | ||
|
||
func Test_NewConsumer_panicsOnIncompatible(t *testing.T) { | ||
givenTarget := &mockConsumerTarget{ | ||
consumer: consumer.NewRecorder(), | ||
} | ||
|
||
assert.Execution(t, func() { | ||
NewConsumer(givenTarget) | ||
}).WillPanicWith("^\\*consumer\\.Recorder does not implement formatter\\.MutableAware$") | ||
} | ||
|
||
type mockConsumerTarget struct { | ||
consumer consumer.Consumer | ||
} | ||
|
||
func (instance *mockConsumerTarget) GetConsumer() consumer.Consumer { | ||
return instance.consumer | ||
} | ||
|
||
func (instance *mockConsumerTarget) SetConsumer(v consumer.Consumer) { | ||
instance.consumer = v | ||
} |
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,15 @@ | ||
// Package value provides a value facade for native.Provider to be able | ||
// to easy be configured using flag libraries like the SDK implementation | ||
// or other compatible ones. It implements encoding.TextMarshaler and | ||
// encoding.TextUnmarshaler, too. | ||
// | ||
// Example: | ||
// pv := value.NewProvider(native.DefaultProvider) | ||
// | ||
// flag.Var(pv.Consumer.Formatter, "log.format", "Configures the log format.") | ||
// flag.Var(pv.Level, "log.level", "Configures the log level.") | ||
// | ||
// flag.Parse() | ||
// Now you can call: | ||
// $ <myExecutable> -log.format=json -log.level=debug ... | ||
package value |
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
Oops, something went wrong.