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

replacing flags package to read from env variables, updating README #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deranjer
Copy link
Contributor

This allows reading in env variables to set goStatic arguments.

Updated README with some more info.

Was not able to test this in Docker (not too familiar with the build process) but this does work locally on Windows when I tested it.

@deranjer
Copy link
Contributor Author

Well just realized I may not have organized the additional Docker information in the README in the most optimal way, but can change that if requested.

Copy link
Owner

@PierreZ PierreZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR 🚀

Left some comments, but I would love to have a test to check if flag's content is loaded through env var. Do you see how we could achieve this?

@@ -77,7 +79,34 @@ The fallback option is principally useful for single-page applications (SPAs) wh

The second case is useful if you have multiple SPAs within the one filesystem. e.g., */* and */admin*.

## Docker Usage
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Use goStatic with Docker" is a better name? Also, H3 title may be better in the Usage part


**Important:** The environment variables are the exact same as the cmd line args, except they are uppercase, and the "-" is replaced with a "_".

### Docker Compose Example
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Use goStatic with Docker-compose" is a better name?


You can also use environment variables to set the command arguments. Note that if you supply both `entrypoint` cmd line args and environment variables, the cmd-line args will override your environment variables.

**Important:** The environment variables are the exact same as the cmd line args, except they are uppercase, and the "-" is replaced with a "_".
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an example?

@deranjer
Copy link
Contributor Author

I don't see an easy way, but am not terribly experienced with testing in golang. Just about everything is in the main function. One possible option is to split up the main function up into multiple parts and try testing it that way. Still not the easiest, but I think it could be done.

The other option is somehow calling the main func from testing (not sure if that is even possible considering it stands up a server) or building a binary and running tests against that while handling killing the process after we test. I took an initial crack at that, but was not successful.

If we abandon golang testing entirely we would need to find an external tool to run the executable through its paces (most likely in a build pipeline) and check the output vs the expected output.

Let me know your thoughts on this. I'm sure there is something I'm missing since I'm not terribly familiar with testing in golang.

@PierreZ
Copy link
Owner

PierreZ commented Feb 18, 2022

I don't see an easy way, but am not terribly experienced with testing in golang. Just about everything is in the main function. One possible option is to split up the main function up into multiple parts and try testing it that way. Still not the easiest, but I think it could be done.

The other option is somehow calling the main func from testing (not sure if that is even possible considering it stands up a server) or building a binary and running tests against that while handling killing the process after we test. I took an initial crack at that, but was not successful.

If we abandon golang testing entirely we would need to find an external tool to run the executable through its paces (most likely in a build pipeline) and check the output vs the expected output.

Let me know your thoughts on this. I'm sure there is something I'm missing since I'm not terribly familiar with testing in golang.

Don't worry, as you are the first one to add test on goStatic, I'm expecting something simple for this PR 😉

Something like this in the main_test.go should do the trick:

package main

import "testing"

func TestFlags(t *testing.T) {
  // TODO: set multiples envs with https://pkg.go.dev/os#Setenv (some of the flags, maybe not all)
  flag.Parse()
  // check that variables are in good shape
}

This will allow me(us?) to have some simple regression tests 🚀

Let me know if you have some questions, my go is rusty, but I would be happy to help you with that.

@deranjer
Copy link
Contributor Author

Well it was good to do some more full testing. Unfortunately, one of the params is "path" which fails testing (assuming because PATH is already set in pretty much every OS). Maybe with docker it might be different, but it certainly fails the tests. There is an option to have a prefix in flags, but was unable to get that working. I'll play with it a little more, but might end up canceling this pull since it would require renaming the "path" parameter.

@PierreZ
Copy link
Owner

PierreZ commented Feb 23, 2022

Well it was good to do some more full testing. Unfortunately, one of the params is "path" which fails testing (assuming because PATH is already set in pretty much every OS). Maybe with docker it might be different, but it certainly fails the tests. There is an option to have a prefix in flags, but was unable to get that working. I'll play with it a little more, but might end up canceling this pull since it would require renaming the "path" parameter.

I can help you if needed

@harveysanders
Copy link

Resolves #50

Just throwing this on here to link the PR to the issue. I was going to take a look before I noticed this PR : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants