Test::Nginx & env settings

81 views
Skip to first unread message

Rollin Crittendon

unread,
Jun 19, 2015, 5:14:31 PM6/19/15
to openre...@googlegroups.com
I have an application that uses an environment variable.
In the application's nginx.conf it looks something like this.
====
env DATA_DIRECTORY;
====

For testing I am using Test::Nginx::Socket::Lua.

In a t-file for testing how do I get that same sort of value set?

Right now I have a hack where I pass the string in to a module with a setting.

I would like to have the module code function as before, where it read the value as-follows.
====
os.getenv("DATA_DIRECTORY")
====

Any info is much appreciated.

Yichun Zhang (agentzh)

unread,
Jun 19, 2015, 11:27:46 PM6/19/15
to openresty-en
Hello!

On Sat, Jun 20, 2015 at 5:14 AM, Rollin Crittendon wrote:
> I have an application that uses an environment variable.
> In the application's nginx.conf it looks something like this.
> ====
> env DATA_DIRECTORY;
> ====
> For testing I am using Test::Nginx::Socket::Lua.
> In a t-file for testing how do I get that same sort of value set?
>

Ah, there's no way to set that in the test file at the moment due to
the lack of interface. Maybe we can add a Perl function for that? For
example,

env_to_nginx("foo", "bar=32");

will add the following lines to the nginx.conf generated:

env foo;
env bar=32;

Will you submit a pull request for this feature? Thanks a lot!

Best regards,
-agentzh

Yichun Zhang (agentzh)

unread,
Jun 20, 2015, 12:08:57 AM6/20/15
to openresty-en
Hello!

On Sat, Jun 20, 2015 at 11:27 AM, Yichun Zhang (agentzh) wrote:
> Ah, there's no way to set that in the test file at the moment due to
> the lack of interface. Maybe we can add a Perl function for that? For
> example,
>
> env_to_nginx("foo", "bar=32");
>
> will add the following lines to the nginx.conf generated:
>
> env foo;
> env bar=32;
>
> Will you submit a pull request for this feature? Thanks a lot!
>

Okay, I've just implemented this env_to_nginx() function in the git
master branch of test-nginx:

https://github.com/openresty/test-nginx/commit/b02a309

Please see the detailed documentation in the commit.

Please let me know if it works for you :)

Thanks!
-agentzh

Yichun Zhang (agentzh)

unread,
Jun 20, 2015, 9:50:57 PM6/20/15
to Rollin Crittendon, openresty-en
Hello!

On Sun, Jun 21, 2015 at 8:19 AM, Rollin Crittendon wrote:
> Hi AgentZH,
>

Please do not use capital letters in my nick. Thank you.

> One question I have, asking offline since I am daft on this part…
> I installed the Test::Nginx on my work laptop using cpan.
> How do I get the Git Commit in on my system?
>

Easy:

mkdir -p ~/git
cd ~/git
git clone git://github.com/openresty/test-nginx.git

And then in your own project's repos, just add the -I
~/git/test-nginx/lib option to the prove command, for example,

cd /path/to/my/project
prove -I ~/git/test-nginx/lib -r t

To make the command simpler, you could add an alias to your ~/.bashrc
(assuming you're using bash):

alias prove="prove -I ~/git/test-nginx/lib"

I myself usually create a ./go shell script to automate such things instead.

Regards,
-agentzh

P.S. I'm cc'ing the list.

Karen Cushing

unread,
Apr 8, 2016, 10:35:42 AM4/8/16
to openresty-en
set $ip '';
set_by_lua $ip 'return os.getenv("DATA_DIRECTORY")';
Reply all
Reply to author
Forward
0 new messages