19
19
import jakarta .validation .constraints .AssertTrue ;
20
20
import org .junit .jupiter .api .Test ;
21
21
22
- import java .io .IOException ;
23
- import java .nio .file .Files ;
24
- import java .nio .file .Path ;
25
22
import java .util .Map ;
26
23
import java .util .Optional ;
24
+ import java .util .Set ;
27
25
28
26
import static io .airlift .configuration .testing .ConfigAssertions .assertFullMapping ;
29
27
import static io .airlift .configuration .testing .ConfigAssertions .assertRecordedDefaults ;
32
30
import static io .airlift .units .DataSize .Unit .MEGABYTE ;
33
31
import static java .util .concurrent .TimeUnit .MILLISECONDS ;
34
32
import static java .util .concurrent .TimeUnit .SECONDS ;
35
- import static org .assertj .core .api .Assertions .assertThatThrownBy ;
36
33
37
34
public class TestGcsFileSystemConfig
38
35
{
@@ -59,10 +56,7 @@ void testDefaults()
59
56
60
57
@ Test
61
58
void testExplicitPropertyMappings ()
62
- throws IOException
63
59
{
64
- Path jsonKeyFile = Files .createTempFile (null , null );
65
-
66
60
Map <String , String > properties = ImmutableMap .<String , String >builder ()
67
61
.put ("gcs.read-block-size" , "51MB" )
68
62
.put ("gcs.write-block-size" , "52MB" )
@@ -71,8 +65,6 @@ void testExplicitPropertyMappings()
71
65
.put ("gcs.project-id" , "project" )
72
66
.put ("gcs.endpoint" , "http://custom.dns.org:8000" )
73
67
.put ("gcs.use-access-token" , "true" )
74
- .put ("gcs.json-key" , "{}" )
75
- .put ("gcs.json-key-file-path" , jsonKeyFile .toString ())
76
68
.put ("gcs.client.max-retries" , "10" )
77
69
.put ("gcs.client.backoff-scale-factor" , "4.0" )
78
70
.put ("gcs.client.max-retry-time" , "10s" )
@@ -89,40 +81,41 @@ void testExplicitPropertyMappings()
89
81
.setProjectId ("project" )
90
82
.setEndpoint (Optional .of ("http://custom.dns.org:8000" ))
91
83
.setUseGcsAccessToken (true )
92
- .setJsonKey ("{}" )
93
- .setJsonKeyFilePath (jsonKeyFile .toString ())
94
84
.setMaxRetries (10 )
95
85
.setBackoffScaleFactor (4.0 )
96
86
.setMaxRetryTime (new Duration (10 , SECONDS ))
97
87
.setMinBackoffDelay (new Duration (20 , MILLISECONDS ))
98
88
.setMaxBackoffDelay (new Duration (20 , MILLISECONDS ))
99
89
.setApplicationId ("application id" );
100
- assertFullMapping (properties , expected );
90
+ assertFullMapping (properties , expected , Set . of ( "gcs.json-key" , "gcs.json-key-file-path" ) );
101
91
}
102
92
103
93
@ Test
104
94
public void testValidation ()
105
95
{
106
- assertThatThrownBy (
96
+ assertFailsValidation (
107
97
new GcsFileSystemConfig ()
108
98
.setUseGcsAccessToken (true )
109
- .setJsonKey ("{}}" )::validate )
110
- .isInstanceOf (IllegalStateException .class )
111
- .hasMessage ("Cannot specify 'gcs.json-key' when 'gcs.use-access-token' is set" );
99
+ .setJsonKey ("{}}" ),
100
+ "authMethodValid" ,
101
+ "Either gcs.use-access-token or gcs.json-key or gcs.json-key-file-path must be set" ,
102
+ AssertTrue .class );
112
103
113
- assertThatThrownBy (
104
+ assertFailsValidation (
114
105
new GcsFileSystemConfig ()
115
106
.setUseGcsAccessToken (true )
116
- .setJsonKeyFilePath ("/dev/null" )::validate )
117
- .isInstanceOf (IllegalStateException .class )
118
- .hasMessage ("Cannot specify 'gcs.json-key-file-path' when 'gcs.use-access-token' is set" );
107
+ .setJsonKeyFilePath ("/dev/null" ),
108
+ "authMethodValid" ,
109
+ "Either gcs.use-access-token or gcs.json-key or gcs.json-key-file-path must be set" ,
110
+ AssertTrue .class );
119
111
120
- assertThatThrownBy (
112
+ assertFailsValidation (
121
113
new GcsFileSystemConfig ()
122
114
.setJsonKey ("{}" )
123
- .setJsonKeyFilePath ("/dev/null" )::validate )
124
- .isInstanceOf (IllegalStateException .class )
125
- .hasMessage ("'gcs.json-key' and 'gcs.json-key-file-path' cannot be both set" );
115
+ .setJsonKeyFilePath ("/dev/null" ),
116
+ "authMethodValid" ,
117
+ "Either gcs.use-access-token or gcs.json-key or gcs.json-key-file-path must be set" ,
118
+ AssertTrue .class );
126
119
127
120
assertFailsValidation (
128
121
new GcsFileSystemConfig ()
0 commit comments