11using NUnit . Framework ;
22using System ;
33using System . IO ;
4+ using System . IO . Compression ;
45using System . Linq ;
56using System . Net . Http ;
7+ using System . Threading . Tasks ;
68
79namespace PostSyncTests
810{
911 /// <summary>
10- /// These tests are made to be run from the main branch after a merge and sync to the public S3 bucket. This is needed
12+ /// These tests are made to be run automatically after a merge and sync to the public S3 bucket. This is needed
1113 /// in order to validate that the public S3 bucket is up to date with the repository and that the sync is working.
1214 /// If running these tests in a feature branch with changes to the recommendation files, the tests should fail.
1315 /// </summary>
1416 public class S3SyncTests
1517 {
1618 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+ }
1730
1831 [ Test ]
19- public void ValidateS3RecommendationContentMatchesRepository ( )
32+ public async Task ValidateS3RecommendationContentMatchesRepository ( )
2033 {
21- var pathToRepoRecs = FindDirectoryUpwards ( "recommendation" ) ;
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+
2242 var allRepoRecs = Directory . EnumerateFiles ( pathToRepoRecs ) . ToList ( ) ;
2343
24- using var httpClient = new HttpClient ( ) ;
2544 Assert . Multiple ( async ( ) =>
2645 {
2746 foreach ( var file in allRepoRecs )
@@ -35,23 +54,5 @@ public void ValidateS3RecommendationContentMatchesRepository()
3554 }
3655 } ) ;
3756 }
38-
39- private static string FindDirectoryUpwards ( string searchPattern )
40- {
41- var fullPath = string . Empty ;
42- var currentDir = Directory . GetCurrentDirectory ( ) ;
43- while ( string . IsNullOrEmpty ( fullPath ) && currentDir != null )
44- {
45- var matchingDir = Directory . GetDirectories ( currentDir , "recommendation" ) . FirstOrDefault ( ) ;
46-
47- if ( matchingDir != null )
48- {
49- return matchingDir ;
50- }
51- currentDir = Directory . GetParent ( currentDir ) ? . FullName ;
52- }
53-
54- throw new InvalidOperationException ( $ "Couldn't find directory with name { searchPattern } when looking upward from current directory") ;
55- }
5657 }
5758}
0 commit comments