@skyramp/skyramp 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -54,6 +54,11 @@ struct response_wrapper {
54
54
  char *error;
55
55
  };
56
56
 
57
+ struct tester_generate_info {
58
+ char *generated_files;
59
+ char *error;
60
+ };
61
+
57
62
  #line 1 "cgo-generated-wrapper"
58
63
 
59
64
 
@@ -152,6 +157,7 @@ extern char* writeTestDescriptionWrapper(char* testDescription, char* testName);
152
157
  extern char* applyMockDescriptionWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* mockDescription, char* mockPath, char* projectPath);
153
158
  extern char* buildRequestsWrapper(char* mockDescription);
154
159
  extern struct tester_info runTesterStartWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, GoUint8 generateResult);
160
+ extern struct tester_generate_info runTesterGenerateRestWrapper(char* protocol, char* apiSchemaPath, char* alias, char* endpointPath, char* language, char* tag, char* sampleRequestPath, char* projectPath, GoInt port, GoUint8 generateRobot, GoUint8 functionalScenario, GoUint8 negativeScenario);
155
161
  extern struct tester_info runTesterStartWrapperWithGlobalHeaders(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, char* testFileName, char* testName, char* globalJsonHeaders, GoUint8 generateResult, char* projectPath, char* overrideFile, char* overrideDict);
156
162
  extern char* runTesterStatusWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testerId, GoUint8 isFormattingEnabled);
157
163
  extern char* getJsonValue(char* jsonString, char* jsonPath);
Binary file
@@ -54,6 +54,11 @@ struct response_wrapper {
54
54
  char *error;
55
55
  };
56
56
 
57
+ struct tester_generate_info {
58
+ char *generated_files;
59
+ char *error;
60
+ };
61
+
57
62
  #line 1 "cgo-generated-wrapper"
58
63
 
59
64
 
@@ -152,6 +157,7 @@ extern char* writeTestDescriptionWrapper(char* testDescription, char* testName);
152
157
  extern char* applyMockDescriptionWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* mockDescription, char* mockPath, char* projectPath);
153
158
  extern char* buildRequestsWrapper(char* mockDescription);
154
159
  extern struct tester_info runTesterStartWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, GoUint8 generateResult);
160
+ extern struct tester_generate_info runTesterGenerateRestWrapper(char* protocol, char* apiSchemaPath, char* alias, char* endpointPath, char* language, char* tag, char* sampleRequestPath, char* projectPath, GoInt port, GoUint8 generateRobot, GoUint8 functionalScenario, GoUint8 negativeScenario);
155
161
  extern struct tester_info runTesterStartWrapperWithGlobalHeaders(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, char* testFileName, char* testName, char* globalJsonHeaders, GoUint8 generateResult, char* projectPath, char* overrideFile, char* overrideDict);
156
162
  extern char* runTesterStatusWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testerId, GoUint8 isFormattingEnabled);
157
163
  extern char* getJsonValue(char* jsonString, char* jsonPath);
@@ -54,6 +54,11 @@ struct response_wrapper {
54
54
  char *error;
55
55
  };
56
56
 
57
+ struct tester_generate_info {
58
+ char *generated_files;
59
+ char *error;
60
+ };
61
+
57
62
  #line 1 "cgo-generated-wrapper"
58
63
 
59
64
 
@@ -152,6 +157,7 @@ extern char* writeTestDescriptionWrapper(char* testDescription, char* testName);
152
157
  extern char* applyMockDescriptionWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* mockDescription, char* mockPath, char* projectPath);
153
158
  extern char* buildRequestsWrapper(char* mockDescription);
154
159
  extern struct tester_info runTesterStartWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, GoUint8 generateResult);
160
+ extern struct tester_generate_info runTesterGenerateRestWrapper(char* protocol, char* apiSchemaPath, char* alias, char* endpointPath, char* language, char* tag, char* sampleRequestPath, char* projectPath, GoInt port, GoUint8 generateRobot, GoUint8 functionalScenario, GoUint8 negativeScenario);
155
161
  extern struct tester_info runTesterStartWrapperWithGlobalHeaders(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, char* testFileName, char* testName, char* globalJsonHeaders, GoUint8 generateResult, char* projectPath, char* overrideFile, char* overrideDict);
