Skip to content

Commit

Permalink
Add acceptance test for 'experimental.scripts' (#2240)
Browse files Browse the repository at this point in the history
  • Loading branch information
denik authored Jan 27, 2025
1 parent 67d1413 commit be908ee
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 51 deletions.
11 changes: 11 additions & 0 deletions acceptance/bundle/scripts/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bundle:
name: scripts

experimental:
scripts:
preinit: "python3 ./myscript.py $EXITCODE preinit"
postinit: "python3 ./myscript.py 0 postinit"
prebuild: "python3 ./myscript.py 0 prebuild"
postbuild: "python3 ./myscript.py 0 postbuild"
predeploy: "python3 ./myscript.py 0 predeploy"
postdeploy: "python3 ./myscript.py 0 postdeploy"
8 changes: 8 additions & 0 deletions acceptance/bundle/scripts/myscript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys

info = " ".join(sys.argv[1:])
sys.stderr.write(f"from myscript.py {info}: hello stderr!\n")
sys.stdout.write(f"from myscript.py {info}: hello stdout!\n")

exitcode = int(sys.argv[1])
sys.exit(exitcode)
52 changes: 52 additions & 0 deletions acceptance/bundle/scripts/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

>>> EXITCODE=0 errcode $CLI bundle validate
Executing 'preinit' script
from myscript.py 0 preinit: hello stdout!
from myscript.py 0 preinit: hello stderr!
Executing 'postinit' script
from myscript.py 0 postinit: hello stdout!
from myscript.py 0 postinit: hello stderr!
Name: scripts
Target: default
Workspace:
User: $USERNAME
Path: /Workspace/Users/$USERNAME/.bundle/scripts/default

Validation OK!

>>> EXITCODE=1 errcode $CLI bundle validate
Executing 'preinit' script
from myscript.py 1 preinit: hello stdout!
from myscript.py 1 preinit: hello stderr!
Error: failed to execute script: exit status 1

Name: scripts

Found 1 error

Exit code: 1

>>> EXITCODE=0 errcode $CLI bundle deploy
Executing 'preinit' script
from myscript.py 0 preinit: hello stdout!
from myscript.py 0 preinit: hello stderr!
Executing 'postinit' script
from myscript.py 0 postinit: hello stdout!
from myscript.py 0 postinit: hello stderr!
Executing 'prebuild' script
from myscript.py 0 prebuild: hello stdout!
from myscript.py 0 prebuild: hello stderr!
Executing 'postbuild' script
from myscript.py 0 postbuild: hello stdout!
from myscript.py 0 postbuild: hello stderr!
Executing 'predeploy' script
from myscript.py 0 predeploy: hello stdout!
from myscript.py 0 predeploy: hello stderr!
Error: unable to deploy to /Workspace/Users/$USERNAME/.bundle/scripts/default/state as $USERNAME.
Please make sure the current user or one of their groups is listed under the permissions of this bundle.
For assistance, contact the owners of this project.
They may need to redeploy the bundle to apply the new permissions.
Please refer to https://docs.databricks.com/dev-tools/bundles/permissions.html for more on managing permissions.


Exit code: 1
3 changes: 3 additions & 0 deletions acceptance/bundle/scripts/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trace EXITCODE=0 errcode $CLI bundle validate
trace EXITCODE=1 errcode $CLI bundle validate
trace EXITCODE=0 errcode $CLI bundle deploy
4 changes: 4 additions & 0 deletions acceptance/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,8 @@ func AddHandlers(server *TestServer) {
},
}, nil
})

server.Handle("POST /api/2.0/workspace/mkdirs", func(r *http.Request) (any, error) {
return "{}", nil
})
}
51 changes: 0 additions & 51 deletions bundle/scripts/scripts_test.go

This file was deleted.

0 comments on commit be908ee

Please sign in to comment.