From 2473c2a819769c95988f8dd84b0f846f9a3bc8c3 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 2 Jul 2024 15:25:55 -0700 Subject: [PATCH 1/4] Avoid duplicate `include`s causing warnings in tests Currently we're calling `include` in a loop over supported backends. The files being `include`d contain definitions which get overwritten when `include` is called a second time, resulting in a lot of warnings that make the test logs noisy. The approach taken here to address this is to wrap things in expressions, define an anonymous module inside of the loop over backends, `Core.eval` the expressions into the anonymous module, and `Core.include` the files into it. There are better ways to do this but this *should* get the job done with minimal required changes. --- test/runtests.jl | 110 +++++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index e57feba480..099a128607 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,45 +1,54 @@ -using AWS -using AWS: AWSCredentials, AWSServices, assume_role_creds -using AWS.AWSExceptions: - AWSException, IMDSUnavailable, InvalidFileName, NoCredentials, ProtocolNotDefined -using AWS.AWSMetadata: - ServiceFile, - _clean_documentation, - _filter_latest_service_version, - _generate_low_level_definition, - _generate_high_level_definition, - _generate_high_level_definitions, - _get_service_files, - _get_service_and_version, - _get_function_parameters, - _clean_uri, - _format_name, - _splitline, - _wraplines, - _validindex -using Base64 -using Compat: mergewith -using Dates -using Downloads -using GitHub -using HTTP -using IniFile: Inifile -using JSON -using OrderedCollections: LittleDict, OrderedDict -using MbedTLS: digest, MD_SHA256, MD_MD5 -using Mocking -using Pkg -using Random -using Suppressor -using Test -using UUIDs -using XMLDict -using StableRNGs +const TOP_LEVEL_STUFF = quote + using AWS + using AWS: AWSCredentials, AWSServices, assume_role_creds + using AWS.AWSExceptions: + AWSException, IMDSUnavailable, InvalidFileName, NoCredentials, ProtocolNotDefined + using AWS.AWSMetadata: + ServiceFile, + _clean_documentation, + _filter_latest_service_version, + _generate_low_level_definition, + _generate_high_level_definition, + _generate_high_level_definitions, + _get_service_files, + _get_service_and_version, + _get_function_parameters, + _clean_uri, + _format_name, + _splitline, + _wraplines, + _validindex + using Base64 + using Compat: mergewith + using Dates + using Downloads + using GitHub + using HTTP + using IniFile: Inifile + using JSON + using OrderedCollections: LittleDict, OrderedDict + using MbedTLS: digest, MD_SHA256, MD_MD5 + using Mocking + using Pkg + using Random + using Suppressor + using Test + using UUIDs + using XMLDict + using StableRNGs -Mocking.activate() + Mocking.activate() -include("patch.jl") -include("resources/totp.jl") + include("patch.jl") + include("resources/totp.jl") + + function _now_formatted() + return lowercase(Dates.format(now(Dates.UTC), dateformat"yyyymmdd\THHMMSSsss\Z")) + end + + testset_role(role_name) = string("AWS.jl-", role_name) +end +eval(TOP_LEVEL_STUFF) # ensure things are loaded/defined in Main const TEST_MINIO = begin all(k -> haskey(ENV, k), ("MINIO_ACCESS_KEY", "MINIO_SECRET_KEY", "MINIO_REGION_NAME")) @@ -47,12 +56,6 @@ end aws = AWSConfig() -function _now_formatted() - return lowercase(Dates.format(now(Dates.UTC), dateformat"yyyymmdd\THHMMSSsss\Z")) -end - -testset_role(role_name) = "AWS.jl-$role_name" - @testset "AWS.jl" begin include("AWSExceptions.jl") include("AWSMetadataUtilities.jl") @@ -63,14 +66,17 @@ testset_role(role_name) = "AWS.jl-$role_name" backends = [AWS.HTTPBackend, AWS.DownloadsBackend] @testset "Backend: $(nameof(backend))" for backend in backends AWS.DEFAULT_BACKEND[] = backend() - include("AWS.jl") - include("IMDS.jl") - include("AWSCredentials.jl") - include("role.jl") - include("issues.jl") + M = Module(Symbol(:Test, nameof(backend))) + Core.eval(M, TOP_LEVEL_STUFF) # ensure things are loaded/defined in this module too + Core.eval(M, :(using ..Main: aws)) + Core.include(M, "AWS.jl") + Core.include(M, "IMDS.jl") + Core.include(M, "AWSCredentials.jl") + Core.include(M, "role.jl") + Core.include(M, "issues.jl") if TEST_MINIO - include("minio.jl") + Core.include(M, "minio.jl") end end end From 083389152aa705ad3a02419d4c32c1515e898b2b Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 2 Jul 2024 15:41:38 -0700 Subject: [PATCH 2/4] Appease JuliaFormatter, appease macro expansion --- test/runtests.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 099a128607..f9135f059e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,7 +2,11 @@ const TOP_LEVEL_STUFF = quote using AWS using AWS: AWSCredentials, AWSServices, assume_role_creds using AWS.AWSExceptions: - AWSException, IMDSUnavailable, InvalidFileName, NoCredentials, ProtocolNotDefined + AWSException, + IMDSUnavailable, + InvalidFileName, + NoCredentials, + ProtocolNotDefined using AWS.AWSMetadata: ServiceFile, _clean_documentation, @@ -42,8 +46,10 @@ const TOP_LEVEL_STUFF = quote include("patch.jl") include("resources/totp.jl") + const _NOW_FMT = DateFormat("yyyymmdd\\THHMMSSsss\\Z") + function _now_formatted() - return lowercase(Dates.format(now(Dates.UTC), dateformat"yyyymmdd\THHMMSSsss\Z")) + return lowercase(Dates.format(now(Dates.UTC), _NOW_FMT)) end testset_role(role_name) = string("AWS.jl-", role_name) From 566a721f0acbc8994ef08f059abb7f64e290de81 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 2 Jul 2024 16:00:52 -0700 Subject: [PATCH 3/4] Uh, how about this maybe? --- test/runtests.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index f9135f059e..beff2fbed7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -43,8 +43,8 @@ const TOP_LEVEL_STUFF = quote Mocking.activate() - include("patch.jl") - include("resources/totp.jl") + Base.include(@__MODULE__, "patch.jl") + Base.include(@__MODULE__, "resources/totp.jl") const _NOW_FMT = DateFormat("yyyymmdd\\THHMMSSsss\\Z") @@ -75,14 +75,14 @@ aws = AWSConfig() M = Module(Symbol(:Test, nameof(backend))) Core.eval(M, TOP_LEVEL_STUFF) # ensure things are loaded/defined in this module too Core.eval(M, :(using ..Main: aws)) - Core.include(M, "AWS.jl") - Core.include(M, "IMDS.jl") - Core.include(M, "AWSCredentials.jl") - Core.include(M, "role.jl") - Core.include(M, "issues.jl") + Base.include(M, "AWS.jl") + Base.include(M, "IMDS.jl") + Base.include(M, "AWSCredentials.jl") + Base.include(M, "role.jl") + Base.include(M, "issues.jl") if TEST_MINIO - Core.include(M, "minio.jl") + Base.include(M, "minio.jl") end end end From 3c4fc6da19139a0f85f163065bfb53e8090a51e6 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 2 Jul 2024 16:23:07 -0700 Subject: [PATCH 4/4] Don't assume the current module is `Main` --- test/AWS.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/AWS.jl b/test/AWS.jl index 3fd83aa37c..70bbdbc95e 100644 --- a/test/AWS.jl +++ b/test/AWS.jl @@ -1,6 +1,6 @@ @testset "service module" begin @service S3 - @test :S3 in names(Main) + @test isdefined(@__MODULE__, :S3) end @testset "global config, kwargs" begin