@@ -13,6 +13,12 @@ def test_s3_client_without_cloud_space_id(monkeypatch):
13
13
botocore = mock .MagicMock ()
14
14
monkeypatch .setattr (client , "botocore" , botocore )
15
15
16
+ instance_metadata_provider = mock .MagicMock ()
17
+ monkeypatch .setattr (client , "InstanceMetadataProvider" , instance_metadata_provider )
18
+
19
+ instance_metadata_fetcher = mock .MagicMock ()
20
+ monkeypatch .setattr (client , "InstanceMetadataFetcher" , instance_metadata_fetcher )
21
+
16
22
s3 = client .S3Client (1 )
17
23
assert s3 .client
18
24
assert s3 .client
@@ -24,7 +30,8 @@ def test_s3_client_without_cloud_space_id(monkeypatch):
24
30
25
31
26
32
@pytest .mark .skipif (sys .platform == "win32" , reason = "not supported on windows" )
27
- def test_s3_client_with_cloud_space_id (monkeypatch ):
33
+ @pytest .mark .parametrize ("use_shared_credentials" , [False , True ])
34
+ def test_s3_client_with_cloud_space_id (use_shared_credentials , monkeypatch ):
28
35
boto3 = mock .MagicMock ()
29
36
monkeypatch .setattr (client , "boto3" , boto3 )
30
37
@@ -33,6 +40,16 @@ def test_s3_client_with_cloud_space_id(monkeypatch):
33
40
34
41
monkeypatch .setenv ("LIGHTNING_CLOUD_SPACE_ID" , "dummy" )
35
42
43
+ if use_shared_credentials :
44
+ monkeypatch .setenv ("AWS_SHARED_CREDENTIALS_FILE" , "/.credentials/.aws_credentials" )
45
+ monkeypatch .setenv ("AWS_CONFIG_FILE" , "/.credentials/.aws_credentials" )
46
+
47
+ instance_metadata_provider = mock .MagicMock ()
48
+ monkeypatch .setattr (client , "InstanceMetadataProvider" , instance_metadata_provider )
49
+
50
+ instance_metadata_fetcher = mock .MagicMock ()
51
+ monkeypatch .setattr (client , "InstanceMetadataFetcher" , instance_metadata_fetcher )
52
+
36
53
s3 = client .S3Client (1 )
37
54
assert s3 .client
38
55
assert s3 .client
@@ -45,3 +62,5 @@ def test_s3_client_with_cloud_space_id(monkeypatch):
45
62
assert s3 .client
46
63
assert s3 .client
47
64
assert len (boto3 .client ._mock_mock_calls ) == 9
65
+
66
+ assert instance_metadata_provider ._mock_call_count == 0 if use_shared_credentials else 3
0 commit comments