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

fix: tests now work with different sh implementations #3505

Closed
wants to merge 8 commits into from

Conversation

finnag
Copy link
Contributor

@finnag finnag commented Jun 9, 2023

what

Ignore output from commands that test failure scenarios with sh in workflow hooks

why

4915d8d introduced output checking of failing commands in workflow hook script tests. However, the output from sh is not stable between different platforms, so this broke tests on at least Mac OS X.

The following commands have unstable output between architectures:

sh -c "echo 'a"
sh -c "jlkjlkefjelkfjelkfj"

Fix by interpreting empty expected output as any output is valid in this test.

tests

I have tested my changes by

  • make docker/test
  • make test # on a mac

references

@finnag finnag requested a review from a team as a code owner June 9, 2023 09:42
@github-actions github-actions bot added the go Pull requests that update Go code label Jun 9, 2023
4915d8d introduced output checking of failing
commands in workflow hook script tests. However, the output
from sh is not stable between different platforms, so
this broke tests on at least Mac OS X.

The following commands have unstable output between architectures:

  sh -c "echo 'a"
  sh -c "lkjlkj"

Fix by interpreting empty expected output as any output is valid in
this test.
@nitrocode
Copy link
Member

cc @X-Guardian

@nitrocode
Copy link
Member

Thank you @finnag for contributing this. Are you running atlantis on macos?

Since you, @X-Guardian , contributed #3422, could you be a second pair of eyes and review this PR to ensure this works and is implemented as expected?

@X-Guardian
Copy link
Contributor

@finnag, please detail the exact output you saw on the mac. It would be better to adjust the check to cope with the various output differences rather than ignore the check altogether.

@finnag
Copy link
Contributor Author

finnag commented Jun 12, 2023

I sometimes develop on a mac, and run atlantis locally while developing. That's where I usually run the tests. In production it runs on a linux server somewhere. Looks like mac outputs the same as centos.

There are many sh variants, here are some:

% /bin/sh -c "echo 'a"   # locally on a Mac
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file

% docker run centos /bin/sh -c "echo 'a"
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file

% docker run alpine /bin/sh -c "echo 'a" 
/bin/sh: syntax error: unterminated quoted string

% docker run debian /bin/sh -c "echo 'a" 
/bin/sh: 1: Syntax error: Unterminated quoted string

and for the unknown command:

% /bin/sh -c jefjef
/bin/sh: jefjef: command not found

% docker run centos /bin/sh -c jefjef
/bin/sh: jefjef: command not found

% docker run alpine /bin/sh -c jefjef 
/bin/sh: jefjef: not found

% docker run debian /bin/sh -c jefjef 
/bin/sh: 1: jefjef: not found

@finnag
Copy link
Contributor Author

finnag commented Jun 14, 2023

@X-Guardian what do you think? the current tests require dash as /bin/sh. fails with bash (macos, centos) and busybox/ash (alpine). Doesn't feel necessary to force developers to use dash or docker to run the tests.

@GenPage
Copy link
Member

GenPage commented Jun 20, 2023

I agree with @finnag here, we shouldn't be checking for shell outputs in unit tests. If we really feel it's vital to be checking shell outputs as part of testing, it should be moved to e2e tests where proper testing against different shell programs can be setup and performed.

GenPage
GenPage previously approved these changes Jun 20, 2023
@GenPage GenPage enabled auto-merge (squash) June 20, 2023 19:03
GenPage
GenPage previously approved these changes Jun 20, 2023
@GenPage GenPage added waiting-on-response Waiting for a response from the user needs tests Change requires tests labels Jul 7, 2023
auto-merge was automatically disabled August 4, 2023 08:13

Head branch was pushed to by a user without write access

@finnag
Copy link
Contributor Author

finnag commented Aug 4, 2023

updated to match latest main.

@github-actions
Copy link

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.

@github-actions github-actions bot added the Stale label Sep 12, 2023
@finnag
Copy link
Contributor Author

finnag commented Sep 13, 2023

There is now an alternative fix for this in main, so this is no longer required.

@finnag finnag closed this Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code needs tests Change requires tests waiting-on-response Waiting for a response from the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants