@@ -212,4 +212,159 @@ test_expect_success HAVE_JQ 'use of --local,--xml and --hosts is supported' '
212212 test_debug "echo got $hosts" &&
213213 test "$hosts" = "fluke[0-16]"
214214'
215+ test_expect_success ' flux R parse-config works' '
216+ mkdir conf &&
217+ cat <<-EOF >conf/resource.toml &&
218+ [[resource.config]]
219+ hosts = "foo"
220+ cores = "0-1"
221+ gpus = "0"
222+ EOF
223+ flux R parse-config conf > conf.json &&
224+ test_debug "flux R decode --short < conf.json" &&
225+ test $(flux R decode -c node < conf.json) -eq 1 &&
226+ test $(flux R decode -c core < conf.json) -eq 2 &&
227+ test $(flux R decode -c gpu < conf.json) -eq 1 &&
228+ test "$(flux R decode --nodelist < conf.json)" = "foo"
229+ '
230+ test_expect_success ' flux R parse-config works (multiple entries)' '
231+ mkdir -p conf &&
232+ cat <<-EOF >conf/resource.toml &&
233+ [[resource.config]]
234+ hosts = "foo[0-2]"
235+ cores = "0-1"
236+ [[resource.config]]
237+ hosts = "foo2"
238+ gpus = "0"
239+ [[resource.config]]
240+ hosts = "foo0"
241+ properties = ["login"]
242+ EOF
243+ flux R parse-config conf > conf2.json &&
244+ test_debug "flux R decode --short < conf2.json" &&
245+ test $(flux R decode -c node < conf2.json) -eq 3 &&
246+ test $(flux R decode -c core < conf2.json) -eq 6 &&
247+ test $(flux R decode -c gpu < conf2.json) -eq 1 &&
248+ test "$(flux R decode --nodelist < conf2.json)" = "foo[0-2]" &&
249+ test "$(flux R decode -p login --nodelist < conf2.json)" = "foo0"
250+ '
251+ test_expect_success ' flux R parse-config fails on invalid TOML' '
252+ mkdir -p conf &&
253+ cat <<-EOF >conf/resource.toml &&
254+ [[resource.config]]
255+ EOF
256+ test_must_fail flux R parse-config conf
257+ '
258+ test_expect_success ' flux R parse-config fails on when resource.config missing' '
259+ mkdir -p conf &&
260+ cat <<-EOF >conf/resource.toml &&
261+ [resource]
262+ noverify = true
263+ EOF
264+ test_must_fail flux R parse-config conf
265+ '
266+ test_expect_success ' flux R parse-config detects empty host list' '
267+ mkdir -p conf &&
268+ cat <<-EOF >conf/resource.toml &&
269+ [[resource.config]]
270+ hosts = "foo"
271+ cores = "0-1"
272+ [[resource.config]]
273+ hosts = ""
274+ cores = "0-3"
275+ EOF
276+ test_must_fail flux R parse-config conf
277+ '
278+ test_expect_success ' flux R parse-config detects invalid host list' '
279+ mkdir -p conf &&
280+ cat <<-EOF >conf/resource.toml &&
281+ [[resource.config]]
282+ hosts = "foo[p]"
283+ cores = "0-1"
284+ EOF
285+ test_must_fail flux R parse-config conf
286+ '
287+ test_expect_success ' flux R parse-config detects invalid idset' '
288+ mkdir -p conf &&
289+ cat <<-EOF >conf/resource.toml &&
290+ [[resource.config]]
291+ hosts = "foo0"
292+ cores = "0-"
293+ EOF
294+ test_must_fail flux R parse-config conf &&
295+ cat <<-EOF >conf/resource.toml &&
296+ [[resource.config]]
297+ hosts = "foo0"
298+ gpus = "2,1"
299+ EOF
300+ test_must_fail flux R parse-config conf
301+ '
302+ test_expect_success ' flux R parse-config detects host with no resources' '
303+ mkdir -p conf &&
304+ cat <<-EOF >conf/resource.toml &&
305+ [[resource.config]]
306+ hosts = "foo[0-10]"
307+ cores = "0-1"
308+ [[resource.config]]
309+ hosts = "foo11"
310+ EOF
311+ test_must_fail flux R parse-config conf
312+ '
313+ test_expect_success ' flux R parse-config detects host with no resources' '
314+ mkdir -p conf &&
315+ cat <<-EOF >conf/resource.toml &&
316+ [[resource.config]]
317+ hosts = "foo[0-10]"
318+ cores = "0-1"
319+ [[resource.config]]
320+ hosts = "foo11"
321+ EOF
322+ test_must_fail flux R parse-config conf
323+ '
324+ test_expect_success ' flux R parse-config detects missing hosts entry' '
325+ mkdir -p conf &&
326+ cat <<-EOF >conf/resource.toml &&
327+ [[resource.config]]
328+ hosts = "foo[0-10]"
329+ cores = "0-1"
330+ [[resource.config]]
331+ cores = "0-1"
332+ EOF
333+ test_must_fail flux R parse-config conf
334+ '
335+ test_expect_success ' flux R parse-config detects invalid entry' '
336+ mkdir -p conf &&
337+ cat <<-EOF >conf/resource.toml &&
338+ [[resource.config]]
339+ hosts = "foo[0-10]"
340+ cores = "0-1"
341+ [[resource.config]]
342+ hosts = "foo11"
343+ cores = "0-3"
344+ junk = 5
345+ EOF
346+ test_must_fail flux R parse-config conf
347+ '
348+ test_expect_success ' flux R parse-config detects invalid property' '
349+ mkdir -p conf &&
350+ cat <<-EOF >conf/resource.toml &&
351+ [[resource.config]]
352+ hosts = "foo[0-10]"
353+ cores = "0-1"
354+ [[resource.config]]
355+ hosts = "foo1"
356+ properties = ["de^bug"]
357+ EOF
358+ test_must_fail flux R parse-config conf &&
359+ cat <<-EOF >conf/resource.toml &&
360+ [[resource.config]]
361+ hosts = "foo[0-10]"
362+ cores = "0-1"
363+ [[resource.config]]
364+ hosts = "foo1"
365+ properties = [1]
366+ EOF
367+ test_must_fail flux R parse-config conf
368+ '
369+
215370test_done
0 commit comments