From 1ac5fbe9fca9a80b80bf484c5784e776425a3d58 Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Mon, 6 Mar 2023 10:51:59 -0500 Subject: [PATCH] Bumped coverage on utility methods fallen slightly, bumpy bump. --- index/utility_methods.go | 2 +- index/utility_methods_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/index/utility_methods.go b/index/utility_methods.go index 3febeda..8a0cf40 100644 --- a/index/utility_methods.go +++ b/index/utility_methods.go @@ -405,7 +405,7 @@ func GenerateCleanSpecConfigBaseURL(baseURL *url.URL, dir string, includeFile bo if !includeFile { dirSegs = dirSegs[:len(dirSegs)-1] } - + // relative paths are a pain in the ass, damn you digital ocean, use a single spec, and break them // down into services, please don't blast apart specs into a billion shards. if strings.Contains(dir, "../") { diff --git a/index/utility_methods_test.go b/index/utility_methods_test.go index ba0ae43..531149c 100644 --- a/index/utility_methods_test.go +++ b/index/utility_methods_test.go @@ -26,6 +26,28 @@ func TestGenerateCleanSpecConfigBaseURL_RelativeDeep(t *testing.T) { GenerateCleanSpecConfigBaseURL(u, path, true)) } +func TestGenerateCleanSpecConfigBaseURL_NoBaseURL(t *testing.T) { + + u, _ := url.Parse("/things/stuff/jazz/cakes/winter/oil") + path := "../../../../foo/bar/baz/crap.yaml#thang" + assert.Equal(t, "/things/stuff/foo/bar/baz", + GenerateCleanSpecConfigBaseURL(u, path, false)) + + assert.Equal(t, "/things/stuff/foo/bar/baz/crap.yaml#thang", + GenerateCleanSpecConfigBaseURL(u, path, true)) +} + +func TestGenerateCleanSpecConfigBaseURL_HttpStrip(t *testing.T) { + + u, _ := url.Parse(".") + path := "http://thing.com/crap.yaml#thang" + assert.Equal(t, "http://thing.com", + GenerateCleanSpecConfigBaseURL(u, path, false)) + + assert.Equal(t, "", + GenerateCleanSpecConfigBaseURL(u, "crap.yaml#thing", true)) +} + func TestSpecIndex_extractDefinitionRequiredRefProperties(t *testing.T) { c := CreateOpenAPIIndexConfig() idx := NewSpecIndexWithConfig(nil, c)