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

E2e test fail if you do not have the Git configured with the committer info #219

Closed
josecelano opened this issue May 17, 2022 · 0 comments · Fixed by #257
Closed

E2e test fail if you do not have the Git configured with the committer info #219

josecelano opened this issue May 17, 2022 · 0 comments · Fixed by #257
Labels
good first issue Good for newcomers

Comments

@josecelano
Copy link
Member

From: #201 (comment)

Tests fail if you execute them locally with yarn test without having any committer configuration in your Git configuration. If you remove these lines from your global git config:

[user]
        name = Your Name
        email = Your Email
        signingkey = XXXX

You will see these errors:

Summary of all failing tests
 FAIL  __tests__/e2e/main.test.ts (11.704 s)
  ● GitHub Action › should create a new job

    expect(received).toBe(expected) // Object.is equality

    Expected: "true"
    Received: undefined

      124 |     const output = executeAction(env)
      125 |
    > 126 |     expect(getOutputVariable('job_created', output.toString())).toBe('true')
          |                                                                 ^
      127 |     expect(getOutputVariable('job_commit', output.toString())).toBe(
      128 |       getLatestCommitHash(gitRepo.getDir()).getHash()
      129 |     )

      at __tests__/e2e/main.test.ts:126:65
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should get the next job

    expect(received).toBe(expected) // Object.is equality

    Expected: "test"
    Received: undefined

      145 |     const output = executeAction(env)
      146 |
    > 147 |     expect(getOutputVariable('job_payload', output.toString())).toBe(
          |                                                                 ^
      148 |       dummyPayload()
      149 |     )
      150 |     expect(getOutputVariable('job_commit', output.toString())).toBe(

      at __tests__/e2e/main.test.ts:147:65
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should mark the pending job as started

    expect(received).toBe(expected) // Object.is equality

    Expected: "true"
    Received: undefined

      169 |     const output = executeAction(env)
      170 |
    > 171 |     expect(getOutputVariable('job_started', output.toString())).toBe('true')
          |                                                                 ^
      172 |     expect(getOutputVariable('job_commit', output.toString())).toBe(
      173 |       getLatestCommitHash(gitRepo.getDir()).getHash()
      174 |     )

      at __tests__/e2e/main.test.ts:171:65
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should mark the pending job as finished

    expect(received).toBe(expected) // Object.is equality

    Expected: "true"
    Received: undefined

      198 |     })
      199 |
    > 200 |     expect(getOutputVariable('job_finished', output.toString())).toBe('true')
          |                                                                  ^
      201 |     expect(getOutputVariable('job_commit', output.toString())).toBe(
      202 |       getLatestCommitHash(gitRepo.getDir()).getHash()
      203 |     )

      at __tests__/e2e/main.test.ts:200:66
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should allow to overwrite commit signing key

    Command failed: git log --show-signature -n1
    fatal: your current branch 'main' does not have any commits yet

      88 | export function gitLogForLatestCommit(gitRepoDir: string): string {
      89 |   const output = cp
    > 90 |     .execFileSync('git', ['log', '--show-signature', '-n1'], {
         |      ^
      91 |       cwd: gitRepoDir
      92 |     })
      93 |     .toString()

      at gitLogForLatestCommit (src/__tests__/helpers.ts:90:6)
      at __tests__/e2e/main.test.ts:224:47
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should allow to disable commit signing for a given commit

    Command failed: git log --show-signature -n1
    fatal: your current branch 'main' does not have any commits yet

      88 | export function gitLogForLatestCommit(gitRepoDir: string): string {
      89 |   const output = cp
    > 90 |     .execFileSync('git', ['log', '--show-signature', '-n1'], {
         |      ^
      91 |       cwd: gitRepoDir
      92 |     })
      93 |     .toString()

      at gitLogForLatestCommit (src/__tests__/helpers.ts:90:6)
      at __tests__/e2e/main.test.ts:243:47
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should always overwrite the commit author with: NautilusCyberneering[bot] <bot@nautilus-cyberneering.de>

    Command failed: git log --show-signature -n1
    fatal: your current branch 'main' does not have any commits yet

      88 | export function gitLogForLatestCommit(gitRepoDir: string): string {
      89 |   const output = cp
    > 90 |     .execFileSync('git', ['log', '--show-signature', '-n1'], {
         |      ^
      91 |       cwd: gitRepoDir
      92 |     })
      93 |     .toString()

      at gitLogForLatestCommit (src/__tests__/helpers.ts:90:6)
      at __tests__/e2e/main.test.ts:259:47
      at fulfilled (__tests__/e2e/main.test.ts:28:58)


Test Suites: 1 failed, 20 passed, 21 total
Tests:       7 failed, 117 passed, 124 total

I think this is related to #175. Tests should set up the configuration they need and not rely on preexisting configurations.

Probably, Git is failing to create the new commits because of the "unknown identify" error.

This error could be also related to this issue. From the tests output, you cannot know the problem was the missing committer configuration. But it's only because jest hides the action output. The tests are failing in the "assert" (when we get info of the latest commit) step instead of in the "commit" step.

Maybe the problem is the function executeAction captures the error and it returns a string anyway.

function executeAction(env): string | Buffer {
  const np = process.execPath
  const ip = path.join(__dirname, '..', '..', 'lib', 'main.js')
  const options: cp.ExecFileSyncOptions = {
    env
  }

  let output: string

  try {
    output = cp.execFileSync(np, [ip], options).toString()
  } catch (error) {
    output = getErrorMessage(error)
  }

  return output
}

I think I did that because of this test:

  it('should return an error for invalid actions', async () => {
    const gitRepo = await createInitializedGitRepo()

    const env = {
      ...process.env,
      INPUT_QUEUE_NAME: 'queue-name',
      INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
      INPUT_ACTION: 'INVALID ACTION',
      INPUT_JOB_PAYLOAD: dummyPayload(),
      INPUT_GIT_COMMIT_NO_GPG_SIGN: true
    }

    const output = executeAction(env)

    expect(output).toEqual(
      expect.stringContaining(
        '::error::Invalid action. Actions can only be: create-job, next-job, start-job, finish-job'
      )
    )
  })

It's the only case when we need to capture the exception. I suppose the obvious solution is to move the try/catch to that test, for the time being. If we have more cases wher<e we need to capture the exception we can implement a different function like expectActionExcetutionToThrowError(...).

@josecelano josecelano added the good first issue Good for newcomers label May 17, 2022
This was referenced Jun 1, 2022
josecelano added a commit to josecelano/git-queue that referenced this issue Jun 7, 2022
@josecelano josecelano linked a pull request Jun 7, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant