mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* remove the explicit throw is new parseApi * fix parseApi to be more consitent with the older version - Add many more unit tests (these are exact copies of the old behaviour so that any changes do not change behaviour) - Make explicit, with documentation, why certain actions are being taken with the parsing of the api URL parts Signed-off-by: Sebastian Malton <smalton@mirantis.com> Co-authored-by: Sebastian Malton <smalton@mirantis.com>
110 lines
2.6 KiB
TypeScript
110 lines
2.6 KiB
TypeScript
import { KubeApi, IKubeApiLinkBase } from "../kube-api";
|
|
|
|
interface ParseAPITest {
|
|
url: string;
|
|
expected: IKubeApiLinkBase;
|
|
}
|
|
|
|
const tests: ParseAPITest[] = [
|
|
{
|
|
url: "/api/v1/namespaces/kube-system/pods/coredns-6955765f44-v8p27",
|
|
expected: {
|
|
apiBase: "/api/v1/pods",
|
|
apiPrefix: "/api",
|
|
apiGroup: "",
|
|
apiVersion: "v1",
|
|
apiVersionWithGroup: "v1",
|
|
namespace: "kube-system",
|
|
resource: "pods",
|
|
name: "coredns-6955765f44-v8p27"
|
|
},
|
|
},
|
|
{
|
|
url: "/apis/stable.example.com/foo1/crontabs",
|
|
expected: {
|
|
apiBase: "/apis/stable.example.com/foo1/crontabs",
|
|
apiPrefix: "/apis",
|
|
apiGroup: "stable.example.com",
|
|
apiVersion: "foo1",
|
|
apiVersionWithGroup: "stable.example.com/foo1",
|
|
resource: "crontabs",
|
|
name: undefined,
|
|
namespace: undefined,
|
|
},
|
|
},
|
|
{
|
|
url: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
|
expected: {
|
|
apiBase: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
|
apiPrefix: "/apis",
|
|
apiGroup: "cluster.k8s.io",
|
|
apiVersion: "v1alpha1",
|
|
apiVersionWithGroup: "cluster.k8s.io/v1alpha1",
|
|
resource: "clusters",
|
|
name: undefined,
|
|
namespace: undefined,
|
|
},
|
|
},
|
|
{
|
|
url: "/api/v1/namespaces",
|
|
expected: {
|
|
apiBase: "/api/v1/namespaces",
|
|
apiPrefix: "/api",
|
|
apiGroup: "",
|
|
apiVersion: "v1",
|
|
apiVersionWithGroup: "v1",
|
|
resource: "namespaces",
|
|
name: undefined,
|
|
namespace: undefined,
|
|
},
|
|
},
|
|
{
|
|
url: "/api/v1/secrets",
|
|
expected: {
|
|
apiBase: "/api/v1/secrets",
|
|
apiPrefix: "/api",
|
|
apiGroup: "",
|
|
apiVersion: "v1",
|
|
apiVersionWithGroup: "v1",
|
|
resource: "secrets",
|
|
name: undefined,
|
|
namespace: undefined,
|
|
},
|
|
},
|
|
{
|
|
url: "/api/v1/nodes/minikube",
|
|
expected: {
|
|
apiBase: "/api/v1/nodes",
|
|
apiPrefix: "/api",
|
|
apiGroup: "",
|
|
apiVersion: "v1",
|
|
apiVersionWithGroup: "v1",
|
|
resource: "nodes",
|
|
name: "minikube",
|
|
namespace: undefined,
|
|
},
|
|
},
|
|
{
|
|
url: "/api/foo-bar/nodes/minikube",
|
|
expected: {
|
|
apiBase: "/api/foo-bar/nodes",
|
|
apiPrefix: "/api",
|
|
apiGroup: "",
|
|
apiVersion: "foo-bar",
|
|
apiVersionWithGroup: "foo-bar",
|
|
resource: "nodes",
|
|
name: "minikube",
|
|
namespace: undefined,
|
|
},
|
|
},
|
|
];
|
|
|
|
jest.mock('../kube-watch-api.ts', () => 'KubeWatchApi');
|
|
describe("parseApi unit tests", () => {
|
|
for (const i in tests) {
|
|
const { url: tUrl, expected:tExpect} = tests[i];
|
|
test(`test #${parseInt(i)+1}`, () => {
|
|
expect(KubeApi.parseApi(tUrl)).toStrictEqual(tExpect);
|
|
});
|
|
}
|
|
}); |