diff --git a/connection.go b/connection.go index 01e5e8c..3911289 100644 --- a/connection.go +++ b/connection.go @@ -587,7 +587,7 @@ func (c *conn) handleStagingRemove(ctx context.Context, presignedUrl string, hea content, err := io.ReadAll(res.Body) if err != nil || !Succeeded(res) { - return dbsqlerrint.NewDriverError(ctx, fmt.Sprintf("staging operation over HTTP was unsuccessful: %d-%s, nil", res.StatusCode, content), nil) + return dbsqlerrint.NewDriverError(ctx, fmt.Sprintf("staging operation over HTTP was unsuccessful: %d-%s", res.StatusCode, content), nil) } return nil diff --git a/staging_test.go b/staging_test.go index 13cc5c9..731aa1c 100644 --- a/staging_test.go +++ b/staging_test.go @@ -1,11 +1,29 @@ package dbsql import ( + "context" + "net/http" + "net/http/httptest" "testing" + "github.com/databricks/databricks-sql-go/internal/config" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) +func TestHandleStagingRemoveHTTPError(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusForbidden) + w.Write([]byte("Access Denied")) + })) + defer server.Close() + + c := &conn{cfg: config.WithDefaults()} + err := c.handleStagingRemove(context.Background(), server.URL, map[string]string{}) + require.NotNil(t, err) + assert.NotContains(t, err.Error(), ", nil", "error message should not contain literal \", nil\"") +} + func TestPathAllowed(t *testing.T) { t.Run("Should not allow paths that don't share directory", func(t *testing.T) { stagingAllowedLocalPath := []string{"/var/www/html"}