Skip to content

Commit

Permalink
Merge branch 'serverless-flare' into nicholas.hulston/serverless-flar…
Browse files Browse the repository at this point in the history
…e/autodiscover-infrastructure-files
  • Loading branch information
nhulston authored Jul 14, 2023
2 parents 475be72 + a0ff88f commit 8d44448
Show file tree
Hide file tree
Showing 46 changed files with 972 additions and 611 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@datadog/datadog-ci",
"version": "2.16.1",
"version": "2.17.0",
"description": "Run datadog actions from the CI.",
"repository": "https:/DataDog/datadog-ci",
"license": "Apache-2.0",
Expand Down Expand Up @@ -83,7 +83,7 @@
"js-yaml": "3.13.1",
"jszip": "^3.10.1",
"ora": "5.4.1",
"proxy-agent": "5.0.0",
"proxy-agent": "^6.2.1",
"rimraf": "^3.0.2",
"semver": "^7.5.3",
"simple-git": "3.16.0",
Expand Down Expand Up @@ -132,7 +132,7 @@
"jest-matcher-specific-error": "1.0.0",
"pkg": "5.5.2",
"prettier": "2.0.5",
"proxy": "1.0.2",
"proxy": "^2.1.1",
"ts-jest": "28.0.8",
"ts-node": "8.8.1",
"typescript": "4.3.5"
Expand Down
35 changes: 6 additions & 29 deletions src/commands/git-metadata/__tests__/git.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as simpleGit from 'simple-git'

import {getCommitInfo, gitRemote, newSimpleGit, stripCredentials} from '../git'
import {getCommitInfo, newSimpleGit, stripCredentials} from '../git'

interface MockConfig {
hash?: string
Expand All @@ -9,6 +9,8 @@ interface MockConfig {
}

const createMockSimpleGit = (conf: MockConfig) => ({
// eslint-disable-next-line no-null/no-null
getConfig: (_: string) => ({value: null}),
getRemotes: async (_: boolean) => {
if (conf.remotes === undefined) {
throw Error('Unexpected call to getRemotes')
Expand All @@ -32,31 +34,6 @@ const createMockSimpleGit = (conf: MockConfig) => ({
})

describe('git', () => {
describe('gitRemote', () => {
test('should choose the remote named origin', async () => {
const mock = createMockSimpleGit({
remotes: [
{name: 'first', refs: {push: 'remote1'}},
{name: 'origin', refs: {push: 'remote2'}},
],
}) as any
const remote = await gitRemote(mock)

expect(remote).toBe('remote2')
})
test('should choose the first remote', async () => {
const mock = createMockSimpleGit({
remotes: [
{name: 'first', refs: {push: 'remote1'}},
{name: 'second', refs: {push: 'remote2'}},
],
}) as any
const remote = await gitRemote(mock)

expect(remote).toBe('remote1')
})
})

describe('stripCredentials: git protocol', () => {
test('should return the same value', () => {
const input = '[email protected]:user/project.git'
Expand Down Expand Up @@ -115,15 +92,15 @@ describe('git', () => {

describe('newSimpleGit', () => {
test('should throw an error if git is not installed', async () => {
jest.spyOn(simpleGit, 'gitP').mockImplementation(() => {
jest.spyOn(simpleGit, 'simpleGit').mockImplementation(() => {
throw Error('gitp error')
})
await expect(newSimpleGit()).rejects.toThrow('gitp error')
})

test('should throw an error if revparse throws an error', async () => {
const mock = createMockSimpleGit({}) as any
jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock)
jest.spyOn(simpleGit, 'simpleGit').mockReturnValue(mock)
jest.spyOn(mock, 'revparse').mockImplementation(async () => {
throw Error('revparse error')
})
Expand All @@ -133,7 +110,7 @@ describe('git', () => {

test('should not throw any errors', async () => {
const mock = createMockSimpleGit({}) as any
jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock)
jest.spyOn(simpleGit, 'simpleGit').mockReturnValue(mock)
jest.spyOn(mock, 'revparse').mockResolvedValue('1234')

await expect(newSimpleGit()).resolves.not.toThrow()
Expand Down
Loading

0 comments on commit 8d44448

Please sign in to comment.