mirror of https://github.com/databricks/cli.git
Add RequireSuccessfulRun helper (#125)
This commit is contained in:
parent
94f884f0a7
commit
cb16ad1184
|
@ -15,13 +15,11 @@ import (
|
||||||
func TestAccApiGet(t *testing.T) {
|
func TestAccApiGet(t *testing.T) {
|
||||||
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
||||||
|
|
||||||
c := NewCobraTestRunner(t, "api", "get", "/api/2.0/preview/scim/v2/Me")
|
stdout, _ := RequireSuccessfulRun(t, "api", "get", "/api/2.0/preview/scim/v2/Me")
|
||||||
stdout, _, err := c.Run()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Deserialize SCIM API response.
|
// Deserialize SCIM API response.
|
||||||
var out map[string]any
|
var out map[string]any
|
||||||
err = json.Unmarshal(stdout.Bytes(), &out)
|
err := json.Unmarshal(stdout.Bytes(), &out)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Assert that the output somewhat makes sense for the SCIM API.
|
// Assert that the output somewhat makes sense for the SCIM API.
|
||||||
|
@ -43,15 +41,11 @@ func TestAccApiPost(t *testing.T) {
|
||||||
|
|
||||||
// Post to mkdir
|
// Post to mkdir
|
||||||
{
|
{
|
||||||
c := NewCobraTestRunner(t, "api", "post", "--body=@"+requestPath, "/api/2.0/dbfs/mkdirs")
|
RequireSuccessfulRun(t, "api", "post", "--body=@"+requestPath, "/api/2.0/dbfs/mkdirs")
|
||||||
_, _, err := c.Run()
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post to delete
|
// Post to delete
|
||||||
{
|
{
|
||||||
c := NewCobraTestRunner(t, "api", "post", "--body=@"+requestPath, "/api/2.0/dbfs/delete")
|
RequireSuccessfulRun(t, "api", "post", "--body=@"+requestPath, "/api/2.0/dbfs/delete")
|
||||||
_, _, err := c.Run()
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,13 @@ func NewCobraTestRunner(t *testing.T, args ...string) *cobraTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RequireSuccessfulRun(t *testing.T, args ...string) (bytes.Buffer, bytes.Buffer) {
|
||||||
|
c := NewCobraTestRunner(t, args...)
|
||||||
|
stdout, stderr, err := c.Run()
|
||||||
|
require.NoError(t, err)
|
||||||
|
return stdout, stderr
|
||||||
|
}
|
||||||
|
|
||||||
func writeFile(t *testing.T, name string, body string) string {
|
func writeFile(t *testing.T, name string, body string) string {
|
||||||
f, err := os.Create(filepath.Join(t.TempDir(), name))
|
f, err := os.Create(filepath.Join(t.TempDir(), name))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
Loading…
Reference in New Issue