mirror of https://github.com/databricks/cli.git
[DECO-68] Modify acceptance test to work with deco testing infra and represent vscode usecase (#78)
Contains changes to make this integration test work on our GitHub actions testing env 1. use go run main.go to run bricks sync to run the latest bricks from master 2. Log the output from the bricks sync process to allow for debugging 3. removed databricks.yml and instead rely on BRICKS_ROOT and other env vars for auth and bricks sync 4. Added --persist-snapshot set to false to test full sync (same as is used in the vscode extension <img width="898" alt="Screenshot 2022-09-27 at 4 26 18 PM" src="https://user-images.githubusercontent.com/88374338/192553769-7af08ca0-b73a-4cf6-a214-8c58edc4c3e5.png"> The additional logs in the picture above are from a wip PR in deco cli that I made some changes to in order to make deco cli work with bricks : https://github.com/databricks/eng-dev-ecosystem/pull/97
This commit is contained in:
parent
0b754e6de8
commit
ed56fc01cb
|
@ -1,23 +1,44 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/databricks/bricks/folders"
|
||||||
"github.com/databricks/databricks-sdk-go/service/repos"
|
"github.com/databricks/databricks-sdk-go/service/repos"
|
||||||
"github.com/databricks/databricks-sdk-go/service/workspace"
|
"github.com/databricks/databricks-sdk-go/service/workspace"
|
||||||
"github.com/databricks/databricks-sdk-go/workspaces"
|
"github.com/databricks/databricks-sdk-go/workspaces"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccSync(t *testing.T) {
|
// TODO: Write an integration tests for incremental bricks sync once its complete
|
||||||
|
// with support for different profiles (go/jira/DECO-118)
|
||||||
|
|
||||||
|
// This test needs auth env vars to run.
|
||||||
|
// Please run using the deco env test or deco env shell
|
||||||
|
func TestAccFullSync(t *testing.T) {
|
||||||
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
||||||
|
|
||||||
|
// We assume cwd is in the bricks repo
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Log("[WARN] error fetching current working dir: ", err)
|
||||||
|
}
|
||||||
|
t.Log("test run dir: ", wd)
|
||||||
|
bricksRepo, err := folders.FindDirWithLeaf(wd, ".git")
|
||||||
|
if err != nil {
|
||||||
|
t.Log("[ERROR] error finding git repo root in : ", wd)
|
||||||
|
}
|
||||||
|
t.Log("bricks repo location: : ", bricksRepo)
|
||||||
|
assert.Equal(t, "bricks", filepath.Base(bricksRepo))
|
||||||
|
|
||||||
wsc := workspaces.New()
|
wsc := workspaces.New()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
me, err := wsc.CurrentUser.Me(ctx)
|
me, err := wsc.CurrentUser.Me(ctx)
|
||||||
|
@ -37,29 +58,47 @@ func TestAccSync(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
// clone public remote repo
|
// clone public empty remote repo
|
||||||
tempDir := t.TempDir()
|
tempDir := t.TempDir()
|
||||||
cmd := exec.Command("git", "clone", repoUrl)
|
cmd := exec.Command("git", "clone", repoUrl)
|
||||||
cmd.Dir = tempDir
|
cmd.Dir = tempDir
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Initialize the databrick.yml config
|
// Create amsterdam.txt file
|
||||||
projectDir := filepath.Join(tempDir, "empty-repo")
|
projectDir := filepath.Join(tempDir, "empty-repo")
|
||||||
content := []byte("name: test-project\nprofile: DEFAULT")
|
f, err := os.Create(filepath.Join(projectDir, "amsterdam.txt"))
|
||||||
f, err := os.Create(filepath.Join(projectDir, "databricks.yml"))
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
_, err = f.Write(content)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
// start bricks sync process
|
// start bricks sync process
|
||||||
cmd = exec.Command("bricks", "sync", "--remote-path", repoPath)
|
cmd = exec.Command("go", "run", "main.go", "sync", "--remote-path", repoPath, "--persist-snapshot", "false")
|
||||||
cmd.Dir = projectDir
|
|
||||||
|
var cmdOut, cmdErr bytes.Buffer
|
||||||
|
cmd.Stdout = &cmdOut
|
||||||
|
cmd.Stderr = &cmdErr
|
||||||
|
cmd.Dir = bricksRepo
|
||||||
|
// bricks sync command will inherit the env vars from process
|
||||||
|
t.Setenv("BRICKS_ROOT", projectDir)
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
|
// We wait three seconds to allow the bricks sync process flush its
|
||||||
|
// stdout buffer
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
// terminate the bricks sync process
|
||||||
cmd.Process.Kill()
|
cmd.Process.Kill()
|
||||||
|
// Print the stdout and stderr logs from the bricks sync process
|
||||||
|
t.Log("[INFO] bricks sync logs: ")
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("error in bricks sync process: %s\n", err)
|
||||||
|
}
|
||||||
|
for _, line := range strings.Split(strings.TrimSuffix(cmdOut.String(), "\n"), "\n") {
|
||||||
|
t.Log("[bricks sync stdout]", line)
|
||||||
|
}
|
||||||
|
for _, line := range strings.Split(strings.TrimSuffix(cmdErr.String(), "\n"), "\n") {
|
||||||
|
t.Log("[bricks sync stderr]", line)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// First upload assertion
|
// First upload assertion
|
||||||
|
@ -69,7 +108,7 @@ func TestAccSync(t *testing.T) {
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return len(repoContent.Objects) == 2
|
return len(repoContent.Objects) == 2
|
||||||
}, 30*time.Second, time.Second)
|
}, 30*time.Second, 5*time.Second)
|
||||||
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
|
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
|
||||||
Path: repoPath,
|
Path: repoPath,
|
||||||
})
|
})
|
||||||
|
@ -79,7 +118,7 @@ func TestAccSync(t *testing.T) {
|
||||||
files1 = append(files1, filepath.Base(v.Path))
|
files1 = append(files1, filepath.Base(v.Path))
|
||||||
}
|
}
|
||||||
assert.Len(t, files1, 2)
|
assert.Len(t, files1, 2)
|
||||||
assert.Contains(t, files1, "databricks.yml")
|
assert.Contains(t, files1, "amsterdam.txt")
|
||||||
assert.Contains(t, files1, ".gitkeep")
|
assert.Contains(t, files1, ".gitkeep")
|
||||||
|
|
||||||
// Create new files and assert
|
// Create new files and assert
|
||||||
|
@ -91,7 +130,7 @@ func TestAccSync(t *testing.T) {
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return len(repoContent.Objects) == 4
|
return len(repoContent.Objects) == 4
|
||||||
}, 30*time.Second, time.Second)
|
}, 30*time.Second, 5*time.Second)
|
||||||
repoContent, err = wsc.Workspace.List(ctx, workspace.ListRequest{
|
repoContent, err = wsc.Workspace.List(ctx, workspace.ListRequest{
|
||||||
Path: repoPath,
|
Path: repoPath,
|
||||||
})
|
})
|
||||||
|
@ -101,7 +140,7 @@ func TestAccSync(t *testing.T) {
|
||||||
files2 = append(files2, filepath.Base(v.Path))
|
files2 = append(files2, filepath.Base(v.Path))
|
||||||
}
|
}
|
||||||
assert.Len(t, files2, 4)
|
assert.Len(t, files2, 4)
|
||||||
assert.Contains(t, files2, "databricks.yml")
|
assert.Contains(t, files2, "amsterdam.txt")
|
||||||
assert.Contains(t, files2, ".gitkeep")
|
assert.Contains(t, files2, ".gitkeep")
|
||||||
assert.Contains(t, files2, "hello.txt")
|
assert.Contains(t, files2, "hello.txt")
|
||||||
assert.Contains(t, files2, "world.txt")
|
assert.Contains(t, files2, "world.txt")
|
||||||
|
@ -114,7 +153,7 @@ func TestAccSync(t *testing.T) {
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return len(repoContent.Objects) == 3
|
return len(repoContent.Objects) == 3
|
||||||
}, 30*time.Second, time.Second)
|
}, 30*time.Second, 5*time.Second)
|
||||||
repoContent, err = wsc.Workspace.List(ctx, workspace.ListRequest{
|
repoContent, err = wsc.Workspace.List(ctx, workspace.ListRequest{
|
||||||
Path: repoPath,
|
Path: repoPath,
|
||||||
})
|
})
|
||||||
|
@ -124,7 +163,7 @@ func TestAccSync(t *testing.T) {
|
||||||
files3 = append(files3, filepath.Base(v.Path))
|
files3 = append(files3, filepath.Base(v.Path))
|
||||||
}
|
}
|
||||||
assert.Len(t, files3, 3)
|
assert.Len(t, files3, 3)
|
||||||
assert.Contains(t, files3, "databricks.yml")
|
assert.Contains(t, files3, "amsterdam.txt")
|
||||||
assert.Contains(t, files3, ".gitkeep")
|
assert.Contains(t, files3, ".gitkeep")
|
||||||
assert.Contains(t, files3, "world.txt")
|
assert.Contains(t, files3, "world.txt")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue