2024-12-20 14:40:54 +00:00
|
|
|
package testcli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/internal/testutil"
|
|
|
|
"github.com/databricks/cli/libs/testdiff"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func captureOutput(t testutil.TestingT, ctx context.Context, args []string) string {
|
2025-01-02 09:49:21 +00:00
|
|
|
t.Helper()
|
2024-12-20 14:40:54 +00:00
|
|
|
r := NewRunner(t, ctx, args...)
|
|
|
|
stdout, stderr, err := r.Run()
|
|
|
|
assert.NoError(t, err)
|
2024-12-30 15:26:21 +00:00
|
|
|
return stderr.String() + stdout.String()
|
2024-12-20 14:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func AssertOutput(t testutil.TestingT, ctx context.Context, args []string, expectedPath string) {
|
2025-01-02 09:49:21 +00:00
|
|
|
t.Helper()
|
2024-12-20 14:40:54 +00:00
|
|
|
out := captureOutput(t, ctx, args)
|
2024-12-30 15:26:21 +00:00
|
|
|
testdiff.AssertOutput(t, ctx, out, fmt.Sprintf("Output from %v", args), expectedPath)
|
2024-12-20 14:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func AssertOutputJQ(t testutil.TestingT, ctx context.Context, args []string, expectedPath string, ignorePaths []string) {
|
2025-01-02 09:49:21 +00:00
|
|
|
t.Helper()
|
2024-12-20 14:40:54 +00:00
|
|
|
out := captureOutput(t, ctx, args)
|
2024-12-30 15:26:21 +00:00
|
|
|
testdiff.AssertOutputJQ(t, ctx, out, fmt.Sprintf("Output from %v", args), expectedPath, ignorePaths)
|
2024-12-20 14:40:54 +00:00
|
|
|
}
|