Skip to content

Commit

Permalink
Merge pull request #297 from OctopusDeploy/fix-273
Browse files Browse the repository at this point in the history
feat: added SemVer support and fixed #273
  • Loading branch information
jbristowe authored May 4, 2022
2 parents 526afca + a09f4c1 commit a57993d
Show file tree
Hide file tree
Showing 8 changed files with 1,334 additions and 4,063 deletions.
17 changes: 15 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 All @@ -20,4 +27,10 @@ describe('installer', () => {
expect(data).toContain(path.sep + 'octo' + path.sep)
})
}, 100000)

test('acquires latest version of Octopus CLI', () => {
return installOctopusCli('*').then(data => {
expect(data).toContain(path.sep + 'octo' + path.sep)
})
}, 100000)
})
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

0 comments on commit a57993d

Please sign in to comment.