2023-01-31 10:34:51 +08:00
|
|
|
/**
|
|
|
|
* Copyright 2023 actions-toolkit authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-02-01 18:47:01 +08:00
|
|
|
import {beforeEach, describe, expect, it, jest, test} from '@jest/globals';
|
2023-01-17 18:53:57 +08:00
|
|
|
|
2023-02-01 18:47:01 +08:00
|
|
|
import {BuildKit} from '../../src/buildkit/buildkit';
|
|
|
|
import {Builder} from '../../src/buildx/builder';
|
2023-01-23 17:07:14 +08:00
|
|
|
|
2023-02-01 18:47:01 +08:00
|
|
|
import {BuilderInfo} from '../../src/types/builder';
|
2023-01-17 18:53:57 +08:00
|
|
|
|
2023-01-24 07:44:31 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2023-01-23 17:07:14 +08:00
|
|
|
jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<BuilderInfo> => {
|
2023-01-17 18:53:57 +08:00
|
|
|
return {
|
|
|
|
name: 'builder2',
|
|
|
|
driver: 'docker-container',
|
2023-01-23 17:07:14 +08:00
|
|
|
lastActivity: new Date('2023-01-16 09:45:23 +0000 UTC'),
|
2023-01-17 18:53:57 +08:00
|
|
|
nodes: [
|
|
|
|
{
|
2023-02-25 02:41:10 +08:00
|
|
|
buildkit: 'v0.11.0',
|
|
|
|
'buildkitd-flags': '--debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
|
|
|
|
'driver-opts': ['BUILDKIT_STEP_LOG_MAX_SIZE=10485760', 'BUILDKIT_STEP_LOG_MAX_SPEED=10485760', 'JAEGER_TRACE=localhost:6831', 'image=moby/buildkit:latest', 'network=host'],
|
2023-01-17 18:53:57 +08:00
|
|
|
endpoint: 'unix:///var/run/docker.sock',
|
|
|
|
name: 'builder20',
|
|
|
|
platforms: 'linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6',
|
|
|
|
status: 'running'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getVersion', () => {
|
|
|
|
it('valid', async () => {
|
2023-02-20 14:19:57 +08:00
|
|
|
const builder = new Builder();
|
2023-02-18 14:31:21 +08:00
|
|
|
const builderInfo = await builder.inspect('builder2');
|
2023-02-20 14:19:57 +08:00
|
|
|
const buildkit = new BuildKit();
|
2023-02-18 14:31:21 +08:00
|
|
|
const version = await buildkit.getVersion(builderInfo.nodes[0]);
|
|
|
|
expect(version).toBe('v0.11.0');
|
2023-01-17 18:53:57 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('satisfies', () => {
|
|
|
|
test.each([
|
|
|
|
['builder2', '>=0.10.0', true],
|
|
|
|
['builder2', '>0.11.0', false]
|
|
|
|
])('given %p', async (builderName, range, expected) => {
|
2023-02-20 14:19:57 +08:00
|
|
|
const buildkit = new BuildKit();
|
2023-01-23 17:07:14 +08:00
|
|
|
expect(await buildkit.versionSatisfies(builderName, range)).toBe(expected);
|
2023-01-17 18:53:57 +08:00
|
|
|
});
|
|
|
|
});
|