@@ -26,6 +26,7 @@ import {Exec} from '../../src/exec';
2626
2727import { Cert } from '../../src/types/buildx' ;
2828
29+ const fixturesDir = path . join ( __dirname , '..' , 'fixtures' ) ;
2930// prettier-ignore
3031const tmpDir = path . join ( process . env . TEMP || '/tmp' , 'buildx-jest' ) ;
3132const tmpName = path . join ( tmpDir , '.tmpname-jest' ) ;
@@ -252,3 +253,38 @@ describe('resolveCertsDriverOpts', () => {
252253 }
253254 } ) ;
254255} ) ;
256+
257+ describe ( 'refs' , ( ) => {
258+ it ( 'returns all refs' , async ( ) => {
259+ const refs = Buildx . refs ( {
260+ dir : path . join ( fixturesDir , 'buildx-refs' )
261+ } ) ;
262+ expect ( Object . keys ( refs ) . length ) . toEqual ( 11 ) ;
263+ } ) ;
264+ it ( 'returns default builder refs' , async ( ) => {
265+ const refs = Buildx . refs ( {
266+ dir : path . join ( fixturesDir , 'buildx-refs' ) ,
267+ builderName : 'default'
268+ } ) ;
269+ expect ( Object . keys ( refs ) . length ) . toEqual ( 8 ) ;
270+ } ) ;
271+ it ( 'returns foo builder refs' , async ( ) => {
272+ const refs = Buildx . refs ( {
273+ dir : path . join ( fixturesDir , 'buildx-refs' ) ,
274+ builderName : 'foo'
275+ } ) ;
276+ expect ( Object . keys ( refs ) . length ) . toEqual ( 3 ) ;
277+ } ) ;
278+ it ( 'returns default builder refs since' , async ( ) => {
279+ const mdate = new Date ( '2023-09-05T00:00:00Z' ) ;
280+ fs . utimesSync ( path . join ( fixturesDir , 'buildx-refs' , 'default' , 'default' , '36dix0eiv9evr61vrwzn32w7q' ) , mdate , mdate ) ;
281+ fs . utimesSync ( path . join ( fixturesDir , 'buildx-refs' , 'default' , 'default' , '49p5r8und2konke5pmlyzqp3n' ) , mdate , mdate ) ;
282+ fs . utimesSync ( path . join ( fixturesDir , 'buildx-refs' , 'default' , 'default' , 'a8zqzhhv5yiazm396jobsgdw2' ) , mdate , mdate ) ;
283+ const refs = Buildx . refs ( {
284+ dir : path . join ( fixturesDir , 'buildx-refs' ) ,
285+ builderName : 'default' ,
286+ since : new Date ( '2024-01-10T00:00:00Z' )
287+ } ) ;
288+ expect ( Object . keys ( refs ) . length ) . toEqual ( 5 ) ;
289+ } ) ;
290+ } ) ;
0 commit comments