-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
bridgetest
and bridgetest.InitLogging
This allows modules outside of the bridge to test code that uses `tfbridge.GetLogger`. This will be used by `dynamic`. It may also be used by AWS, which currently has test code which uses the now moved-to-internal logging.InitContext.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# bridgetest | ||
|
||
The `bridgetest` module adds facilities for providers to use when testing bridge | ||
integrations. Nothing in this module should be depended on for runtime functionality. |
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 @@ | ||
package bridgetest | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/pulumi/pulumi/sdk/v3/go/common/diag" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" | ||
|
||
"github.com/pulumi/pulumi-terraform-bridge/v3/internal/logging" | ||
) | ||
|
||
// A sink that [tfbridge.GetLogger] can write to. | ||
type LoggingSink interface { | ||
Log(context context.Context, sev diag.Severity, urn resource.URN, msg string) error | ||
LogStatus(context context.Context, sev diag.Severity, urn resource.URN, msg string) error | ||
} | ||
|
||
type discardSink struct{} | ||
|
||
func (*discardSink) Log(context.Context, diag.Severity, resource.URN, string) error { | ||
return nil | ||
} | ||
|
||
func (*discardSink) LogStatus(context.Context, diag.Severity, resource.URN, string) error { | ||
return nil | ||
} | ||
|
||
// InitLogging equips ctx with a logger usable by [tfbridge.GetLogger]. | ||
// | ||
//nolint:revive // Let t come before ctx. | ||
func InitLogging(t *testing.T, ctx context.Context, sink LoggingSink) context.Context { | ||
contract.Assertf(t != nil, "t cannot be nil") | ||
if sink == nil { | ||
sink = &discardSink{} | ||
} | ||
return logging.InitLogging(ctx, logging.LogOptions{LogSink: sink}) | ||
} |