mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-04-17 22:42:16 +08:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import {describe, expect, test} from 'vitest'
|
|
import {parseK8sSecret, K8sSecret} from './k8sSecret'
|
|
|
|
describe('K8sSecret type', () => {
|
|
describe('Parsing from any', () => {
|
|
test('it returns a type guarded secret', () => {
|
|
const secret = {data: {token: 'token', 'ca.crt': 'cert'}}
|
|
expect(() => parseK8sSecret(secret)).not.toThrow()
|
|
})
|
|
|
|
test('it throws an error when secret not provided', () => {
|
|
expect(() => parseK8sSecret(undefined)).toThrow()
|
|
})
|
|
|
|
test('it throws an error when there is no data field', () => {
|
|
const secret = {}
|
|
expect(() => parseK8sSecret(secret)).toThrow()
|
|
})
|
|
|
|
test('it throws an error when there is no token', () => {
|
|
const secret = {
|
|
data: {
|
|
'ca.crt': 'cert'
|
|
}
|
|
}
|
|
expect(() => parseK8sSecret(secret)).toThrow()
|
|
})
|
|
|
|
test('it throws an error when there is no ca.crt field', () => {
|
|
const secret = {data: {token: 'token'}}
|
|
expect(() => parseK8sSecret(secret)).toThrow()
|
|
})
|
|
})
|
|
})
|