-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add subprotocol for logs websocket (#80)
* fix: add subprotocol for logs websocket * fix: add unit tests for websockets utils
- Loading branch information
Showing
4 changed files
with
66 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { getWebsocketSubProtocolAndPathPrefix } from '../k8s-utils'; | ||
|
||
describe('getWebsocketSubProtocolAndPathPrefix', () => { | ||
it('should return correct path with leading slash, host, and subProtocols', () => { | ||
const path = '/example-path'; | ||
const result = getWebsocketSubProtocolAndPathPrefix(path); | ||
|
||
expect(result).toEqual({ | ||
path: '/wss/k8s/example-path', | ||
host: 'auto', | ||
subProtocols: ['base64.binary.k8s.io'], | ||
}); | ||
}); | ||
|
||
it('should set path to undefined if an empty string is provided', () => { | ||
const path = ''; | ||
const result = getWebsocketSubProtocolAndPathPrefix(path); | ||
|
||
expect(result).toEqual({ | ||
path: undefined, | ||
host: 'auto', | ||
subProtocols: ['base64.binary.k8s.io'], | ||
}); | ||
}); | ||
|
||
it('should add a leading slash to paths without one', () => { | ||
const path = 'no-leading-slash'; | ||
const result = getWebsocketSubProtocolAndPathPrefix(path); | ||
|
||
expect(result).toEqual({ | ||
path: '/wss/k8s/no-leading-slash', | ||
host: 'auto', | ||
subProtocols: ['base64.binary.k8s.io'], | ||
}); | ||
}); | ||
|
||
it('should not add an extra leading slash if the path already has one', () => { | ||
const path = '/already-has-slash'; | ||
const result = getWebsocketSubProtocolAndPathPrefix(path); | ||
|
||
expect(result).toEqual({ | ||
path: '/wss/k8s/already-has-slash', | ||
host: 'auto', | ||
subProtocols: ['base64.binary.k8s.io'], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters