2023-04-14 12:40:34 +00:00
|
|
|
package output
|
2023-03-21 15:25:18 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSingleTaskJobOutputToString(t *testing.T) {
|
|
|
|
taskNotebook := NotebookOutput{
|
|
|
|
Result: "foo",
|
|
|
|
Truncated: true,
|
|
|
|
}
|
|
|
|
myJob := JobOutput{
|
|
|
|
TaskOutputs: map[string]RunOutput{
|
|
|
|
"my_notebook_task": &taskNotebook,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
actual, err := myJob.String()
|
|
|
|
require.NoError(t, err)
|
|
|
|
expected := "foo\n[truncated...]\n"
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMultiTaskJobOutputToString(t *testing.T) {
|
|
|
|
taskFoo := NotebookOutput{
|
|
|
|
Result: "foo",
|
|
|
|
Truncated: true,
|
|
|
|
}
|
|
|
|
taskBar := LogsOutput{
|
|
|
|
Logs: "bar",
|
|
|
|
LogsTruncated: false,
|
|
|
|
}
|
|
|
|
myJob := JobOutput{
|
|
|
|
TaskOutputs: map[string]RunOutput{
|
|
|
|
"my_foo_task": &taskFoo,
|
|
|
|
"my_bar_task": &taskBar,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
actual, err := myJob.String()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-04-18 12:40:45 +00:00
|
|
|
expected := `Output:
|
2023-03-21 15:25:18 +00:00
|
|
|
=======
|
|
|
|
Task my_bar_task:
|
|
|
|
bar
|
|
|
|
=======
|
|
|
|
Task my_foo_task:
|
|
|
|
foo
|
|
|
|
[truncated...]
|
|
|
|
|
|
|
|
`
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotebookOutputToRunOutput(t *testing.T) {
|
|
|
|
jobOutput := &jobs.RunOutput{
|
|
|
|
NotebookOutput: &jobs.NotebookOutput{
|
|
|
|
Result: "foo",
|
|
|
|
Truncated: true,
|
|
|
|
},
|
|
|
|
Logs: "hello :)",
|
|
|
|
LogsTruncated: true,
|
|
|
|
}
|
|
|
|
actual := toRunOutput(jobOutput)
|
|
|
|
|
|
|
|
expected := &NotebookOutput{
|
|
|
|
Result: "foo",
|
|
|
|
Truncated: true,
|
|
|
|
}
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDbtOutputToRunOutput(t *testing.T) {
|
|
|
|
jobOutput := &jobs.RunOutput{
|
|
|
|
DbtOutput: &jobs.DbtOutput{
|
|
|
|
ArtifactsLink: "foo",
|
|
|
|
},
|
|
|
|
Logs: "hello :)",
|
|
|
|
}
|
|
|
|
actual := toRunOutput(jobOutput)
|
|
|
|
|
|
|
|
expected := &DbtOutput{
|
|
|
|
ArtifactsLink: "foo",
|
|
|
|
}
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSqlOutputToRunOutput(t *testing.T) {
|
|
|
|
jobOutput := &jobs.RunOutput{
|
|
|
|
SqlOutput: &jobs.SqlOutput{
|
|
|
|
QueryOutput: &jobs.SqlQueryOutput{
|
|
|
|
OutputLink: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Logs: "hello :)",
|
|
|
|
}
|
|
|
|
actual := toRunOutput(jobOutput)
|
|
|
|
|
|
|
|
expected := &SqlOutput{
|
|
|
|
QueryOutput: &jobs.SqlQueryOutput{
|
|
|
|
OutputLink: "foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLogOutputToRunOutput(t *testing.T) {
|
|
|
|
jobOutput := &jobs.RunOutput{
|
|
|
|
Logs: "hello :)",
|
|
|
|
LogsTruncated: true,
|
|
|
|
}
|
|
|
|
actual := toRunOutput(jobOutput)
|
|
|
|
|
|
|
|
expected := &LogsOutput{
|
|
|
|
Logs: "hello :)",
|
|
|
|
LogsTruncated: true,
|
|
|
|
}
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|