databricks-cli/internal/api_test.go

52 lines
1.1 KiB
Go
Raw Normal View History

package internal
import (
"encoding/json"
"fmt"
"path"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
_ "github.com/databricks/cli/cmd/api"
)
func TestAccApiGet(t *testing.T) {
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
2022-12-09 14:41:04 +00:00
stdout, _ := RequireSuccessfulRun(t, "api", "get", "/api/2.0/preview/scim/v2/Me")
// Deserialize SCIM API response.
var out map[string]any
2022-12-09 14:41:04 +00:00
err := json.Unmarshal(stdout.Bytes(), &out)
require.NoError(t, err)
// Assert that the output somewhat makes sense for the SCIM API.
assert.Equal(t, true, out["active"])
assert.NotNil(t, out["id"])
}
func TestAccApiPost(t *testing.T) {
env := GetEnvOrSkipTest(t, "CLOUD_ENV")
t.Log(env)
if env == "gcp" {
t.Skip("DBFS REST API is disabled on gcp")
}
dbfsPath := path.Join("/tmp/databricks/integration", RandomName("api-post"))
requestPath := writeFile(t, "body.json", fmt.Sprintf(`{
"path": "%s"
}`, dbfsPath))
// Post to mkdir
{
2023-05-01 09:10:02 +00:00
RequireSuccessfulRun(t, "api", "post", "--json=@"+requestPath, "/api/2.0/dbfs/mkdirs")
}
// Post to delete
{
2023-05-01 09:10:02 +00:00
RequireSuccessfulRun(t, "api", "post", "--json=@"+requestPath, "/api/2.0/dbfs/delete")
}
}