Skip to content

Commit 416c3ab

Browse files
committed
Improve test skipping.
Consolidate the variety of test attributes into just [SkippableFact] and [SkippableTheory] that take a flags enum value specifying required server features or config settings. Also support "baseline" test skipping in these new attributes to reduce the number of #if blocks.
1 parent 1a580db commit 416c3ab

16 files changed

+180
-297
lines changed

tests/SideBySide/Attributes.cs

Lines changed: 28 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,73 @@
1-
using System;
21
using MySql.Data.MySqlClient;
32
using Xunit;
43

54
namespace SideBySide
65
{
7-
public class RequiresFeatureFactAttribute : FactAttribute
6+
public class SkippableFactAttribute : FactAttribute
87
{
9-
public RequiresFeatureFactAttribute()
8+
public SkippableFactAttribute()
9+
: this(ServerFeatures.None, ConfigSettings.None)
1010
{
1111
}
1212

13-
public RequiresFeatureFactAttribute(ServerFeatures features)
13+
public SkippableFactAttribute(ServerFeatures serverFeatures)
14+
: this(serverFeatures, ConfigSettings.None)
1415
{
15-
if (!AppConfig.SupportedFeatures.HasFlag(features))
16-
Skip = "Doesn't support " + features;
1716
}
1817

19-
public bool RequiresSsl
20-
{
21-
get => m_requiresSsl;
22-
set
23-
{
24-
m_requiresSsl = value;
25-
if (m_requiresSsl)
26-
{
27-
var csb = AppConfig.CreateConnectionStringBuilder();
28-
if (csb.SslMode == MySqlSslMode.None || csb.SslMode == MySqlSslMode.Preferred)
29-
Skip = "SSL not explicitly required";
30-
}
31-
}
32-
}
33-
34-
private bool m_requiresSsl;
35-
}
36-
37-
public class RequiresFeatureTheoryAttribute : TheoryAttribute
38-
{
39-
public RequiresFeatureTheoryAttribute()
18+
public SkippableFactAttribute(ConfigSettings configSettings)
19+
: this(ServerFeatures.None, configSettings)
4020
{
4121
}
4222

43-
public RequiresFeatureTheoryAttribute(ServerFeatures features)
23+
public SkippableFactAttribute(ServerFeatures serverFeatures, ConfigSettings configSettings)
4424
{
45-
if (!AppConfig.SupportedFeatures.HasFlag(features))
46-
Skip = "Doesn't support " + features;
25+
Skip = TestUtilities.GetSkipReason(serverFeatures, configSettings);
4726
}
4827

49-
public bool RequiresSsl
28+
public string Baseline
5029
{
51-
get => m_requiresSsl;
30+
get => null;
5231
set
5332
{
54-
m_requiresSsl = value;
55-
if (m_requiresSsl)
56-
{
57-
var csb = AppConfig.CreateConnectionStringBuilder();
58-
if (csb.SslMode == MySqlSslMode.None || csb.SslMode == MySqlSslMode.Preferred)
59-
Skip = "SSL not explicitly required";
60-
}
33+
#if BASELINE
34+
Skip = value;
35+
#endif
6136
}
6237
}
63-
64-
private bool m_requiresSsl;
6538
}
6639

67-
public class PasswordlessUserFactAttribute : FactAttribute
40+
public class SkippableTheoryAttribute : TheoryAttribute
6841
{
69-
public PasswordlessUserFactAttribute()
42+
public SkippableTheoryAttribute()
43+
: this(ServerFeatures.None, ConfigSettings.None)
7044
{
71-
if(string.IsNullOrWhiteSpace(AppConfig.PasswordlessUser))
72-
Skip = "No passwordless user";
7345
}
74-
}
7546

76-
public class BulkLoaderCsvFileFactAttribute : FactAttribute
77-
{
78-
public BulkLoaderCsvFileFactAttribute()
47+
public SkippableTheoryAttribute(ServerFeatures serverFeatures)
48+
: this(serverFeatures, ConfigSettings.None)
7949
{
80-
if(string.IsNullOrWhiteSpace(AppConfig.MySqlBulkLoaderCsvFile))
81-
Skip = "No bulk loader CSV file specified";
8250
}
83-
}
8451

85-
public class BulkLoaderTsvFileFactAttribute : FactAttribute
86-
{
87-
public BulkLoaderTsvFileFactAttribute()
52+
public SkippableTheoryAttribute(ConfigSettings configSettings)
53+
: this(ServerFeatures.None, configSettings)
8854
{
89-
if(string.IsNullOrWhiteSpace(AppConfig.MySqlBulkLoaderTsvFile))
90-
Skip = "No bulk loader TSV file specified";
9155
}
92-
}
9356

94-
public class BulkLoaderLocalCsvFileFactAttribute : FactAttribute
95-
{
96-
public BulkLoaderLocalCsvFileFactAttribute()
57+
public SkippableTheoryAttribute(ServerFeatures serverFeatures, ConfigSettings configSettings)
9758
{
98-
if(string.IsNullOrWhiteSpace(AppConfig.MySqlBulkLoaderLocalCsvFile))
99-
Skip = "No bulk loader local CSV file specified";
59+
Skip = TestUtilities.GetSkipReason(serverFeatures, configSettings);
10060
}
10161

102-
public bool TrustedHost
62+
public string Baseline
10363
{
104-
105-
get => _trustedHost;
64+
get => null;
10665
set
10766
{
108-
_trustedHost = value;
109-
110-
var csb = AppConfig.CreateConnectionStringBuilder();
111-
if (_trustedHost)
112-
{
113-
if (csb.SslMode == MySqlSslMode.None
114-
|| csb.SslMode == MySqlSslMode.Preferred
115-
|| csb.SslMode == MySqlSslMode.Required)
116-
Skip = "SslMode should be VerifyCA or higher.";
117-
}
118-
else
119-
{
120-
if (csb.SslMode == MySqlSslMode.VerifyCA
121-
|| csb.SslMode == MySqlSslMode.VerifyFull)
122-
Skip = "SslMode should be less than VerifyCA.";
123-
}
124-
}
125-
}
126-
private bool _trustedHost;
127-
}
128-
129-
public class BulkLoaderLocalTsvFileFactAttribute : FactAttribute
130-
{
131-
public BulkLoaderLocalTsvFileFactAttribute()
132-
{
133-
if(string.IsNullOrWhiteSpace(AppConfig.MySqlBulkLoaderLocalTsvFile))
134-
Skip = "No bulk loader local TSV file specified";
135-
}
136-
}
137-
138-
public class UnbufferedResultSetsFactAttribute : FactAttribute
139-
{
140-
#if !BASELINE
141-
public UnbufferedResultSetsFactAttribute()
142-
{
143-
var csb = AppConfig.CreateConnectionStringBuilder();
144-
if(csb.BufferResultSets == true)
145-
Skip = "Do not run when BufferResultSets are used";
146-
}
67+
#if BASELINE
68+
Skip = value;
14769
#endif
148-
}
149-
150-
public class TcpConnectionFactAttribute : FactAttribute
151-
{
152-
public TcpConnectionFactAttribute()
153-
{
154-
var csb = AppConfig.CreateConnectionStringBuilder();
155-
if(csb.Server.StartsWith("/", StringComparison.Ordinal) || csb.Server.StartsWith("./", StringComparison.Ordinal))
156-
Skip = "Not a TCP Connection";
157-
}
158-
}
159-
160-
public class SecondaryDatabaseRequiredFactAttribute : FactAttribute
161-
{
162-
public SecondaryDatabaseRequiredFactAttribute()
163-
{
164-
if (string.IsNullOrEmpty(AppConfig.SecondaryDatabase))
165-
Skip = "No SecondaryDatabase specified.";
70+
}
16671
}
16772
}
16873
}

