2019-07-25 06:17:19 +00:00
|
|
|
import fs from 'fs';
|
2019-10-18 09:02:46 +00:00
|
|
|
import { fromStream as _fromStream } from 'hasha';
|
2019-07-25 06:17:19 +00:00
|
|
|
import { updateDependency } from '../../../lib/manager/homebrew/update';
|
2019-05-01 08:39:40 +00:00
|
|
|
|
2019-10-18 09:02:46 +00:00
|
|
|
jest.mock('hasha');
|
2019-05-25 20:48:33 +00:00
|
|
|
jest.mock('../../../lib/util/got');
|
2019-05-01 08:39:40 +00:00
|
|
|
|
2019-10-18 09:02:46 +00:00
|
|
|
const fromStream: jest.Mock<Promise<string>> = _fromStream as any;
|
2019-08-15 06:26:21 +00:00
|
|
|
|
2019-05-01 08:39:40 +00:00
|
|
|
const aide = fs.readFileSync('test/manager/homebrew/_fixtures/aide.rb', 'utf8');
|
|
|
|
const ibazel = fs.readFileSync(
|
|
|
|
'test/manager/homebrew/_fixtures/ibazel.rb',
|
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('manager/homebrew/update', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
it('updates "releases" github dependency', async () => {
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.16.1',
|
|
|
|
depName: 'Aide',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'aide',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'aide',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'0f2b7cecc70c1a27d35c06c98804fcdb9f326630de5d035afc447122186010b7',
|
2019-07-24 05:57:03 +00:00
|
|
|
url:
|
|
|
|
'https://github.com/aide/aide/releases/download/v0.16.1/aide-0.16.1.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.17.7',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream.mockResolvedValueOnce('new_hash_value');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(aide, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).not.toBe(aide);
|
|
|
|
expect(newContent).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('updates "archive" github dependency', async () => {
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.8.2',
|
|
|
|
depName: 'Ibazel',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'bazelbuild',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'bazel-watcher',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4',
|
2019-07-24 05:57:03 +00:00
|
|
|
url:
|
|
|
|
'https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.9.3',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream.mockResolvedValueOnce('new_hash_value');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(ibazel, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).not.toBe(ibazel);
|
|
|
|
expect(newContent).toMatchSnapshot();
|
|
|
|
});
|
2019-10-18 09:02:46 +00:00
|
|
|
it('returns unchanged content if fromStream promise rejects', async () => {
|
2019-05-01 08:39:40 +00:00
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.8.2',
|
|
|
|
depName: 'Ibazel',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'bazelbuild',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'bazel-watcher',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4',
|
2019-07-24 05:57:03 +00:00
|
|
|
url:
|
|
|
|
'https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.9.3',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream.mockRejectedValueOnce('Request failed');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(ibazel, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).toBe(ibazel);
|
|
|
|
});
|
|
|
|
it('returns unchanged content if url field in upgrade object is invalid', async () => {
|
|
|
|
const content = ibazel;
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.8.2',
|
|
|
|
depName: 'Ibazel',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'bazelbuild',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'bazel-watcher',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4',
|
2019-07-24 05:57:03 +00:00
|
|
|
url: 'invalid_url',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.9.3',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream.mockResolvedValueOnce('some_content');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(content, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).toBe(content);
|
|
|
|
});
|
|
|
|
it('returns unchanged content if repoName in upgrade object is invalid', async () => {
|
|
|
|
const content = ibazel;
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.8.2',
|
|
|
|
depName: 'Ibazel',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'bazelbuild',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'invalid/repo/name',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4',
|
2019-07-24 05:57:03 +00:00
|
|
|
url:
|
|
|
|
'https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.9.3',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream
|
|
|
|
.mockRejectedValueOnce('Request failed')
|
|
|
|
.mockResolvedValueOnce('some_content');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(content, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).toBe(content);
|
|
|
|
});
|
|
|
|
it('returns unchanged content if repoName in upgrade object is wrong', async () => {
|
|
|
|
const content = ibazel;
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.8.2',
|
|
|
|
depName: 'Ibazel',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'bazelbuild',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'wrong-version/archive/v10.2.3.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4',
|
2019-07-24 05:57:03 +00:00
|
|
|
url:
|
|
|
|
'https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.9.3',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream
|
|
|
|
.mockRejectedValueOnce('Request failed')
|
|
|
|
.mockResolvedValueOnce('some_content');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(content, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).toBe(content);
|
|
|
|
});
|
|
|
|
it('returns unchanged content if url field in Formula file is invalid', async () => {
|
|
|
|
const content = `
|
|
|
|
class Ibazel < Formula
|
|
|
|
desc 'IBazel is a tool for building Bazel targets when source files change.'
|
|
|
|
homepage 'https://github.com/bazelbuild/bazel-watcher'
|
|
|
|
url ???https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
|
|
|
|
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
|
|
|
|
end
|
|
|
|
`;
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.8.2',
|
|
|
|
depName: 'Ibazel',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'bazelbuild',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'bazel-watcher',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4',
|
2019-07-24 05:57:03 +00:00
|
|
|
url:
|
|
|
|
'https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.9.3',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream.mockResolvedValueOnce('some_content');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(content, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).toBe(content);
|
|
|
|
});
|
|
|
|
it('returns unchanged content if url field in Formula file is missing', async () => {
|
|
|
|
const content = `
|
|
|
|
class Ibazel < Formula
|
|
|
|
desc 'IBazel is a tool for building Bazel targets when source files change.'
|
|
|
|
homepage 'https://github.com/bazelbuild/bazel-watcher'
|
|
|
|
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
|
|
|
|
end
|
|
|
|
`;
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.8.2',
|
|
|
|
depName: 'Ibazel',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'bazelbuild',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'bazel-watcher',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4',
|
2019-07-24 05:57:03 +00:00
|
|
|
url:
|
|
|
|
'https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.9.3',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream.mockResolvedValueOnce('some_content');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(content, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).toBe(content);
|
|
|
|
});
|
|
|
|
it('returns unchanged content if sha256 field in Formula file is invalid', async () => {
|
|
|
|
const content = `
|
|
|
|
class Ibazel < Formula
|
|
|
|
desc 'IBazel is a tool for building Bazel targets when source files change.'
|
|
|
|
homepage 'https://github.com/bazelbuild/bazel-watcher'
|
|
|
|
url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
|
|
|
|
sha256 ???26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
|
|
|
|
end
|
|
|
|
`;
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.8.2',
|
|
|
|
depName: 'Ibazel',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'bazelbuild',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'bazel-watcher',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4',
|
2019-07-24 05:57:03 +00:00
|
|
|
url:
|
|
|
|
'https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.9.3',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream.mockResolvedValueOnce('some_content');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(content, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).toBe(content);
|
|
|
|
});
|
|
|
|
it('returns unchanged content if sha256 field in Formula file is missing', async () => {
|
|
|
|
const content = `
|
|
|
|
class Ibazel < Formula
|
|
|
|
desc 'IBazel is a tool for building Bazel targets when source files change.'
|
|
|
|
homepage 'https://github.com/bazelbuild/bazel-watcher'
|
|
|
|
url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
|
|
|
|
end
|
|
|
|
`;
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.8.2',
|
|
|
|
depName: 'Ibazel',
|
2019-07-24 05:51:28 +00:00
|
|
|
managerData: {
|
|
|
|
ownerName: 'bazelbuild',
|
2019-07-24 05:54:26 +00:00
|
|
|
repoName: 'bazel-watcher',
|
2019-07-24 05:51:28 +00:00
|
|
|
sha256:
|
|
|
|
'26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4',
|
2019-07-24 05:57:03 +00:00
|
|
|
url:
|
|
|
|
'https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz',
|
2019-07-24 05:51:28 +00:00
|
|
|
},
|
2019-05-01 08:39:40 +00:00
|
|
|
newValue: 'v0.9.3',
|
|
|
|
};
|
2019-10-18 09:02:46 +00:00
|
|
|
fromStream.mockResolvedValueOnce('some_content');
|
2019-05-01 08:39:40 +00:00
|
|
|
const newContent = await updateDependency(content, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).toBe(content);
|
|
|
|
});
|
2019-10-18 09:02:46 +00:00
|
|
|
it('returns unchanged content if both got requests fail', async () => {
|
|
|
|
const upgrade = {
|
|
|
|
currentValue: 'v0.16.1',
|
|
|
|
depName: 'Aide',
|
|
|
|
managerData: {
|
|
|
|
ownerName: 'aide',
|
|
|
|
repoName: 'aide',
|
|
|
|
sha256:
|
|
|
|
'0f2b7cecc70c1a27d35c06c98804fcdb9f326630de5d035afc447122186010b7',
|
|
|
|
url:
|
|
|
|
'https://github.com/aide/aide/releases/download/v0.16.1/aide-0.16.1.tar.gz',
|
|
|
|
},
|
|
|
|
newValue: 'v0.17.7',
|
|
|
|
};
|
|
|
|
fromStream
|
|
|
|
.mockRejectedValueOnce('Request failed.')
|
|
|
|
.mockRejectedValueOnce('Request failed.');
|
|
|
|
const newContent = await updateDependency(aide, upgrade);
|
|
|
|
expect(newContent).not.toBeNull();
|
|
|
|
expect(newContent).toBe(aide);
|
|
|
|
expect(newContent).toMatchSnapshot();
|
|
|
|
});
|
2019-05-01 08:39:40 +00:00
|
|
|
});
|