Skip to content

Commit

Permalink
os.getLastModified
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
myarmolinsky committed Dec 5, 2024
1 parent f1e957f commit 5793f03
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 60 deletions.
7 changes: 1 addition & 6 deletions src/utils/image-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ export const isImageFresh = async (deviceType: string, version: string) => {
return false;
}

const balena = getBalenaSdk();
const lastModifiedDate = await balena.models.os.getLastModified(
deviceType,
version,
);
return lastModifiedDate < createdDate;
return true;
};

/**
Expand Down
54 changes: 0 additions & 54 deletions tests/utils/image-manager/image-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,60 +343,6 @@ describe('image-manager', function () {
afterEach(function () {
this.utilsGetFileCreatedDate.restore();
});

describe('given the file was created before the os last modified time', function () {
beforeEach(function () {
this.osGetLastModified = stub(balena.models.os, 'getLastModified');
this.osGetLastModified.returns(
Promise.resolve(new Date('2014-02-01T00:00:00.000Z')),
);
});

afterEach(function () {
this.osGetLastModified.restore();
});

it('should return false', function () {
const promise = imageManager.isImageFresh('raspberry-pi', '1.2.3');
return expect(promise).to.eventually.be.false;
});
});

describe('given the file was created after the os last modified time', function () {
beforeEach(function () {
this.osGetLastModified = stub(balena.models.os, 'getLastModified');
this.osGetLastModified.returns(
Promise.resolve(new Date('2013-01-01T00:00:00.000Z')),
);
});

afterEach(function () {
this.osGetLastModified.restore();
});

it('should return true', function () {
const promise = imageManager.isImageFresh('raspberry-pi', '1.2.3');
return expect(promise).to.eventually.be.true;
});
});

describe('given the file was created just at the os last modified time', function () {
beforeEach(function () {
this.osGetLastModified = stub(balena.models.os, 'getLastModified');
this.osGetLastModified.returns(
Promise.resolve(new Date('2014-00-01T00:00:00.000Z')),
);
});

afterEach(function () {
this.osGetLastModified.restore();
});

it('should return false', function () {
const promise = imageManager.isImageFresh('raspberry-pi', '1.2.3');
return expect(promise).to.eventually.be.false;
});
});
});
});
});
Expand Down

0 comments on commit 5793f03

Please sign in to comment.