Skip to content

Commit f156cac

Browse files
make testserver pipelines 404 match real backend (#2952)
## Changes - Update testserver's pipeline/get to match the output of the real server. - Update resources/pipelines test to test destruction of resources. - Add 'musterr' helper to better show intent that command must fail. ## Why Using this test in #2926 --------- Co-authored-by: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com>
1 parent c583951 commit f156cac

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

acceptance/bin/read_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def print_resource_terraform(section, name, *attrs):
3232
print(section, name, " ".join(values))
3333
found += 1
3434
if not found:
35-
print(f"Resource {(resource_type, name)} not found. Available: {available}")
35+
print(f"State not found for {section}.{name}")
3636

3737

3838
print_resource_terraform(*sys.argv[1:])

acceptance/bundle/resources/pipelines/output.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,25 @@ pipelines my id='[UUID]' name='test-pipeline-[UNIQUE_NAME]'
8888
},
8989
"state":"IDLE"
9090
}
91+
92+
=== Destroy the pipeline and verify that it's removed from the state and from remote
93+
>>> [CLI] bundle destroy --auto-approve
94+
The following resources will be deleted:
95+
delete pipeline my
96+
97+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/acc-[UNIQUE_NAME]/default
98+
99+
Deleting files...
100+
Destroy complete!
101+
102+
>>> print_requests
103+
{
104+
"method": "DELETE",
105+
"path": "/api/2.0/pipelines/[UUID]"
106+
}
107+
State not found for pipelines.my
108+
109+
>>> musterr [CLI] pipelines get [UUID]
110+
Error: The specified pipeline [UUID] was not found.
111+
112+
Exit code (musterr): 1

acceptance/bundle/resources/pipelines/script

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,13 @@ trace update_file.py databricks.yml foo.py bar.py
1515
trace $CLI bundle deploy
1616
trace print_requests
1717

18-
trace $CLI pipelines get $(read_id.py pipelines my)
18+
ppid=`read_id.py pipelines my`
19+
trace $CLI pipelines get $ppid
20+
rm out.requests.txt
21+
22+
title "Destroy the pipeline and verify that it's removed from the state and from remote"
23+
trace $CLI bundle destroy --auto-approve
24+
25+
trace print_requests
26+
trace musterr $CLI pipelines get $ppid
1927
rm out.requests.txt

acceptance/internal/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func addDefaultHandlers(server *testserver.Server) {
255255
// Pipelines:
256256

257257
server.Handle("GET", "/api/2.0/pipelines/{pipeline_id}", func(req testserver.Request) any {
258-
return testserver.MapGet(req.Workspace, req.Workspace.Pipelines, req.Vars["pipeline_id"])
258+
return req.Workspace.PipelineGet(req.Vars["pipeline_id"])
259259
})
260260

261261
server.Handle("POST", "/api/2.0/pipelines", func(req testserver.Request) any {

acceptance/script.prepare

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ errcode() {
1111
fi
1212
}
1313

14+
musterr() {
15+
# Temporarily disable 'set -e' to prevent the script from exiting on error
16+
set +e
17+
# Execute the provided command with all arguments
18+
"$@"
19+
local exit_code=$?
20+
# Re-enable 'set -e'
21+
set -e
22+
if [ $exit_code -eq 0 ]; then
23+
>&2 printf "\nUnexpected success\n"
24+
exit 1
25+
fi
26+
>&2 printf "\nExit code (musterr): $exit_code\n"
27+
}
28+
1429
trace() {
1530
>&2 printf "\n>>> %s\n" "$*"
1631

libs/testserver/pipelines.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ import (
99
"github.com/google/uuid"
1010
)
1111

12+
func (s *FakeWorkspace) PipelineGet(pipelineId string) Response {
13+
defer s.LockUnlock()()
14+
15+
value, ok := s.Pipelines[pipelineId]
16+
if !ok {
17+
return Response{
18+
StatusCode: 404,
19+
Body: map[string]string{"message": fmt.Sprintf("The specified pipeline %s was not found.", pipelineId)},
20+
}
21+
}
22+
return Response{
23+
Body: value,
24+
}
25+
}
26+
1227
func (s *FakeWorkspace) PipelineCreate(req Request) Response {
1328
defer s.LockUnlock()()
1429

0 commit comments

Comments
 (0)