Skip to content

Commit

Permalink
Fix check my work safety net when running workbench jobs (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall authored Nov 19, 2024
1 parent f07e149 commit 7841492
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
15 changes: 7 additions & 8 deletions internal/handlers/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,15 @@ func CheckMyWork(w http.ResponseWriter, r *http.Request) {
// make sure the file exists in the filesystem
case "File Path", "Supplemental File":
filename := strings.ReplaceAll(cell, `\`, `/`)
// we're testing with /tmp files
if len(filename) < 6 || filename[0:5] != "/tmp/" {
// but need to make sure we're mapping /mnt/islandora_staging into /data in docker
filename = strings.TrimLeft(filename, "/")
if len(filename) > 3 && filename[0:3] != "mnt" {
filename = fmt.Sprintf("/mnt/islandora_staging/%s", filename)
}

// todo: only have fabricator run in docker
// and not in the github action job, too
filename = strings.TrimLeft(filename, "/")
if len(filename) > 3 && filename[0:3] != "mnt" {
filename = fmt.Sprintf("/mnt/islandora_staging/%s", filename)
}

filename = strings.ReplaceAll(filename, "/mnt/islandora_staging", "/data")
filename = strings.ReplaceAll(filename, "/mnt/islandora_staging", os.Getenv("FABRICATOR_DATA_MOUNT"))
if !fileExists(filename) {
errors[i] = "File does not exist in islandora_staging"
}
Expand Down
7 changes: 4 additions & 3 deletions internal/handlers/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func TestCheckMyWork(t *testing.T) {
os.Setenv("FABRICATOR_DATA_MOUNT", "/tmp")
files := []struct {
name string
permissions os.FileMode
Expand Down Expand Up @@ -149,7 +150,7 @@ func TestCheckMyWork(t *testing.T) {
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "File Path"},
{"foo", "Image", "foo", "/tmp/test_readable.txt"},
{"foo", "Image", "foo", "test_readable.txt"},
},
statusCode: http.StatusOK,
response: `{}`,
Expand All @@ -159,7 +160,7 @@ func TestCheckMyWork(t *testing.T) {
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "File Path"},
{"foo", "Image", "foo", "/tmp/test_writable.txt"},
{"foo", "Image", "foo", "test_writable.txt"},
},
statusCode: http.StatusOK,
response: `{}`,
Expand All @@ -170,7 +171,7 @@ func TestCheckMyWork(t *testing.T) {
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "File Path"},
{"foo", "Image", "foo", "/tmp/test_private.txt"},
{"foo", "Image", "foo", "test_private.txt"},
},
statusCode: http.StatusOK,
response: `{"D2":"File does not exist in islandora_staging"}`,
Expand Down
9 changes: 8 additions & 1 deletion scripts/transform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ done
STATUS=$(curl -v \
-w '%{http_code}' \
-H "X-Secret: $SHARED_SECRET" \
-o check.json \
-XPOST \
--upload-file csv.json \
http://localhost:8080/workbench/check)
if [ "${STATUS}" -gt 299 ] || [ "${STATUS}" -lt 200 ]; then
if [ "${STATUS}" != 200 ]; then
echo "Check my work failed"
exit 1
fi

if [[ "$(jq '. | length' check.json)" -gt 0 ]]; then
echo "Check my work failed"
jq . check.json
exit 1
fi

Expand Down

0 comments on commit 7841492

Please sign in to comment.