tests/SideBySide/BulkLoaderAsync.cs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ one int primary key
3838
");
3939
}
4040

41-
[BulkLoaderTsvFileFact]
41+
[SkippableFact(ConfigSettings.TsvFile)]
4242
public async Task BulkLoadTsvFile()
4343
{
4444
using (MySqlConnection connection = new MySqlConnection(AppConfig.ConnectionString))
@@ -55,7 +55,7 @@ public async Task BulkLoadTsvFile()
5555
}
5656
}
5757

58-
[BulkLoaderLocalTsvFileFact]
58+
[SkippableFact(ConfigSettings.LocalTsvFile)]
5959
public async Task BulkLoadLocalTsvFile()
6060
{
6161
using (MySqlConnection connection = new MySqlConnection(AppConfig.ConnectionString))
@@ -72,7 +72,7 @@ public async Task BulkLoadLocalTsvFile()
7272
}
7373
}
7474

75-
[BulkLoaderLocalTsvFileFact]
75+
[SkippableFact(ConfigSettings.LocalTsvFile)]
7676
public async Task BulkLoadLocalTsvFileDoubleEscapedTerminators()
7777
{
7878
using (MySqlConnection connection = new MySqlConnection(AppConfig.ConnectionString))
@@ -91,7 +91,7 @@ public async Task BulkLoadLocalTsvFileDoubleEscapedTerminators()
9191
}
9292
}
9393

