-
Notifications
You must be signed in to change notification settings - Fork 6
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
Origin/suggest relevant envs #32
Conversation
Please mention relevant issues in description, so that they get tracked, and eventually closed. |
controller/controller.go
Outdated
} | ||
|
||
if len(o.Env) > 0 { | ||
envMap, err := preprocess.GetL2EnvVariables(dir) |
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.
Get envMap
is common to both the if statements (this and the previous one). So, we should get it outside/before both the if statement
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.
Yes extracted it out processEnvironmentVariables()
@@ -130,3 +162,15 @@ func checkBHost(t *testing.T, envMap map[string]EnvData) { | |||
} | |||
} | |||
} | |||
|
|||
func checkBHostDoesNotExist(t *testing.T, envMap map[string]EnvData) { | |||
if _, ok := envMap["BHOST"]; ok { |
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.
What is BHOST / AHOST key ?
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.
It is variables from env file
Let's set default value to |
controller/controller.go
Outdated
func processEnvironmentVariables(o *lama2cmd.Opts, directory string) { | ||
envMap, err := preprocess.GetL2EnvVariables(directory) | ||
if err != nil { | ||
log.Error().Str("Type", "Preprocess").Msg(err.Error()) |
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.
Leave a comment highlighting what sort of error can be expected here after verification. I think it could only be a JSON marshalling error. Everything else returns an empty map.
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.
Yes
controller/controller.go
Outdated
log.Error().Str("Type", "Preprocess").Msg(err.Error()) | ||
os.Exit(0) | ||
} | ||
if o.Env == "" { // -e='' |
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 order of these checks must be simplified:
- Is it an
-e
invocation? ( != unset)- is it empty? handle
- is it not empty? handle
- Not an
-e
continue.
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.
Also if it is a -e
request, for efficiency sake, once printing is done, we should simply exit the app, right? We are not doing that now, continuing processing.
Essentially -e
is a editor extension support command; we don't expect a normal user to poke into it.
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.
Got it
controller/controller.go
Outdated
} | ||
} | ||
|
||
func marshalAndPrintJSON(data interface{}) { |
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.
Should go into utils, not clutter controller.
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.
Yes
controller/controller.go
Outdated
os.Exit(0) | ||
} | ||
|
||
func getRelevantEnvs(envMap map[string]map[string]interface{}, o *lama2cmd.Opts) map[string]interface{} { |
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.
All these env related functionalities should goto its own file.
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.
Got it
tests/basic_commands_test.go
Outdated
func runL2CommandAndGetOutput(t *testing.T, cmdArgs ...string) string { | ||
|
||
// Get the full path to the l2 binary | ||
l2BinPath := "../build/l2" |
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.
How do we ensure check is happening on the latest binary? Any mechanism to avoid the error?
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.
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.
tests/basic_commands_test.go
Outdated
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func runL2CommandAndGetOutput(t *testing.T, cmdArgs ...string) string { |
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.
If this is a utility method (looks like it), we should not be taking in the testing object as a parameter. It confuses the reader.
In functions, as a rule, strive for minimum number of params.
For sophistication, compose functions
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.
Okay got it, I have a similar function in anohter file will add both in test utils file
Env/env.go
Outdated
@@ -0,0 +1,48 @@ | |||
package env |
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.
Recommend changing the package name to something more non-generic (env
is a common name, with meaning at systems level).
Maybe call it: l2env
Env/env.go
Outdated
os.Exit(0) | ||
} | ||
// Check if it's an -e invocation | ||
if o.Env != "UNSET_VU5TRVQ" { |
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.
As mentioned earlier, if it is o.Env
we should stop processing, and exit the app.
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.
In this function im exiting, should I remove it from this and use the exit in the conditions?
MarshalAndPrintJSON()
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.
os.exit(0)
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 name and logic doesn't match. What you are actually doing is:
MarshalAndPrintJSONAndExit
:)
It is important to keep meaning and actions same.
Either name should be printExit
or something like that, or you should move exit outside.
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.
Right :|
Ive added in the conditions
tests/utils/test_utils.go
Outdated
return nil | ||
} | ||
|
||
func getL2BinaryPath() (string, error) { |
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.
getLocalL2BinaryPath
to differentiate from system binary.
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.
right
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 πΎ
[feat]: Firecamp Echo Server
What type of MR is this?
Description
Issue
More autocomplete problem
Important files to start review from
controller.go
l2 --help
Added tests?
Added to documentation?
If documentation update is there then run
make mkdocs
once PR is in acceptable state.