156
162
  extern char* runTesterStatusWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testerId, GoUint8 isFormattingEnabled);
157
163
  extern char* getJsonValue(char* jsonString, char* jsonPath);
Binary file
@@ -54,6 +54,11 @@ struct response_wrapper {
54
54
  char *error;
55
55
  };
56
56
 
57
+ struct tester_generate_info {
58
+ char *generated_files;
59
+ char *error;
60
+ };
61
+
57
62
  #line 1 "cgo-generated-wrapper"
58
63
 
59
64
 
@@ -152,6 +157,7 @@ extern char* writeTestDescriptionWrapper(char* testDescription, char* testName);
152
157
  extern char* applyMockDescriptionWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* mockDescription, char* mockPath, char* projectPath);
153
158
  extern char* buildRequestsWrapper(char* mockDescription);
154
159
  extern struct tester_info runTesterStartWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, GoUint8 generateResult);
160
+ extern struct tester_generate_info runTesterGenerateRestWrapper(char* protocol, char* apiSchemaPath, char* alias, char* endpointPath, char* language, char* tag, char* sampleRequestPath, char* projectPath, GoInt port, GoUint8 generateRobot, GoUint8 functionalScenario, GoUint8 negativeScenario);
155
161
  extern struct tester_info runTesterStartWrapperWithGlobalHeaders(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, char* testFileName, char* testName, char* globalJsonHeaders, GoUint8 generateResult, char* projectPath, char* overrideFile, char* overrideDict);
156
162
  extern char* runTesterStatusWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testerId, GoUint8 isFormattingEnabled);
157
163
  extern char* getJsonValue(char* jsonString, char* jsonPath);
Binary file
Binary file
@@ -54,6 +54,11 @@ struct response_wrapper {
54
54
  char *error;
55
55
  };
56
56
 
57
+ struct tester_generate_info {
58
+ char *generated_files;
59
+ char *error;
60
+ };
61
+
57
62
  #line 1 "cgo-generated-wrapper"
58
63
 
59
64
 
@@ -152,6 +157,7 @@ extern __declspec(dllexport) char* writeTestDescriptionWrapper(char* testDescrip
152
157
  extern __declspec(dllexport) char* applyMockDescriptionWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* mockDescription, char* mockPath, char* projectPath);
153
158
  extern __declspec(dllexport) char* buildRequestsWrapper(char* mockDescription);
154
159
  extern __declspec(dllexport) struct tester_info runTesterStartWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, GoUint8 generateResult);
160
+ extern __declspec(dllexport) struct tester_generate_info runTesterGenerateRestWrapper(char* protocol, char* apiSchemaPath, char* alias, char* endpointPath, char* language, char* tag, char* sampleRequestPath, char* projectPath, GoInt port, GoUint8 generateRobot, GoUint8 functionalScenario, GoUint8 negativeScenario);
155
161
  extern __declspec(dllexport) struct tester_info runTesterStartWrapperWithGlobalHeaders(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testDescription, char* testFileName, char* testName, char* globalJsonHeaders, GoUint8 generateResult, char* projectPath, char* overrideFile, char* overrideDict);
156
162
  extern __declspec(dllexport) char* runTesterStatusWrapper(char* namespace, char* kubePath, char* kubeContext, char* clusterName, char* address, char* testerId, GoUint8 isFormattingEnabled);
157
163
  extern __declspec(dllexport) char* getJsonValue(char* jsonString, char* jsonPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyramp/skyramp",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "module for leveraging skyramp cli functionality",
5
5
  "scripts": {
6
6
  "lint": "eslint 'src/**/*.js' 'src/**/*.ts' --fix",
@@ -1,8 +1,5 @@
1
- declare const Protocol: {
2
- readonly REST: 'rest';
3
- readonly GRAPHQL: 'graphql';
4
- readonly GRPC: 'grpc';
5
- };
6
-
7
- export default Protocol;
8
-
1
+ export enum Protocol {
2
+ REST = 'rest',
3
+ GRAPHQL = 'graphql',
4
+ GRPC = 'grpc'
5
+ }
@@ -2,7 +2,13 @@ import { ResponseValue } from '..';
2
2
  import { Endpoint } from './Endpoint';
3
3
  import { Scenario } from './Scenario';
4
4
  import {TrafficConfig} from './TrafficConfig';
5
+ import { Protocol } from './Protocol';
5
6
  import {oauthResponseType} from './SkyrampClient';
7
+
8
+ export enum Language {
9
+ PYTHON = 'python'
10
+ }
11
+
6
12
  interface testerStartV1Options {
7
13
  namespace?: string;
8
14
  kubePath?: string;
@@ -85,5 +91,20 @@ export declare class SkyrampClient {
85
91
  getOAuthURL(provider: string, port: number): string;
86
92
  runOAuthLoopback(provider: string, port: number): Promise<oauthResponseType>;
87
93
  registerUser(provider: string, email: string, oauthToken: string): Promise<string>;
94
+
95
+ testerGenerate(
96
+ protocol: Protocol,
97
+ apiSchemaPath: string,
98
+ alias: string,
99
+ endpointPath: string,
100
+ language: Language,
101
+ tag: string,
102
+ sampleRequestPath: string,
103
+ port: int,
104
+ generateRobot: boolean,
105
+ functionalScenario: boolean,
106
+ negativeScenario: boolean): Promise<string[]>;
107
+
88
108
  sendRequest(options: SendRequestV2Options): Promise<void>;
109
+ deployDashboard(network: string): Promise<void>;
89
110
  }
@@ -27,6 +27,11 @@ const testerInfoType = koffi.struct({
27
27
  error: 'char*',
28
28
  });
29
29
 
30
+ const testerGenerateType = koffi.struct({
31
+ generated_files: 'char*',
32
+ error: 'char*',
33
+ });
34
+
30
35
  const contractResponseType = koffi.struct({
31
36
  response: 'char*',
32
37
  error: 'char*',
@@ -57,6 +62,7 @@ const applyMockDescriptionWrapper = lib.func('applyMockDescriptionWrapper', 'str
57
62
  const initTargetWrapper = lib.func('initTargetWrapper', 'string', ['string']);
58
63
  const deployTargetWrapper = lib.func('deployTargetWrapper', 'string', ['string', 'string', 'string', 'string', 'string', 'string', 'bool']);
59
64
  const deleteTargetWrapper = lib.func('deleteTargetWrapper', 'string', ['string', 'string', 'string', 'string', 'string']);
65
+ const runTesterGenerateRestWrapper = lib.func('runTesterGenerateRestWrapper', testerGenerateType, ['string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'int', 'bool', 'bool', 'bool']);
60
66
 
61
67
  // credential / oauth related
62
68
  const readCredentialWrapper = lib.func('readCredentialWrapper', credResponseType, []);
@@ -68,6 +74,11 @@ const runOAuthLoopback = lib.func('runOAuthLoopback', oauthResponseType, ['strin
68
74
  // contract test
69
75
  // func sendRequestWrapper(address, namespace, kubePath, kubeContext, clusterName, request *C.char) *C.char {
70
76
  const sendRequestWrapper = lib.func('sendRequestWrapper', contractResponseType, ['string', 'string', 'string', 'string', 'string', 'string']);
77
+
78
+ // dashboard
79
+ const deployDockerDashboardWrapper = lib.func('deployDockerDashboardWrapper', 'string', ['string']);
80
+ const deployK8sDashboardWrapper = lib.func('deployK8sDashboardWrapper', 'string', ['string', 'string']);
81
+
71
82
  /**
72
83
  * The `SkyrampClient` class is the main client that provides methods for interacting with the Skyramp service.
73
84
  * It allows users to manage Kubernetes clusters, deploy and delete workers and targets, apply mock descriptions, and start tests.
@@ -88,8 +99,9 @@ class SkyrampClient {
88
99
  * @param {string} [clusterName] - The name of the cluster (when using individual parameters)
89
100
  * @param {string} [context] - The context of the cluster (when using individual parameters)
90
101
  * @param {string} [userToken] - The user token for authentication (when using individual parameters)
102
+ * @param {string} [directory=process.cwd()] - The working directory of the client.
91
103
  */
92
- constructor(kubeconfigPathOrOptions, clusterName, context, userToken) {
104
+ constructor(kubeconfigPathOrOptions, clusterName, context, userToken, directory = process.cwd()) {
93
105
  if (typeof kubeconfigPathOrOptions === 'object') {
94
106
  const options = kubeconfigPathOrOptions;
95
107
  if (options.kubeconfigPath || options.clusterName || options.context) {
@@ -104,10 +116,11 @@ class SkyrampClient {
104
116
  } else {
105
117
  if (kubeconfigPathOrOptions || clusterName || context) {
106
118
  this.addKubeconfig(clusterName, context, kubeconfigPathOrOptions);
119
+ }
120
+ this.workerNamespaces = [];
121
+ this.userToken = userToken;
122
+ this.projectPath = directory;
107
123
  }
108
- this.workerNamespaces = [];
109
- this.userToken = userToken;
110
- }
111
124
  }
112
125
 
113
126
  setUserToken(userToken) {
@@ -623,6 +636,41 @@ class SkyrampClient {
623
636
 
624
637
  return mockDescription;
625
638
  }
639
+
640
+ /**
641
+ * Generates test scenarios based on the provided parameters.
642
+ *
643
+ * @param {Protocol} protocol - The protocol to be used.
644
+ * @param {string} apiSchemaPath - The path to the API schema.
645
+ * @param {string} alias - The alias for the generated tests.
646
+ * @param {string} endpointPath - Endpoint REST path to filter for.
647
+ * @param {Language} language - The programming language for the generated tests.
648
+ * @param {string} tag - Tag to filter OpenAPI endpoint paths for.
649
+ * @param {string} sampleRequestPath - The path to the sample request.
650
+ * @param {int} port - The port number.
651
+ * @param {boolean} generateRobot - Whether to generate robot tests.
652
+ * @param {boolean} functionalScenario - Whether to generate functional scenarios.
653
+ * @param {boolean} negativeScenario - Whether to generate negative scenarios.
654
+ * @returns {Promise<string[]>} A promise that resolves with a list of generated test file paths.
655
+ */
656
+ async testerGenerate(protocol, apiSchemaPath, alias, endpointPath, language, tag, sampleRequestPath, port, generateRobot, functionalScenario, negativeScenario) {
657
+ return new Promise((resolve, reject) => {
658
+ runTesterGenerateRestWrapper.async(protocol, apiSchemaPath, alias, endpointPath, language, tag, sampleRequestPath, this.projectPath, port, generateRobot, functionalScenario, negativeScenario, (err, res) => {
659
+ if (err) {
660
+ console.error(`Error generating tests: ${err.name} - ${err.message}`);
661
+ reject(err);
662
+ } else if (res.error) {
663
+ console.error(`Error generating tests: ${res.error}`);
664
+ reject(new Error(res.error));
665
+ } else {
666
+ console.log(`Test generation completed successfully. Generated files: ${res.generated_files}`);
667
+
668
+ const generatedTestNames = res.generated_files.split(',');
669
+ resolve(generatedTestNames);
670
+ }
671
+ });
672
+ });
673
+ }
626
674
 
627
675
  /**
628
676
  * Sends a request to a Skyramp worker using the V2 API
@@ -635,7 +683,6 @@ class SkyrampClient {
635
683
  * @returns {Promise<string>} A promise that resolves with the response from the worker
636
684
  */
637
685
  async sendRequest(options) {
638
- // FIXME: should be sendRequest
639
686
  const req = new RequestV2(options);
640
687
  return new Promise((resolve, reject) => {
641
688
  const jsonRequest = req.toJson();
@@ -650,6 +697,31 @@ class SkyrampClient {
650
697
  });
651
698
  });
652
699
  }
700
+
701
+ async deployDashboard(network) {
702
+ if (network === undefined || network === null || network === "") {
703
+ network = "dashboard"
704
+ }
705
+ return new Promise((resolve, reject) => {
706
+ if (this.kubeConfigPath === null || this.kubeConfigPath === undefined) {
707
+ deployDockerDashboardWrapper.async(network, (err, res) => {
708
+ if (err) {
709
+ reject(err);
710
+ } else {
711
+ resolve(res);
712
+ }
713
+ });
714
+ } else {
715
+ deployK8sDashboardWrapper.async(network, (err, res) => {
716
+ if (err) {
717
+ reject(err);
718
+ } else {
719
+ resolve(res);
720
+ }
721
+ });
722
+ }
723
+ });
724
+ }
653
725
  }
654
726
 
655
727
  module.exports = SkyrampClient;