devenv icon indicating copy to clipboard operation
devenv copied to clipboard

Add dotenv tests

Open ParetoOptimalDev opened this issue 2 years ago • 7 comments

It's failing as expected when run with nix eval .#tests.

This will also soon fix #772

ParetoOptimalDev avatar Aug 07 '23 17:08 ParetoOptimalDev

@domenkozar This is very prelimnary, but I just wanted to get something up and working.

I'm guessing you want to structure things like dotenv-functions differently, perhaps even having the test somehow use modules/integrations/dotenv.nix rather than introduction modules/integrations/dotenv-functions.nix.

Or perhaps it's a positive to have a module not requiring imports that is more pure?

Also obviously need to wire this into github actions, not sure if you had plans beyond just calling nix eval .#tests for that.

I also don't know the regex you'd prefer using, but I can attempt to figure out a better one than the one I currently have (which might mean just seeing what python-dotenv does). If you already have one in mind though, I can just use that.

ParetoOptimalDev avatar Aug 07 '23 17:08 ParetoOptimalDev

Looks good, we can refactor once the tests pass :fire:

domenkozar avatar Aug 07 '23 17:08 domenkozar

I'm having problems getting the regex to optionally match surrounding single quotes.

I'm pretty close though with:

https://regex101.com/r/ch9iSw/1

^'?(.*?)'? *= *'?(.*?)'?

I think the issue is with the optional space matching, followed by optional quote, followed by lazy matching any character. The pattern works on the first one because it knows the beginning of the line I believe.

Here is the current one for reference that doesn't handle quotes in regex101: https://regex101.com/r/qgtFkK/1

ParetoOptimalDev avatar Aug 07 '23 17:08 ParetoOptimalDev

I think the issue is with the optional space matching, followed by optional quote, followed by lazy matching any character. The pattern works on the first one because it knows the beginning of the line I believe.

queue thought "what if we mark the end of the line!"

Yep, that works: https://regex101.com/r/Tc8L3x/1

ParetoOptimalDev avatar Aug 07 '23 17:08 ParetoOptimalDev

Nevermind, nix and this regex test differ in result:

https://regex101.com/r/DOlw5S/1

nix-repl> builtins.match "'?(.*?)'? *= *'?([^'\n]*)" "a='{\"a\":\"b\"}'"
builtins.match "'?(.*?)'? *= *'?([^'\n]*)" "a='{\"a\":\"b\"}'"
null

ParetoOptimalDev avatar Aug 07 '23 17:08 ParetoOptimalDev

What's missing here?

domenkozar avatar Aug 21 '23 12:08 domenkozar

  • getting the regex to work for the simple cases so far
  • finish tests, likely needing to tune regex along the way
  • this to become higher priority for me over other tasks

This was high priority for me while I thought I could transition to it at work from docker-compose.

However I got stuck on #782, created a reproduction, and ran out of time and had to revert to using docker-compose again.

ParetoOptimalDev avatar Aug 21 '23 14:08 ParetoOptimalDev