github.com/databricks/cli@v0.203.0/internal/api_test.go (about)

     1  package internal
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"path"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  
    12  	_ "github.com/databricks/cli/cmd/api"
    13  )
    14  
    15  func TestAccApiGet(t *testing.T) {
    16  	t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
    17  
    18  	stdout, _ := RequireSuccessfulRun(t, "api", "get", "/api/2.0/preview/scim/v2/Me")
    19  
    20  	// Deserialize SCIM API response.
    21  	var out map[string]any
    22  	err := json.Unmarshal(stdout.Bytes(), &out)
    23  	require.NoError(t, err)
    24  
    25  	// Assert that the output somewhat makes sense for the SCIM API.
    26  	assert.Equal(t, true, out["active"])
    27  	assert.NotNil(t, out["id"])
    28  }
    29  
    30  func TestAccApiPost(t *testing.T) {
    31  	env := GetEnvOrSkipTest(t, "CLOUD_ENV")
    32  	t.Log(env)
    33  	if env == "gcp" {
    34  		t.Skip("DBFS REST API is disabled on gcp")
    35  	}
    36  
    37  	dbfsPath := path.Join("/tmp/databricks/integration", RandomName("api-post"))
    38  	requestPath := writeFile(t, "body.json", fmt.Sprintf(`{
    39  		"path": "%s"
    40  	}`, dbfsPath))
    41  
    42  	// Post to mkdir
    43  	{
    44  		RequireSuccessfulRun(t, "api", "post", "--json=@"+requestPath, "/api/2.0/dbfs/mkdirs")
    45  	}
    46  
    47  	// Post to delete
    48  	{
    49  		RequireSuccessfulRun(t, "api", "post", "--json=@"+requestPath, "/api/2.0/dbfs/delete")
    50  	}
    51  }