1+ using NUnit . Framework ;
2+ using System ;
3+ using System . IO ;
4+ using System . IO . Compression ;
5+ using System . Linq ;
6+ using System . Net . Http ;
7+ using System . Threading . Tasks ;
8+
9+ namespace PostSyncTests
10+ {
11+ /// <summary>
12+ /// These tests are made to be run automatically after a merge and sync to the public S3 bucket. This is needed
13+ /// in order to validate that the public S3 bucket is up to date with the repository and that the sync is working.
14+ /// If running these tests in a feature branch with changes to the recommendation files, the tests should fail.
15+ /// </summary>
16+ public class S3SyncTests
17+ {
18+ private const string S3UrlPrefix = "https://s3.us-west-2.amazonaws.com/aws.portingassistant.dotnet.datastore/recommendationsync/recommendation" ;
19+ private const string TempExtractDir = "masterBranchCode" ;
20+
21+ [ TearDown ]
22+ [ SetUp ]
23+ public static void SetupAndTearDown ( )
24+ {
25+ if ( Directory . Exists ( TempExtractDir ) )
26+ {
27+ Directory . Delete ( TempExtractDir , true ) ;
28+ }
29+ }
30+
31+ [ Test ]
32+ public async Task ValidateS3RecommendationContentMatchesRepository ( )
33+ {
34+ using var httpClient = new HttpClient ( ) ;
35+ // Use always master branch since that is the only branch that should be in sync with S3
36+ var zipBytes = await httpClient . GetByteArrayAsync ( "https://github.com/aws/porting-assistant-dotnet-datastore/archive/refs/heads/master.zip" ) ;
37+ await File . WriteAllBytesAsync ( "github.zip" , zipBytes ) ;
38+ Directory . CreateDirectory ( TempExtractDir ) ;
39+ ZipFile . ExtractToDirectory ( "github.zip" , "masterBranchCode" ) ;
40+ var pathToRepoRecs = $@ "{ TempExtractDir } \porting-assistant-dotnet-datastore-master\recommendation";
41+
42+ var allRepoRecs = Directory . EnumerateFiles ( pathToRepoRecs ) . ToList ( ) ;
43+
44+ Assert . Multiple ( async ( ) =>
45+ {
46+ foreach ( var file in allRepoRecs )
47+ {
48+ var s3ObjectPath = $ "{ S3UrlPrefix } /{ file . Split ( '\\ ' ) . Last ( ) } ";
49+ var s3Content = await httpClient . GetStringAsync ( s3ObjectPath ) ;
50+ var localContent = await File . ReadAllTextAsync ( file ) ;
51+ localContent = localContent . Replace ( "\r \n " , "\n " , StringComparison . Ordinal ) ;
52+ s3Content = s3Content . Replace ( "\r \n " , "\n " , StringComparison . Ordinal ) ;
53+ Assert . AreEqual ( localContent , s3Content , $ "Content didn't match for file { file } ") ;
54+ }
55+ } ) ;
56+ }
57+ }
58+ }
0 commit comments