94-
[BulkLoaderCsvFileFact]
94+
[SkippableFact(ConfigSettings.CsvFile)]
9595
public async Task BulkLoadCsvFile()
9696
{
9797
using (MySqlConnection connection = new MySqlConnection(AppConfig.ConnectionString))
@@ -111,7 +111,7 @@ public async Task BulkLoadCsvFile()
111111
}
112112
}
113113

114-
[BulkLoaderLocalCsvFileFact]
114+
[SkippableFact(ConfigSettings.LocalCsvFile)]
115115
public async Task BulkLoadLocalCsvFile()
116116
{
117117
MySqlBulkLoader bl = new MySqlBulkLoader(m_database.Connection);
@@ -304,7 +304,7 @@ public async Task BulkLoadMissingFileName()
304304
#endif
305305
}
306306

307-
[BulkLoaderLocalCsvFileFact]
307+
[SkippableFact(ConfigSettings.LocalCsvFile)]
308308
public async Task BulkLoadMissingTableName()
309309
{
310310
MySqlBulkLoader bl = new MySqlBulkLoader(m_database.Connection);
@@ -329,11 +329,8 @@ await Assert.ThrowsAsync<MySqlException>(async () =>
329329
#endif
330330
}
331331

332-
#if BASELINE
333-
[Fact(Skip = "SourceStream not implemented")]
334-
public void BulkLoadFileStreamInvalidOperation() {}
335-
#else
336-
[BulkLoaderLocalCsvFileFact]
332+
#if !BASELINE
333+
[SkippableFact(ConfigSettings.LocalCsvFile)]
337334
public async Task BulkLoadFileStreamInvalidOperation()
338335
{
339336
using (MySqlConnection connection = new MySqlConnection(AppConfig.ConnectionString))
@@ -357,13 +354,8 @@ public async Task BulkLoadFileStreamInvalidOperation()
357354
}
358355
}
359356
}
360-
#endif
361357

362-
#if BASELINE
363-
[Fact(Skip = "SourceStream not implemented")]
364-
public void BulkLoadLocalFileStream() {}
365-
#else
366-
[BulkLoaderLocalCsvFileFact]
358+
[SkippableFact(ConfigSettings.LocalCsvFile)]
367359
public async Task BulkLoadLocalFileStream()
368360
{
369361
MySqlBulkLoader bl = new MySqlBulkLoader(m_database.Connection);
@@ -382,12 +374,7 @@ public async Task BulkLoadLocalFileStream()
382374
Assert.Equal(20, rowCount);
383375
}
384376
}
385-
#endif
386377

387-
#if BASELINE
388-
[Fact(Skip = "SourceStream not implemented")]
389-
public void BulkLoadMemoryStreamInvalidOperation() {}
390-
#else
391378
[Fact]
392379
public async Task BulkLoadMemoryStreamInvalidOperation()
393380
{
@@ -408,12 +395,7 @@ public async Task BulkLoadMemoryStreamInvalidOperation()
408395
});
409396
}
410397
}
411-
#endif
412398

413-
#if BASELINE
414-
[Fact(Skip = "SourceStream not implemented")]
415-
public void BulkLoadLocalMemoryStream() {}
416-
#else
417399
[Fact]
418400
public async Task BulkLoadLocalMemoryStream()
419401
{

0 commit comments

Comments
 (0)