friendsofgo / killgrave

Simple way to generate mock servers written in Go

Home Page:https://friendsofgo.github.io/killgrave/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A `correct_request_schema` fails on Windows

CodingNagger opened this issue · comments

When executing tests on Windows the TestMatcherBySchema/correct_request_schema test fails. I'm not sure what the behaviour should be though. However if someone can tell me that the currently expected behaviour is, I will happily open a pull request to fix it.

$ go test -v ./...
?       github.com/friendsofgo/killgrave/cmd/killgrave  [no test files]
=== RUN   TestNewConfig
=== RUN   TestNewConfig/empty_config_file
=== RUN   TestNewConfig/valid_config_file
=== RUN   TestNewConfig/file_not_found
=== RUN   TestNewConfig/wrong_yaml_file
--- PASS: TestNewConfig (0.00s)
    --- PASS: TestNewConfig/empty_config_file (0.00s)
    --- PASS: TestNewConfig/valid_config_file (0.00s)
    --- PASS: TestNewConfig/file_not_found (0.00s)
    --- PASS: TestNewConfig/wrong_yaml_file (0.00s)
=== RUN   TestProxyModeParseString
=== RUN   TestProxyModeParseString/valid_mode
=== RUN   TestProxyModeParseString/unknown_mode
--- PASS: TestProxyModeParseString (0.00s)
    --- PASS: TestProxyModeParseString/valid_mode (0.00s)
    --- PASS: TestProxyModeParseString/unknown_mode (0.00s)
=== RUN   TestProxyModeUnmarshal
=== RUN   TestProxyModeUnmarshal/valid_mode_none
=== RUN   TestProxyModeUnmarshal/empty_mode
=== RUN   TestProxyModeUnmarshal/invalid_mode
=== RUN   TestProxyModeUnmarshal/error_input
=== RUN   TestProxyModeUnmarshal/valid_mode_all
=== RUN   TestProxyModeUnmarshal/valid_mode_missing
--- PASS: TestProxyModeUnmarshal (0.00s)
    --- PASS: TestProxyModeUnmarshal/valid_mode_none (0.00s)
    --- PASS: TestProxyModeUnmarshal/empty_mode (0.00s)
    --- PASS: TestProxyModeUnmarshal/invalid_mode (0.00s)
    --- PASS: TestProxyModeUnmarshal/error_input (0.00s)
    --- PASS: TestProxyModeUnmarshal/valid_mode_all (0.00s)
    --- PASS: TestProxyModeUnmarshal/valid_mode_missing (0.00s)
=== RUN   TestProxyMode_String
=== RUN   TestProxyMode_String/ProxyNone_must_be_return_none_string
=== RUN   TestProxyMode_String/ProxyNone_must_be_return_missing_string
=== RUN   TestProxyMode_String/ProxyNone_must_be_return_all_string
=== RUN   TestProxyMode_String/An_invalid_mode_must_return_none_string
--- PASS: TestProxyMode_String (0.00s)
    --- PASS: TestProxyMode_String/ProxyNone_must_be_return_none_string (0.00s)
    --- PASS: TestProxyMode_String/ProxyNone_must_be_return_missing_string (0.00s)
    --- PASS: TestProxyMode_String/ProxyNone_must_be_return_all_string (0.00s)
    --- PASS: TestProxyMode_String/An_invalid_mode_must_return_none_string (0.00s)
=== RUN   TestAttachWatcher
--- PASS: TestAttachWatcher (0.11s)
=== RUN   TestInitializeWatcher
=== RUN   TestInitializeWatcher/intialize_valid_watcher
=== RUN   TestInitializeWatcher/invalid_directory_to_watch
--- PASS: TestInitializeWatcher (0.00s)
    --- PASS: TestInitializeWatcher/intialize_valid_watcher (0.00s)
    --- PASS: TestInitializeWatcher/invalid_directory_to_watch (0.00s)
PASS
ok      github.com/friendsofgo/killgrave/internal       (cached)
=== RUN   TestImposterHandler
=== RUN   TestImposterHandler/valid_imposter_with_body
=== RUN   TestImposterHandler/valid_imposter_with_bodyFile
=== RUN   TestImposterHandler/valid_imposter_with_not_exists_bodyFile
--- PASS: TestImposterHandler (0.00s)
    --- PASS: TestImposterHandler/valid_imposter_with_body (0.00s)
    --- PASS: TestImposterHandler/valid_imposter_with_bodyFile (0.00s)
    --- PASS: TestImposterHandler/valid_imposter_with_not_exists_bodyFile (0.00s)
=== RUN   TestInvalidRequestWithSchema
=== RUN   TestInvalidRequestWithSchema/valid_request_no_schema
--- PASS: TestInvalidRequestWithSchema (0.00s)
    --- PASS: TestInvalidRequestWithSchema/valid_request_no_schema (0.00s)
=== RUN   TestNewProxy
=== RUN   TestNewProxy/valid_all
=== RUN   TestNewProxy/valid_mode_none
=== RUN   TestNewProxy/error_rawUrl
--- PASS: TestNewProxy (0.00s)
    --- PASS: TestNewProxy/valid_all (0.00s)
    --- PASS: TestNewProxy/valid_mode_none (0.00s)
    --- PASS: TestNewProxy/error_rawUrl (0.00s)
=== RUN   TestProxyHandler
--- PASS: TestProxyHandler (0.00s)
=== RUN   TestResponseDelayUnmarshal
=== RUN   TestResponseDelayUnmarshal/Invalid_type
=== RUN   TestResponseDelayUnmarshal/Valid_range_delay
=== RUN   TestResponseDelayUnmarshal/Range_delay_with_incorrect_delimiter
=== RUN   TestResponseDelayUnmarshal/Range_delay_with_extra_field
=== RUN   TestResponseDelayUnmarshal/Range_delay_where_second_point_is_before_first
=== RUN   TestResponseDelayUnmarshal/Valid_empty_delay
=== RUN   TestResponseDelayUnmarshal/Valid_fixed_delay
=== RUN   TestResponseDelayUnmarshal/Fixed_delay_without_unit_suffix
=== RUN   TestResponseDelayUnmarshal/Range_delay_where_second_point_invalid
--- PASS: TestResponseDelayUnmarshal (0.00s)
    --- PASS: TestResponseDelayUnmarshal/Invalid_type (0.00s)
    --- PASS: TestResponseDelayUnmarshal/Valid_range_delay (0.00s)
    --- PASS: TestResponseDelayUnmarshal/Range_delay_with_incorrect_delimiter (0.00s)
    --- PASS: TestResponseDelayUnmarshal/Range_delay_with_extra_field (0.00s)
    --- PASS: TestResponseDelayUnmarshal/Range_delay_where_second_point_is_before_first (0.00s)
    --- PASS: TestResponseDelayUnmarshal/Valid_empty_delay (0.00s)
    --- PASS: TestResponseDelayUnmarshal/Valid_fixed_delay (0.00s)
    --- PASS: TestResponseDelayUnmarshal/Fixed_delay_without_unit_suffix (0.00s)
    --- PASS: TestResponseDelayUnmarshal/Range_delay_where_second_point_invalid (0.00s)
=== RUN   TestResponseDelay
=== RUN   TestResponseDelay/Empty_delay
=== RUN   TestResponseDelay/Fixed_delay
=== RUN   TestResponseDelay/Range_delay
--- PASS: TestResponseDelay (0.00s)
    --- PASS: TestResponseDelay/Empty_delay (0.00s)
    --- PASS: TestResponseDelay/Fixed_delay (0.00s)
    --- PASS: TestResponseDelay/Range_delay (0.00s)
=== RUN   TestMatcherBySchema
=== RUN   TestMatcherBySchema/non-existing_schema_file
=== RUN   TestMatcherBySchema/empty_body_with_required_schema_file
=== RUN   TestMatcherBySchema/invalid_request_body
=== RUN   TestMatcherBySchema/correct_request_schema
    route_matchers_test.go:69: error while matching by request schema - expected: true, given: false
=== RUN   TestMatcherBySchema/imposter_without_request_schema
=== RUN   TestMatcherBySchema/malformatted_schema_file
=== RUN   TestMatcherBySchema/incorrect_request_schema
--- FAIL: TestMatcherBySchema (0.00s)
    --- PASS: TestMatcherBySchema/non-existing_schema_file (0.00s)
    --- PASS: TestMatcherBySchema/empty_body_with_required_schema_file (0.00s)
    --- PASS: TestMatcherBySchema/invalid_request_body (0.00s)
    --- FAIL: TestMatcherBySchema/correct_request_schema (0.00s)
    --- PASS: TestMatcherBySchema/imposter_without_request_schema (0.00s)
    --- PASS: TestMatcherBySchema/malformatted_schema_file (0.00s)
    --- PASS: TestMatcherBySchema/incorrect_request_schema (0.00s)
=== RUN   TestServer_Build
=== RUN   TestServer_Build/imposter_directory_not_found
=== RUN   TestServer_Build/malformatted_json
=== RUN   TestServer_Build/valid_imposter
--- PASS: TestServer_Build (0.00s)
    --- PASS: TestServer_Build/imposter_directory_not_found (0.00s)
    --- PASS: TestServer_Build/malformatted_json (0.00s)
    --- PASS: TestServer_Build/valid_imposter (0.00s)
=== RUN   TestBuildProxyMode
=== RUN   TestBuildProxyMode/ProxyAll
=== RUN   TestBuildProxyMode/ProxyMissing_Hit
=== RUN   TestBuildProxyMode/ProxyMissing_Proxied
=== RUN   TestBuildProxyMode/ProxyNone_Hit
=== RUN   TestBuildProxyMode/ProxyNone_Missing
--- PASS: TestBuildProxyMode (0.01s)
    --- PASS: TestBuildProxyMode/ProxyAll (0.00s)
    --- PASS: TestBuildProxyMode/ProxyMissing_Hit (0.00s)
    --- PASS: TestBuildProxyMode/ProxyMissing_Proxied (0.00s)
    --- PASS: TestBuildProxyMode/ProxyNone_Hit (0.00s)
    --- PASS: TestBuildProxyMode/ProxyNone_Missing (0.00s)
=== RUN   TestServer_AccessControl
--- PASS: TestServer_AccessControl (0.00s)
FAIL
FAIL    github.com/friendsofgo/killgrave/internal/server/http   0.171s
FAIL

It seems to be an issue with how the schema is loaded when using the reference loader from github.com/xeipuuv/gojsonschema which prevents the schema from being loaded from the JSON imposter. After hours digging last night, it just hit me now that I can use load the schema file directly and then use the library string loader like we do for the request body. All tests now pass on my Windows machine. Opening PR soon.

Great job!! @CodingNagger 🚀
We'll review as soon as possible.
Thanks!!!

Closes with #73