2022-10-10 08:27:45 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2023-01-11 12:32:02 +00:00
|
|
|
"path"
|
2022-10-10 08:27:45 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
_ "github.com/databricks/cli/cmd/api"
|
2022-10-10 08:27:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
2022-10-10 08:27:45 +00:00
|
|
|
|
|
|
|
// Deserialize SCIM API response.
|
|
|
|
var out map[string]any
|
2022-12-09 14:41:04 +00:00
|
|
|
err := json.Unmarshal(stdout.Bytes(), &out)
|
2022-10-10 08:27:45 +00:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
dbfsPath := path.Join("/tmp/databricks/integration", RandomName("api-post"))
|
2022-10-10 08:27:45 +00:00
|
|
|
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")
|
2022-10-10 08:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Post to delete
|
|
|
|
{
|
2023-05-01 09:10:02 +00:00
|
|
|
RequireSuccessfulRun(t, "api", "post", "--json=@"+requestPath, "/api/2.0/dbfs/delete")
|
2022-10-10 08:27:45 +00:00
|
|
|
}
|
|
|
|
}
|