[GitHubGoMod] Ignore comment after version (fixes #10079) (#10080)

* [GithubGoMod] Ignore comment after version (fixes #10079)

* add unit tests for GithubGoModGoVersion.transform

---------

Co-authored-by: chris48s <git@chris-shaw.dev>
This commit is contained in:
Marat Reymers
2024-04-07 10:02:49 +02:00
committed by GitHub
parent 60056fcd6c
commit caea7597f9
2 changed files with 27 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ const queryParamSchema = Joi.object({
filename: Joi.string(),
}).required()
const goVersionRegExp = /^go (.+)$/m
const goVersionRegExp = /^go ([^/\s]+)(\s*\/.+)?$/m
const filenameDescription =
'The `filename` param can be used to specify the path to `go.mod`. By default, we look for `go.mod` in the repo root'

View File

@@ -0,0 +1,26 @@
import { expect } from 'chai'
import { test, given } from 'sazerac'
import { InvalidResponse } from '../index.js'
import GithubGoModGoVersion from './github-go-mod.service.js'
describe('GithubGoModGoVersion', function () {
describe('valid cases', function () {
test(GithubGoModGoVersion.transform, () => {
given('go 1.18').expect({ go: '1.18' })
given('go 1.18 // inline comment').expect({ go: '1.18' })
given('go 1.18// inline comment').expect({ go: '1.18' })
given('go 1.18 /* block comment */').expect({ go: '1.18' })
given('go 1.18/* block comment */').expect({ go: '1.18' })
given('go 1').expect({ go: '1' })
given('go 1.2.3').expect({ go: '1.2.3' })
given('go string').expect({ go: 'string' })
})
})
describe('invalid cases', function () {
expect(() => GithubGoModGoVersion.transform('')).to.throw(InvalidResponse)
expect(() =>
GithubGoModGoVersion.transform("doesn't start with go"),
).to.throw(InvalidResponse)
})
})