-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call
NewTerraformLogRedirector
for PF
Will fix (probably) pulumi/pulumi-ise#9 <!-- Word order above is to work around GitHub's auto-fix mechanism --!>
- Loading branch information
Showing
3 changed files
with
108 additions
and
7 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,72 @@ | ||
package tfbridgetests | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/providerbuilder" | ||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/pulcheck" | ||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" | ||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" | ||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens" | ||
) | ||
|
||
func TestLogCaputure(t *testing.T) { | ||
originalStdout := os.Stdout | ||
r, w, err := os.Pipe() | ||
require.NoError(t, err) | ||
defer r.Close() | ||
defer w.Close() | ||
os.Stdout = w | ||
defer func() { os.Stdout = originalStdout }() | ||
|
||
t.Setenv("TF_LOG", "WARN") | ||
|
||
provider := info.Provider{ | ||
Name: "test", | ||
Version: "0.0.1", | ||
P: tfbridge.ShimProvider(providerbuilder.NewProvider(providerbuilder.NewProviderArgs{ | ||
TypeName: "test", | ||
AllResources: []providerbuilder.Resource{{ | ||
Name: "res", | ||
ResourceSchema: schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
CreateFunc: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { | ||
require.Empty(t, resp.State.SetAttribute(ctx, path.Root("id"), "1234")) | ||
log.Println("[INFO] This is info") | ||
log.Printf("[WARN] You have been warned") | ||
}, | ||
}}, | ||
})), | ||
MetadataInfo: info.NewProviderMetadata(nil), | ||
} | ||
|
||
provider.MustComputeTokens(tokens.SingleModule("test", "index", tokens.MakeStandard("test"))) | ||
|
||
pt, err := pulcheck.PulCheck(t, provider, ` | ||
name: test | ||
runtime: yaml | ||
resources: | ||
mainRes: | ||
type: test:Res | ||
`) | ||
|
||
require.NoError(t, err) | ||
result := pt.Up(t) | ||
|
||
assert.NotContains(t, result.StdOut, "This is info") | ||
assert.Contains(t, result.StdOut, "You have been warned") | ||
} |
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