Skip to content

Commit

Permalink
added coverage for fixed remote unsupported handler
Browse files Browse the repository at this point in the history
Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Nov 26, 2023
1 parent a0d9204 commit 8335db7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 5 additions & 6 deletions index/rolodex_remote_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,22 +314,21 @@ func (i *RemoteFS) Open(remoteURL string) (fs.File, error) {
return wait.file, nil
}

processingWaiter := &waiterRemote{f: remoteParsedURL.Path}

// add to processing
i.ProcessingFiles.Store(remoteParsedURL.Path, processingWaiter)

fileExt := ExtractFileType(remoteParsedURL.Path)

if fileExt == UNSUPPORTED {
i.ProcessingFiles.Delete(remoteParsedURL.Path)
i.remoteErrors = append(i.remoteErrors, fs.ErrInvalid)
if i.logger != nil {
i.logger.Warn("[rolodex remote loader] unsupported file in reference will be ignored", "file", remoteURL, "remoteURL", remoteParsedURL.String())
}
return nil, &fs.PathError{Op: "open", Path: remoteURL, Err: fs.ErrInvalid}
}

processingWaiter := &waiterRemote{f: remoteParsedURL.Path}

// add to processing
i.ProcessingFiles.Store(remoteParsedURL.Path, processingWaiter)

// if the remote URL is absolute (http:// or https://), and we have a rootURL defined, we need to override
// the host being defined by this URL, and use the rootURL instead, but keep the path.
if i.rootURLParsed != nil {
Expand Down
11 changes: 11 additions & 0 deletions index/rolodex_remote_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,14 @@ func TestNewRemoteFS_RemoteBaseURL_EmptySpecFailIndex(t *testing.T) {
assert.Error(t, y)
assert.Equal(t, "there is nothing in the spec, it's empty - so there is nothing to be done", y.Error())
}

func TestNewRemoteFS_Unsupported(t *testing.T) {

cf := CreateOpenAPIIndexConfig()
rfs, _ := NewRemoteFSWithConfig(cf)

x, y := rfs.Open("/woof.png")
assert.Nil(t, x)
assert.Error(t, y)
assert.Equal(t, "open /woof.png: invalid argument", y.Error())
}

0 comments on commit 8335db7

Please sign in to comment.