@@ -227,6 +227,7 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
227227 testSnapshotWithMultipleBlobs ,
228228 testExportLocalNoPlatformSplit ,
229229 testExportLocalNoPlatformSplitOverwrite ,
230+ testExportLocalForcePlatformSplit ,
230231 testSolverOptLocalDirsStillWorks ,
231232 testOCIIndexMediatype ,
232233 testLayerLimitOnMounts ,
@@ -6951,6 +6952,62 @@ func testExportLocalNoPlatformSplitOverwrite(t *testing.T, sb integration.Sandbo
69516952 },
69526953 }, "" , frontend , nil )
69536954 require .Error (t , err )
6955+ require .ErrorContains (t , err , "cannot overwrite hello-linux from" )
6956+ require .ErrorContains (t , err , "when split option is disabled" )
6957+ }
6958+
6959+ func testExportLocalForcePlatformSplit (t * testing.T , sb integration.Sandbox ) {
6960+ workers .CheckFeatureCompat (t , sb , workers .FeatureOCIExporter , workers .FeatureMultiPlatform )
6961+ c , err := New (sb .Context (), sb .Address ())
6962+ require .NoError (t , err )
6963+ defer c .Close ()
6964+
6965+ frontend := func (ctx context.Context , c gateway.Client ) (* gateway.Result , error ) {
6966+ st := llb .Scratch ().File (
6967+ llb .Mkfile ("foo" , 0600 , []byte ("hello" )),
6968+ )
6969+
6970+ def , err := st .Marshal (ctx )
6971+ if err != nil {
6972+ return nil , err
6973+ }
6974+
6975+ return c .Solve (ctx , gateway.SolveRequest {
6976+ Definition : def .ToPB (),
6977+ })
6978+ }
6979+
6980+ destDir := t .TempDir ()
6981+ _ , err = c .Build (sb .Context (), SolveOpt {
6982+ Exports : []ExportEntry {
6983+ {
6984+ Type : ExporterLocal ,
6985+ OutputDir : destDir ,
6986+ Attrs : map [string ]string {
6987+ "platform-split" : "true" ,
6988+ },
6989+ },
6990+ },
6991+ }, "" , frontend , nil )
6992+ require .NoError (t , err )
6993+
6994+ fis , err := os .ReadDir (destDir )
6995+ require .NoError (t , err )
6996+
6997+ require .Len (t , fis , 1 , "expected one files in the output directory" )
6998+
6999+ expPlatform := strings .ReplaceAll (platforms .FormatAll (platforms .DefaultSpec ()), "/" , "_" )
7000+ _ , err = os .Stat (filepath .Join (destDir , expPlatform + "/" ))
7001+ require .NoError (t , err )
7002+
7003+ fis , err = os .ReadDir (filepath .Join (destDir , expPlatform ))
7004+ require .NoError (t , err )
7005+
7006+ require .Len (t , fis , 1 , "expected one files in the output directory for platform " + expPlatform )
7007+
7008+ dt , err := os .ReadFile (filepath .Join (destDir , expPlatform , "foo" ))
7009+ require .NoError (t , err )
7010+ require .Equal (t , "hello" , string (dt ))
69547011}
69557012
69567013func readFileInImage (ctx context.Context , t * testing.T , c * Client , ref , path string ) ([]byte , error ) {
0 commit comments