mirror of https://github.com/databricks/cli.git
49 lines
993 B
Go
49 lines
993 B
Go
package testutil
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TouchNotebook(t *testing.T, elems ...string) string {
|
|
path := filepath.Join(elems...)
|
|
err := os.MkdirAll(filepath.Dir(path), 0755)
|
|
require.NoError(t, err)
|
|
|
|
err = os.WriteFile(path, []byte("# Databricks notebook source"), 0644)
|
|
require.NoError(t, err)
|
|
return path
|
|
}
|
|
|
|
func Touch(t *testing.T, elems ...string) string {
|
|
path := filepath.Join(elems...)
|
|
err := os.MkdirAll(filepath.Dir(path), 0755)
|
|
require.NoError(t, err)
|
|
|
|
f, err := os.Create(path)
|
|
require.NoError(t, err)
|
|
|
|
err = f.Close()
|
|
require.NoError(t, err)
|
|
return path
|
|
}
|
|
|
|
func WriteFile(t *testing.T, content string, elems ...string) string {
|
|
path := filepath.Join(elems...)
|
|
err := os.MkdirAll(filepath.Dir(path), 0755)
|
|
require.NoError(t, err)
|
|
|
|
f, err := os.Create(path)
|
|
require.NoError(t, err)
|
|
|
|
_, err = f.WriteString(content)
|
|
require.NoError(t, err)
|
|
|
|
err = f.Close()
|
|
require.NoError(t, err)
|
|
return path
|
|
}
|