@@ -30,12 +30,39 @@ def test_index_mode_with_empty_data_reports_missing_record_sets(self):
3030 self .assertNotIn ("DATA: unbound variable" , result .stdout + result .stderr )
3131 self .assertIn ("ERROR: no record sets provided in DATA" , result .stdout )
3232
33- def _run_script (self , data : str | None = None ):
33+ def test_publish_succeeds_when_solr_commit_and_count_succeed (self ):
34+ result = self ._run_script (
35+ data = '["set1.xml"]' ,
36+ bundle_output = "finished Traject::Indexer#process: 2 records in 0.1 seconds\n " ,
37+ solr_count = "2" ,
38+ )
39+
40+ self .assertEqual (result .returncode , 0 )
41+ self .assertIn ("Published Record Count: 2" , result .stdout )
42+
43+ def test_publish_fails_when_solr_commit_fails (self ):
44+ result = self ._run_script (
45+ data = '["set1.xml"]' ,
46+ bundle_output = "finished Traject::Indexer#process: 2 records in 0.1 seconds\n " ,
47+ curl_commit_exit = 1 ,
48+ )
49+
50+ self .assertNotEqual (result .returncode , 0 )
51+ self .assertIn ("ERROR: unable to commit Solr collection after publish" , result .stdout )
52+
53+ def _run_script (
54+ self ,
55+ data : str | None = None ,
56+ bundle_output : str = "" ,
57+ solr_count : str = "0" ,
58+ curl_commit_exit : int = 0 ,
59+ ):
3460 tempdir = tempfile .mkdtemp ()
3561 self .addCleanup (shutil .rmtree , tempdir , ignore_errors = True )
3662 tempdir_path = Path (tempdir )
3763 bin_dir = tempdir_path / "bin"
3864 bin_dir .mkdir ()
65+ (tempdir_path / ".bashrc" ).write_text ("" , encoding = "utf-8" )
3966
4067 report_dir = tempdir_path / "dags" / "funcake_dags" / "scripts"
4168 report_dir .mkdir (parents = True )
@@ -53,8 +80,55 @@ def _run_script(self, data: str | None = None):
5380""" ,
5481 )
5582 self ._write_executable (bin_dir / "gem" , "#!/usr/bin/env bash\n exit 0\n " )
56- self ._write_executable (bin_dir / "bundle" , "#!/usr/bin/env bash\n exit 0\n " )
57- self ._write_executable (bin_dir / "aws" , "#!/usr/bin/env bash\n exit 0\n " )
83+ self ._write_executable (
84+ bin_dir / "bundle" ,
85+ f"""#!/usr/bin/env bash
86+ if [ "$1" = "exec" ]; then
87+ printf %s { bundle_output !r}
88+ fi
89+ exit 0
90+ """ ,
91+ )
92+ self ._write_executable (
93+ bin_dir / "aws" ,
94+ """#!/usr/bin/env bash
95+ if [ "$1" = "s3" ] && [ "$2" = "presign" ]; then
96+ printf "http://example.test/presigned\\ n"
97+ fi
98+ exit 0
99+ """ ,
100+ )
101+ self ._write_executable (
102+ bin_dir / "curl" ,
103+ f"""#!/usr/bin/env bash
104+ args="$*"
105+ if [[ "$args" == *"/update?commit=true"* ]]; then
106+ exit { curl_commit_exit }
107+ fi
108+ if [[ "$args" == *"/select?q=*:*&rows=0&wt=json"* ]]; then
109+ printf '{{"response":{{"numFound":{ solr_count } }}}}\\ n'
110+ exit 0
111+ fi
112+ exit 0
113+ """ ,
114+ )
115+ self ._write_executable (
116+ bin_dir / "jq" ,
117+ """#!/usr/bin/env python3
118+ import json
119+ import sys
120+
121+ payload = json.load(sys.stdin)
122+ query = sys.argv[-1]
123+ if query == ".[]":
124+ for item in payload:
125+ print(item)
126+ elif query == ".response.numFound // empty":
127+ print(payload["response"]["numFound"])
128+ else:
129+ raise SystemExit(f"unsupported jq query: {query}")
130+ """ ,
131+ )
58132 self ._write_executable (
59133 bin_dir / "ruby" ,
60134 """#!/usr/bin/env bash
0 commit comments