Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added SemVer support and fixed #273 #297

Merged
merged 10 commits into from
May 4, 2022
11 changes: 9 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ describe('installer', () => {
})
}, 100000)

test('acquires a version of Octopus CLI', () => {
return installOctopusCli('7.4.3124').then(data => {
test('fails to acquire a version of Octopus CLI', () => {
expect.assertions(1)
return installOctopusCli('0.0.0').catch(e => {
expect(<Error>e.message).toContain('Octopus CLI version not found')
})
}, 100000)

test('acquires version 8.* of Octopus CLI', () => {
return installOctopusCli('8.*').then(data => {
expect(data).toContain(path.sep + 'octo' + path.sep)
})
}, 100000)
Expand Down
88 changes: 88 additions & 0 deletions __tests__/octopusCLIVersionFetcher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {OctopusCLIVersionFetcher} from '../src/octopusCLIVersionFetcher'

describe('OctopusCLIVersionFetcher tests', () => {
test('Gets latest', () => {
const fetcher = new OctopusCLIVersionFetcher(['1.0.0', '2.0.0', '2.1.0'])

const version = fetcher.getVersion('*')

expect(version).toBe('2.1.0')
})

test('Fixed returns fixed version', () => {
const fetcher = new OctopusCLIVersionFetcher(['1.0.0', '2.0.0', '2.1.0'])

const version = fetcher.getVersion('1.0.0')

expect(version).toBe('1.0.0')
})

test('When version no exists', () => {
const fetcher = new OctopusCLIVersionFetcher(['1.0.0', '2.0.0', '2.1.0'])

expect(() => fetcher.getVersion('5.0.0')).toThrow()
})

test('Get latest minor', () => {
const fetcher = new OctopusCLIVersionFetcher([
'1.0.0',
'2.0.0',
'2.1.0',
'3.0.0'
])

const version = fetcher.getVersion('2.*')

expect(version).toBe('2.1.0')
})

test('Get latest patch', () => {
const fetcher = new OctopusCLIVersionFetcher([
'1.0.0',
'1.0.3',
'2.1.0',
'3.0.0'
])

const version = fetcher.getVersion('1.0.*')

expect(version).toBe('1.0.3')
})

test('When version spec if invalid', () => {
const fetcher = new OctopusCLIVersionFetcher(['1.0.0', '2.0.0', '2.1.0'])

expect(() => fetcher.getVersion('*.*')).toThrow()

expect(() => fetcher.getVersion('*.2')).toThrow()

expect(() => fetcher.getVersion('sdfs')).toThrow()
})

test('Get latest major', () => {
const fetcher = new OctopusCLIVersionFetcher([
'1.0.0',
'2.0.0',
'2.1.0',
'3.0.0'
])

const version = fetcher.getVersion('2')

expect(version).toBe('2.1.0')
})

test('Get latest not pre-release', () => {
const fetcher = new OctopusCLIVersionFetcher([
'1.0.0',
'1.0.3',
'2.1.0',
'3.0.0',
'4.0.0-pre'
])

const version = fetcher.getVersion('*')

expect(version).toBe('3.0.0')
})
})
Loading