elementor / lokl-cli

Interactive script to launch and manage your Lokl sites
The Unlicense
66 stars 7 forks source link

creating tests/running container with env vars #18

Open leonstafford opened 3 years ago

leonstafford commented 3 years ago

as reported by Jonathan here

Running tests on lokl/lokl did not work for me until I set LOKL_RELEASE_VERSION var before other vars on lokl-cli:

LOKL_RELEASE_VERSION="5.0.0-dev"
LOKL_DOCKER_TAG="$(set_docker_tag)"
LOKL_NAME="$(set_site_name)"
LOKL_PORT="$(set_site_port)"

I also noticed after using the new docker image I am no longer able to upload a custom theme (get ftp screen). I assume this is due to a permission issue on the file system but only just started playing with the Dockerfile.

leonstafford commented 3 years ago

OK, re the ordering of the LOKL_RELEASE_VERSION, I think I can see what's happening.

You'll find in other tests, that I'm mocking/stubbing/overriding (whatever the term is!) that env var where required, ie:

    It "sets docker image tag to php8-LOKL_RELEASE_VERSION when 8 chosen"          
      LOKL_RELEASE_VERSION=0.0.1                                                   
      Data "8"                                                                     
      When call create_site_choose_php_version                                     
      The variable LOKL_DOCKER_TAG should equal 'php8-0.0.1'                       
      The output should include \                                                  
        'create_wordpress_docker_container() called'                               
      The status should be success                                                 
    End 

Note: the most confusing part of ShellSpec is the difference between When run and When call - basically, different shell scopes and ways you'll override built-ins. I've got some tests using one or the other, and if in doubt, try the other one!

So, my hope, is that you were trying to write a test which called one of those set_docker_tag() or such functions before it was defined for testing. I just span up another instance manually and I'm pretty sure end to end test of running a site noninteractively passed before that pre-release, so I think it's just an issue in needing to provide that variable to shellspec test.

Have to run out for a bit, let me know any other info

grovejc commented 3 years ago

Originally I ran ./test.sh from the lokl root directory. It "passed" when I re-ordered the ENV Vars of lokl-cli and manually copied cli.sh to lokl. I think you are correct in stating LOKL_RELEASE_VERSION just needs added to shellspec.