Skip to content

Commit 4f0c73a

Browse files
authored
test: allow multiple default images for a product (#43)
This should resolve the live test failures, and future-proof the tests against any future configuration problems.
1 parent 27e5c72 commit 4f0c73a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

test/jobs-live.jl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,35 @@ previous_last_job = nothing
3838
products = unique(image.product for image in allimages)
3939
@test !isempty(products)
4040
@test "standard-batch" in products
41+
n_single_default_image_tests = 0
4142
for product in products
4243
nimages_for_product = sum(image.product == product for image in allimages)
4344
@test nimages_for_product > 0
4445
images = JuliaHub.batchimages(product; auth)
4546
@test length(images) == nimages_for_product
4647
# Test default image for a product
47-
image = JuliaHub.batchimage(product; auth)
48-
@test image.product == product
49-
product_default_image = only(
50-
filter(i -> i.product == product && i._is_product_default, allimages)
51-
)
52-
@test image.image == product_default_image.image
48+
default_images = filter(i -> i.product == product && i._is_product_default, allimages)
49+
@test length(default_images) > 0 # this assumes that every image has a default image
50+
if length(default_images) == 1
51+
image = JuliaHub.batchimage(product; auth)
52+
@test image.product == product
53+
product_default_image = only(
54+
filter(i -> i.product == product && i._is_product_default, allimages)
55+
)
56+
@test image.image == product_default_image.image
57+
# We want to make sure that this branch gets tested, and having multiple default
58+
# images for several products is a major configuration problem, so we'd expect that
59+
# at least a few products are configured correctly.
60+
n_single_default_image_tests += 1
61+
else
62+
# It can happen that a product declares multiple default images. That's likely a
63+
# configuration error, but we don't want the tests to fail because of it.
64+
# And, in fact, it allows us to sorta test the error handling here.
65+
@warn "Multiple default images for product: $(product)" default_images
66+
@test_throws Exception JuliaHub.batchimage(product; auth)
67+
end
5368
end
69+
@test n_single_default_image_tests > 0
5470
let default_image = JuliaHub.batchimage(; auth)
5571
standard_default_image = only(
5672
filter(i -> i.product == "standard-batch" && i._is_product_default, allimages)

0 commit comments

Comments
 (0)