-
Notifications
You must be signed in to change notification settings - Fork 92
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: wrong error message about missing symlink #138
Conversation
12170c6
to
849be50
Compare
c1db580
to
426b8b9
Compare
It seems that output is being writen on "stderr" (it is injected on the cli logic) on the tests, but on the tests the log level should be the default "none" no ? Overall it is failing because the tests are pedantic with output being on stderr/stdout, unless the test explicitely commands to ignore them. Edited: Ah just saw that the default is now "info" not "none", so in this case the tests should ignore stderr when doing validation of command execution or we can change the log level on the tests. I think changing the log level on the tests for none will be the fastest/safest fix ASAP. Edited 2: the way it is failing is quite bad, will improve the error message. Edited 3 =P: now looking at the code and the test result, it should have been a different error message (more clear), so Im not quite sure what is happening, will work on a branch from this one and will let you know as soon as I got more concrete info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments regarding calling Fatal inside the terramate.Manager.
Codecov Report
@@ Coverage Diff @@
## main #138 +/- ##
==========================================
- Coverage 55.32% 53.42% -1.90%
==========================================
Files 29 29
Lines 3796 3751 -45
==========================================
- Hits 2100 2004 -96
- Misses 1549 1600 +51
Partials 147 147
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The evalSymlinks is needed because our tests pass a --chdir <path>
from t.TempDir()
and in the OSX platform this function returns paths inside the /var
link that points to /private/var
whereas the paths returned from git command are all resolved, so they mismatch and tests fails. If you don't want to automatically resolve user paths by default, then you need to fix the tests to always resolve the temp dir passed as --chdir
before calling terramate. The other changes are unrelated to this problem, but fine for me.
Having said that, the fix can be just:
diff --git a/cmd/terramate/cli/cli.go b/cmd/terramate/cli/cli.go
index 970c5b7..d8b2d60 100644
--- a/cmd/terramate/cli/cli.go
+++ b/cmd/terramate/cli/cli.go
@@ -202,8 +202,11 @@ func newCLI(
configureLogging(logLevel, logFmt, stderr)
- log.Trace().
+ logger := log.With().
Str("action", "newCli()").
+ Logger()
+
+ logger.Trace().
Msg("Get working directory.")
wd := parsedArgs.Chdir
if wd == "" {
@@ -213,23 +216,25 @@ func newCLI(
}
}
- logger := log.With().
- Str("action", "newCli()").
- Str("stack", wd).
- Logger()
+ logger.Trace().
+ Msgf("Get absolute file path of %q.", wd)
+ wd, err = filepath.Abs(wd)
+ if err != nil {
+ return nil, fmt.Errorf("getting absolute path of %q: %w", wd, err)
+ }
logger.Trace().
- Msgf("Evaluate symbolic links for %q.", wd)
- wd, err = filepath.EvalSymlinks(wd)
+ Msgf("stating directory %q", wd)
+ _, err = os.Stat(wd)
if err != nil {
- return nil, fmt.Errorf("failed evaluating symlinks for %q: %w", wd, err)
+ return nil, err
}
logger.Trace().
- Msgf("Get absolute file path of %q.", wd)
- wd, err = filepath.Abs(wd)
+ Msgf("Evaluate symbolic links for %q.", wd)
+ wd, err = filepath.EvalSymlinks(wd)
if err != nil {
- return nil, fmt.Errorf("getting absolute path of %q: %w", wd, err)
+ return nil, fmt.Errorf("failed evaluating symlinks for %q: %w", wd, err)
}
logger.Trace().
i would really not fix tests with extra code to be honest... a chdir should not fail as long as the directory exists and is accessible by the caller.. evaluating symlink and changing to the evaluated dir should be avoided by all means as there are things like automounter that dismount unused mounts... so when not in the actual mounted path the automounter might not notice it still being used and just dismount. automounter works with symlinks in that case... so the implementation will fail on systems depending on short-lived mounts.. (terraform can run for multiple hours) so i would argue to fix the tests in this case. - so should i fix tests? would that be fine? |
yeah, chdir will not fail, it's just that user provides
This is only valid if someone has a mounted path containing a symlink to somewhere outside the mount, so in this case you use the symlink just to keep the mount up but the process do not use it. Something like:
If that's the case, if you provide Now this phrase:
this is very dangerous (as a general statement) and very easy to exploit if the symlink is in a globally writable directory like But maybe makes sense in this case (really don't know)... if that's the case then we need to change the "project detection" to not use Terraform seems to evaluate the symlinks at some entrypoints, not sure if all of them: So I would say we have two options:
I'm ok with both, but You don't need to fix the tests, we can do it if they fail. |
The project's testing is now ready for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
includes #140