2024-03-18 14:41:58 +00:00
|
|
|
package fileset
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/internal/testutil"
|
2024-05-30 07:41:50 +00:00
|
|
|
"github.com/databricks/cli/libs/vfs"
|
2024-03-18 14:41:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNotebookFileIsNotebook(t *testing.T) {
|
2024-05-30 07:41:50 +00:00
|
|
|
f := NewNotebookFile(nil, nil, "")
|
2024-03-18 14:41:58 +00:00
|
|
|
isNotebook, err := f.IsNotebook()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, isNotebook)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSourceFileIsNotNotebook(t *testing.T) {
|
2024-05-30 07:41:50 +00:00
|
|
|
f := NewSourceFile(nil, nil, "")
|
2024-03-18 14:41:58 +00:00
|
|
|
isNotebook, err := f.IsNotebook()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, isNotebook)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnknownFileDetectsNotebook(t *testing.T) {
|
|
|
|
tmpDir := t.TempDir()
|
2024-05-30 07:41:50 +00:00
|
|
|
root := vfs.MustNew(tmpDir)
|
2024-03-18 14:41:58 +00:00
|
|
|
|
2024-04-19 15:05:36 +00:00
|
|
|
t.Run("file", func(t *testing.T) {
|
2024-05-30 07:41:50 +00:00
|
|
|
testutil.Touch(t, tmpDir, "test.py")
|
|
|
|
f := NewFile(root, nil, "test.py")
|
2024-04-19 15:05:36 +00:00
|
|
|
isNotebook, err := f.IsNotebook()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, isNotebook)
|
|
|
|
})
|
2024-03-18 14:41:58 +00:00
|
|
|
|
2024-04-19 15:05:36 +00:00
|
|
|
t.Run("notebook", func(t *testing.T) {
|
2024-05-30 07:41:50 +00:00
|
|
|
testutil.TouchNotebook(t, tmpDir, "notebook.py")
|
|
|
|
f := NewFile(root, nil, "notebook.py")
|
2024-04-19 15:05:36 +00:00
|
|
|
isNotebook, err := f.IsNotebook()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, isNotebook)
|
|
|
|
})
|
2024-03-18 14:41:58 +00:00
|
|
|
}
|