nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.4k stars 331 forks source link

Test fixes #1415

Closed ac000 closed 2 months ago

ac000 commented 2 months ago

Two small fixes.

1) Fix an issue with routing tests when njs is not enabled

2) Suppress cargo-component output when we check for its existence

ac000 commented 2 months ago

Split njs test out into its own function so we now get

collected 115 items / 113 deselected / 2 selected                              

test/test_routing.py::test_routes_match_if PASSED
test/test_routing.py::test_routes_match_if_njs SKIPPED (Unit has no njs
module(s))

================= 1 passed, 1 skipped, 113 deselected in 0.71s =================
$ git range-diff 63fd0c4f...2a06b4bb
1:  fae7b575 < -:  -------- tests: Fix routing tests in the no njs case
-:  -------- > 1:  8e6c4041 tests: Fix routing tests in the no njs case
2:  63fd0c4f = 2:  2a06b4bb tests: Suppress cargo-component output
andrew@kappa unit:test-fixes $ git range-diff --creation-factor=100 63fd0c4f...2a06b4bb
1:  fae7b575 ! 1:  8e6c4041 tests: Fix routing tests in the no njs case
    @@ Commit message
         Signed-off-by: Andrew Clayton <a.clayton@nginx.com>

      ## test/test_routing.py ##
    -@@ test/test_routing.py: def test_routes_match_if():
    +@@ test/test_routing.py: def test_routes_match_destination_proxy():
    +     assert client.get()['status'] == 200, 'proxy'

    -     # njs

    -+    if not option.available['modules']['njs']:
    -+        return
    +-def test_routes_match_if():
    ++def set_if(condition):
    ++    assert 'success' in client.conf(f'"{condition}"', 'routes/0/match/if')
    + 
    +-    def set_if(condition):
    +-        assert 'success' in client.conf(f'"{condition}"', 'routes/0/match/if')
     +
    ++def test_routes_match_if():
    + 
    +     def try_if(condition, status):
    +         set_if(condition)
    +@@ test/test_routing.py: def test_routes_match_if():
    +     assert client.get(url='/foo_empty?foo')['status'] == 200
    +     assert client.get(url='/foo?foo=1')['status'] == 404
    + 
    +-    # njs
    ++def test_routes_match_if_njs(require):
    ++    require({'modules': {'njs': 'any'}})
    ++
    ++    assert 'success' in client.conf(
    ++        {
    ++            "listeners": {"*:8080": {"pass": "routes"}},
    ++            "routes": [
    ++                {
    ++                    "match": {"method": "GET"},
    ++                    "action": {"return": 200},
    ++                }
    ++            ],
    ++            "applications": {},
    ++        }
    ++    )
    + 
          set_if('`${args.foo == \'1\'}`')
          assert client.get(url='/foo_1?foo=1')['status'] == 200
    -     assert client.get(url='/foo_2?foo=2')['status'] == 404
2:  63fd0c4f = 2:  2a06b4bb tests: Suppress cargo-component output
ac000 commented 2 months ago

Rebased with master.

ac000 commented 2 months ago

Rebased with master

$ git range-diff 53d726a1...cff5e092
-:  -------- > 1:  c5846ba3 ci: Fix wasmtime paths in ci.yml
-:  -------- > 2:  46ddb010 ci: Trigger ci.yml for changes under pkg/contrib
1:  22125366 = 3:  6976a614 tests: Fix routing tests in the no njs case
2:  53d726a1 = 4:  cff5e092 tests: Suppress cargo-component output