Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer using raw fixtures in testing #74

Merged
merged 4 commits into from Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
@@ -1,2 +1,6 @@
node_modules
website-preview
website-preview

# Jetbrains IDEs
.idea/
*.iws
17 changes: 8 additions & 9 deletions tflog/options_test.go
Expand Up @@ -7,7 +7,6 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/terraform-plugin-log/internal/loggertest"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -33,8 +32,8 @@ func TestWithAdditionalLocationOffset(t *testing.T) {
{
// Caller line (number after colon) should match
// tflog.SubsystemTrace() line in test case implementation.
"@caller": "/tflog/options_test.go:30",
"@level": hclog.Trace.String(),
"@caller": "/tflog/options_test.go:29",
"@level": "trace",
"@message": "test message",
"@module": testSubsystemModule,
},
Expand All @@ -50,8 +49,8 @@ func TestWithAdditionalLocationOffset(t *testing.T) {
// Caller line (number after colon) should match
// tflog.SubsystemTrace() line in testSubsystemTraceHelper
// function implementation.
"@caller": "/tflog/options_test.go:16",
"@level": hclog.Trace.String(),
"@caller": "/tflog/options_test.go:15",
"@level": "trace",
"@message": "test message",
"@module": testSubsystemModule,
},
Expand All @@ -67,8 +66,8 @@ func TestWithAdditionalLocationOffset(t *testing.T) {
// Caller line (number after colon) should match
// testSubsystemTraceHelper() line in test case
// implementation.
"@caller": "/tflog/options_test.go:63",
"@level": hclog.Trace.String(),
"@caller": "/tflog/options_test.go:62",
"@level": "trace",
"@message": "test message",
"@module": testSubsystemModule,
},
Expand Down Expand Up @@ -137,7 +136,7 @@ func TestWithRootFields(t *testing.T) {
logMessage: "test message",
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Trace.String(),
"@level": "trace",
"@message": "test message",
"@module": testSubsystemModule,
"test-subsystem-key": "test-subsystem-value",
Expand All @@ -154,7 +153,7 @@ func TestWithRootFields(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Trace.String(),
"@level": "trace",
"@message": "test message",
"@module": testSubsystemModule,
"test-root-key": "test-root-value",
Expand Down
51 changes: 25 additions & 26 deletions tflog/provider_test.go
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/terraform-plugin-log/internal/loggertest"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -15,19 +14,19 @@ func TestWith(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
key string
value interface{}
logMessage string
logadditionalFields []map[string]interface{}
expectedOutput []map[string]interface{}
key string
value interface{}
logMessage string
additionalFields []map[string]interface{}
expectedOutput []map[string]interface{}
}{
"no-log-fields": {
key: "test-with-key",
value: "test-with-value",
logMessage: "test message",
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Trace.String(),
"@level": "trace",
"@message": "test message",
"@module": "provider",
"test-with-key": "test-with-value",
Expand All @@ -39,7 +38,7 @@ func TestWith(t *testing.T) {
logMessage: "test message",
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Trace.String(),
"@level": "trace",
"@message": "test message",
"@module": "provider",
"unfielded-test-with-key": nil,
Expand All @@ -50,7 +49,7 @@ func TestWith(t *testing.T) {
key: "test-with-key",
value: "test-with-value",
logMessage: "test message",
logadditionalFields: []map[string]interface{}{
additionalFields: []map[string]interface{}{
{
"test-log-key-1": "test-log-value-1",
"test-log-key-2": "test-log-value-2",
Expand All @@ -59,7 +58,7 @@ func TestWith(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Trace.String(),
"@level": "trace",
"@message": "test message",
"@module": "provider",
"test-log-key-1": "test-log-value-1",
Expand All @@ -83,7 +82,7 @@ func TestWith(t *testing.T) {
ctx = loggertest.ProviderRoot(ctx, &outputBuffer)
ctx = tflog.With(ctx, testCase.key, testCase.value)

tflog.Trace(ctx, testCase.logMessage, testCase.logadditionalFields...)
tflog.Trace(ctx, testCase.logMessage, testCase.additionalFields...)

got, err := loggertest.MultilineJSONDecode(&outputBuffer)

Expand All @@ -110,7 +109,7 @@ func TestTrace(t *testing.T) {
message: "test message",
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Trace.String(),
"@level": "trace",
"@message": "test message",
"@module": "provider",
},
Expand All @@ -127,7 +126,7 @@ func TestTrace(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Trace.String(),
"@level": "trace",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1",
Expand All @@ -152,7 +151,7 @@ func TestTrace(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Trace.String(),
"@level": "trace",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1-map2",
Expand Down Expand Up @@ -203,7 +202,7 @@ func TestDebug(t *testing.T) {
message: "test message",
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Debug.String(),
"@level": "debug",
"@message": "test message",
"@module": "provider",
},
Expand All @@ -220,7 +219,7 @@ func TestDebug(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Debug.String(),
"@level": "debug",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1",
Expand All @@ -245,7 +244,7 @@ func TestDebug(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Debug.String(),
"@level": "debug",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1-map2",
Expand Down Expand Up @@ -296,7 +295,7 @@ func TestInfo(t *testing.T) {
message: "test message",
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Info.String(),
"@level": "info",
"@message": "test message",
"@module": "provider",
},
Expand All @@ -313,7 +312,7 @@ func TestInfo(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Info.String(),
"@level": "info",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1",
Expand All @@ -338,7 +337,7 @@ func TestInfo(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Info.String(),
"@level": "info",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1-map2",
Expand Down Expand Up @@ -389,7 +388,7 @@ func TestWarn(t *testing.T) {
message: "test message",
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Warn.String(),
"@level": "warn",
"@message": "test message",
"@module": "provider",
},
Expand All @@ -406,7 +405,7 @@ func TestWarn(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Warn.String(),
"@level": "warn",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1",
Expand All @@ -431,7 +430,7 @@ func TestWarn(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Warn.String(),
"@level": "warn",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1-map2",
Expand Down Expand Up @@ -482,7 +481,7 @@ func TestError(t *testing.T) {
message: "test message",
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Error.String(),
"@level": "error",
"@message": "test message",
"@module": "provider",
},
Expand All @@ -499,7 +498,7 @@ func TestError(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Error.String(),
"@level": "error",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1",
Expand All @@ -524,7 +523,7 @@ func TestError(t *testing.T) {
},
expectedOutput: []map[string]interface{}{
{
"@level": hclog.Error.String(),
"@level": "error",
"@message": "test message",
"@module": "provider",
"test-key-1": "test-value-1-map2",
Expand Down