pact-foundation / pact-stub-server

Standalone pact stub server
MIT License
75 stars 19 forks source link

'index out of bounds: the len is 1 but the index is 1' #9

Closed gekalogiros closed 6 years ago

gekalogiros commented 6 years ago

I'm using the Rust pact-stub-server to load my specifications and getting the following error:

$ docker run -t -p 8023:8080 -e RUST_BACKTRACE=1 -v "$(pwd)/target/pacts/:/app/pacts" pactfoundation/pact-stub-server -p 8080 -d pacts
09:44:53 [WARN] Unsupported specification version '3.0.0' found in the metadata in the pact file "\"pacts/consumer-provider.json\"", will try load it as a V2 specification
thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', /checkout/src/liballoc/vec.rs:1555:10
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:380
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:396
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:611
   5: std::panicking::begin_panic_new
             at /checkout/src/libstd/panicking.rs:553
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:521
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:497
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:92
   9: core::panicking::panic_bounds_check
             at /checkout/src/libcore/panicking.rs:68
  10: pact_matching::models::matchingrules::matchers_from_json
  11: pact_matching::models::Request::from_json
  12: pact_matching::models::Interaction::from_json
  13: pact_matching::models::Pact::from_json
  14: pact_matching::models::Pact::read_pact
  15: pact_stub_server::walkdir
  16: <core::iter::FlatMap<I, U, F> as core::iter::iterator::Iterator>::next
  17: pact_stub_server::handle_command_args
  18: pact_stub_server::main
  19: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:98
  20: std::rt::lang_start
             at /checkout/src/libstd/panicking.rs:458
             at /checkout/src/libstd/panic.rs:361
             at /checkout/src/libstd/rt.rs:59
  21: __libc_start_main
  22: _start

The pact I tried to load is the following:

{
    "provider": {
        "name": "provider"
    },
    "consumer": {
        "name": "consumer"
    },
    "interactions": [
        {
            "description": "A GET request for retrieving something",
            "request": {
                "method": "GET",
                "path": "/something"
            },
            "response": {
                "status": 200,
                "headers": {
                    "Content-Type": "application/json"
                },
                "body": {
                  ...
                }
            },
            "providerStates": [
                {
                    "name": "it-exists"
                }
            ]
        },
        {
            "description": "A GET request for retrieving something else",
            "request": {
                "method": "GET",
                "path": "/item/00000000-0000-0000-0000-000000000000",
                "matchingRules": {
                    "path": {
                        "": {
                            "matchers": [
                                {
                                    "match": "regex",
                                    "regex": "/item/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
                                }
                            ],
                            "combine": "AND"
                        }
                    }
                }
            },
            "response": {
                "status": 200,
                "headers": {
                    "Content-Type": "application/json"
                },
                "body": {
                    ...
                }
            },
            "providerStates": [
                {
                    "name": "item-exists"
                }
            ]
        }
    ],
    "metadata": {
        "pact-specification": {
            "version": "3.0.0"
        },
        "pact-jvm": {
            "version": "3.5.12"
        }
    }
}
uglyog commented 6 years ago

The stub server only supports V2 pact files at the moment. You can get the consumer test to write out the pact file in V2 format. See the docs on PactProviderRuleMk2, if you are using that.

uglyog commented 6 years ago

Version 0.0.8 supports V3 spec pact files