mirror of https://github.com/databricks/cli.git
add generic test for all event types
This commit is contained in:
parent
2eb3344edb
commit
3cc7393e1a
|
@ -3,6 +3,7 @@ package telemetry_test
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ import (
|
||||||
"github.com/databricks/cli/libs/telemetry"
|
"github.com/databricks/cli/libs/telemetry"
|
||||||
"github.com/databricks/cli/libs/telemetry/events"
|
"github.com/databricks/cli/libs/telemetry/events"
|
||||||
"github.com/databricks/databricks-sdk-go/client"
|
"github.com/databricks/databricks-sdk-go/client"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -31,6 +33,31 @@ func (wrapper *apiClientWrapper) Do(ctx context.Context, method, path string,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTelemetryLogger(t *testing.T) {
|
func TestTelemetryLogger(t *testing.T) {
|
||||||
|
events := []telemetry.FrontendLogEntry{
|
||||||
|
{
|
||||||
|
DatabricksCliLog: telemetry.DatabricksCliLog{
|
||||||
|
CliTestEvent: &events.CliTestEvent{
|
||||||
|
Name: events.DummyCliEnumValue1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
DatabricksCliLog: telemetry.DatabricksCliLog{
|
||||||
|
BundleInitEvent: &events.BundleInitEvent{
|
||||||
|
Uuid: uuid.New().String(),
|
||||||
|
TemplateName: "abc",
|
||||||
|
TemplateEnumArgs: map[string]string{
|
||||||
|
"a": "b",
|
||||||
|
"c": "d",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, reflect.TypeOf(telemetry.DatabricksCliLog{}).NumField(), len(events),
|
||||||
|
"Number of events should match the number of fields in DatabricksCliLog. Please add a new event to this test.")
|
||||||
|
|
||||||
ctx, w := acc.WorkspaceTest(t)
|
ctx, w := acc.WorkspaceTest(t)
|
||||||
ctx = telemetry.ContextWithLogger(ctx)
|
ctx = telemetry.ContextWithLogger(ctx)
|
||||||
|
|
||||||
|
@ -40,23 +67,10 @@ func TestTelemetryLogger(t *testing.T) {
|
||||||
telemetry.MaxAdditionalWaitTime = 2 * time.Second
|
telemetry.MaxAdditionalWaitTime = 2 * time.Second
|
||||||
})
|
})
|
||||||
|
|
||||||
// Log some events.
|
for _, event := range events {
|
||||||
err := telemetry.Log(ctx, telemetry.FrontendLogEntry{
|
err := telemetry.Log(ctx, event)
|
||||||
DatabricksCliLog: telemetry.DatabricksCliLog{
|
require.NoError(t, err)
|
||||||
CliTestEvent: &events.CliTestEvent{
|
}
|
||||||
Name: events.DummyCliEnumValue1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
err = telemetry.Log(ctx, telemetry.FrontendLogEntry{
|
|
||||||
DatabricksCliLog: telemetry.DatabricksCliLog{
|
|
||||||
CliTestEvent: &events.CliTestEvent{
|
|
||||||
Name: events.DummyCliEnumValue2,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
apiClient, err := client.New(w.W.Config)
|
apiClient, err := client.New(w.W.Config)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -69,7 +83,7 @@ func TestTelemetryLogger(t *testing.T) {
|
||||||
|
|
||||||
// Assert that the events were logged.
|
// Assert that the events were logged.
|
||||||
assert.Equal(t, telemetry.ResponseBody{
|
assert.Equal(t, telemetry.ResponseBody{
|
||||||
NumProtoSuccess: 2,
|
NumProtoSuccess: int64(len(events)),
|
||||||
Errors: []telemetry.LogError{},
|
Errors: []telemetry.LogError{},
|
||||||
}, *wrapper.response)
|
}, *wrapper.response)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue