mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
3d7690c58b
commit
72678a3948
@ -19,10 +19,10 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CustomResourceDefinition } from "../endpoints";
|
import { CustomResourceDefinition, CustomResourceDefinitionSpec } from "../endpoints";
|
||||||
|
|
||||||
describe("Crds", () => {
|
describe("Crds", () => {
|
||||||
describe("getVersion", () => {
|
describe("getVersion()", () => {
|
||||||
it("should throw if none of the versions are served", () => {
|
it("should throw if none of the versions are served", () => {
|
||||||
const crd = new CustomResourceDefinition({
|
const crd = new CustomResourceDefinition({
|
||||||
apiVersion: "apiextensions.k8s.io/v1",
|
apiVersion: "apiextensions.k8s.io/v1",
|
||||||
@ -136,7 +136,7 @@ describe("Crds", () => {
|
|||||||
expect(crd.getVersion()).toBe("123");
|
expect(crd.getVersion()).toBe("123");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should get the version name from the version field", () => {
|
it("should get the version name from the version field, ignoring versions on v1beta", () => {
|
||||||
const crd = new CustomResourceDefinition({
|
const crd = new CustomResourceDefinition({
|
||||||
apiVersion: "apiextensions.k8s.io/v1beta1",
|
apiVersion: "apiextensions.k8s.io/v1beta1",
|
||||||
kind: "CustomResourceDefinition",
|
kind: "CustomResourceDefinition",
|
||||||
@ -147,7 +147,14 @@ describe("Crds", () => {
|
|||||||
},
|
},
|
||||||
spec: {
|
spec: {
|
||||||
version: "abc",
|
version: "abc",
|
||||||
},
|
versions: [
|
||||||
|
{
|
||||||
|
name: "foobar",
|
||||||
|
served: true,
|
||||||
|
storage: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} as CustomResourceDefinitionSpec,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(crd.getVersion()).toBe("abc");
|
expect(crd.getVersion()).toBe("abc");
|
||||||
|
|||||||
@ -48,34 +48,36 @@ export interface CRDVersion {
|
|||||||
additionalPrinterColumns?: AdditionalPrinterColumnsV1[];
|
additionalPrinterColumns?: AdditionalPrinterColumnsV1[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomResourceDefinition {
|
export interface CustomResourceDefinitionSpec {
|
||||||
spec: {
|
group: string;
|
||||||
group: string;
|
/**
|
||||||
/**
|
* @deprecated for apiextensions.k8s.io/v1 but used in v1beta1
|
||||||
* @deprecated for apiextensions.k8s.io/v1 but used previously
|
*/
|
||||||
*/
|
version?: string;
|
||||||
version?: string;
|
names: {
|
||||||
names: {
|
plural: string;
|
||||||
plural: string;
|
singular: string;
|
||||||
singular: string;
|
kind: string;
|
||||||
kind: string;
|
listKind: string;
|
||||||
listKind: string;
|
|
||||||
};
|
|
||||||
scope: "Namespaced" | "Cluster" | string;
|
|
||||||
/**
|
|
||||||
* @deprecated for apiextensions.k8s.io/v1 but used previously
|
|
||||||
*/
|
|
||||||
validation?: object;
|
|
||||||
versions?: CRDVersion[];
|
|
||||||
conversion: {
|
|
||||||
strategy?: string;
|
|
||||||
webhook?: any;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* @deprecated for apiextensions.k8s.io/v1 but used previously
|
|
||||||
*/
|
|
||||||
additionalPrinterColumns?: AdditionalPrinterColumnsV1Beta[];
|
|
||||||
};
|
};
|
||||||
|
scope: "Namespaced" | "Cluster";
|
||||||
|
/**
|
||||||
|
* @deprecated for apiextensions.k8s.io/v1 but used in v1beta1
|
||||||
|
*/
|
||||||
|
validation?: object;
|
||||||
|
versions?: CRDVersion[];
|
||||||
|
conversion: {
|
||||||
|
strategy?: string;
|
||||||
|
webhook?: any;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @deprecated for apiextensions.k8s.io/v1 but used in v1beta1
|
||||||
|
*/
|
||||||
|
additionalPrinterColumns?: AdditionalPrinterColumnsV1Beta[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CustomResourceDefinition {
|
||||||
|
spec: CustomResourceDefinitionSpec;
|
||||||
status: {
|
status: {
|
||||||
conditions: {
|
conditions: {
|
||||||
lastTransitionTime: string;
|
lastTransitionTime: string;
|
||||||
@ -159,6 +161,7 @@ export class CustomResourceDefinition extends KubeObject {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case "apiextensions.k8s.io/v1beta1":
|
case "apiextensions.k8s.io/v1beta1":
|
||||||
const { additionalPrinterColumns: apc } = this.spec;
|
const { additionalPrinterColumns: apc } = this.spec;
|
||||||
const additionalPrinterColumns = apc?.map(({ JSONPath, ...apc }) => ({ ...apc, jsonPath: JSONPath }));
|
const additionalPrinterColumns = apc?.map(({ JSONPath, ...apc }) => ({ ...apc, jsonPath: JSONPath }));
|
||||||
@ -170,9 +173,9 @@ export class CustomResourceDefinition extends KubeObject {
|
|||||||
schema: this.spec.validation,
|
schema: this.spec.validation,
|
||||||
additionalPrinterColumns,
|
additionalPrinterColumns,
|
||||||
};
|
};
|
||||||
default:
|
|
||||||
throw new Error(`Unknown apiVersion=${apiVersion}: Failed to find a version for CustomResourceDefinition ${this.metadata.name}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new Error(`Unknown apiVersion=${apiVersion}: Failed to find a version for CustomResourceDefinition ${this.metadata.name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getVersion() {
|
getVersion() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user