# create-smktest

> Smoketest suites gerentator in jest format

Latest version **0.0.8** (published 2021-11-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install create-smktest
pnpm add create-smktest
yarn add create-smktest
bun add create-smktest
```

Provides the command `create-smktest`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2021-11-09 |
| First published | 2021-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 38 |
| Unpacked size | 3.8 MB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Author | Cannavit |
| Maintainers | cecilio.cannav |
| Keywords | smoketest, smoke, test, smktest, jest, automation, suites, apis, backend, nodejs |

## Links

- npm: https://www.npmjs.com/package/create-smktest
- Repository: .
- npm.io page: https://npm.io/package/create-smktest

## Dependencies (38)

- [arg](https://npm.io/package/arg.md) ^5.0.0
- [esm](https://npm.io/package/esm.md) ^3.2.25
- [ncp](https://npm.io/package/ncp.md) ^2.0.0
- [jest](https://npm.io/package/jest.md) ^27.0.4
- [link](https://npm.io/package/link.md) ^0.1.5
- [ping](https://npm.io/package/ping.md) ^0.4.1
- [axios](https://npm.io/package/axios.md) ^0.21.4
- [chalk](https://npm.io/package/chalk.md) ^4.1.1
- [execa](https://npm.io/package/execa.md) ^5.1.1
- [listr](https://npm.io/package/listr.md) ^0.14.3
- [assert](https://npm.io/package/assert.md) ^2.0.0
- [dotenv](https://npm.io/package/dotenv.md) ^10.0.0
- [figlet](https://npm.io/package/figlet.md) ^1.5.0
- [listr2](https://npm.io/package/listr2.md) ^3.12.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [base-64](https://npm.io/package/base-64.md) ^1.0.0
- [express](https://npm.io/package/express.md) ^4.17.1
- [install](https://npm.io/package/install.md) ^0.13.0
- [shelljs](https://npm.io/package/shelljs.md) ^0.8.4
- [slashes](https://npm.io/package/slashes.md) ^2.0.2
- [inquirer](https://npm.io/package/inquirer.md) ^8.0.0
- [readline](https://npm.io/package/readline.md) ^1.3.0
- [promisify](https://npm.io/package/promisify.md) 0.0.3
- [valid-url](https://npm.io/package/valid-url.md) ^1.0.9
- [github-api](https://npm.io/package/github-api.md) ^3.4.0
- [linebyline](https://npm.io/package/linebyline.md) ^1.3.0
- [make-error](https://npm.io/package/make-error.md) ^1.3.6
- [pkg-install](https://npm.io/package/pkg-install.md) ^1.0.0
- [@octokit/rest](https://npm.io/package/@octokit/rest.md) ^18.6.7
- [child_process](https://npm.io/package/child_process.md) ^1.0.2
- [smktest-utils](https://npm.io/package/smktest-utils.md) ^1.1.4
- [util.promisify](https://npm.io/package/util.promisify.md) ^1.1.1
- [axios-curlirize](https://npm.io/package/axios-curlirize.md) ^1.3.7
- [swagger-smktest](https://npm.io/package/swagger-smktest.md) ^0.2.5
- [generate-unique-id](https://npm.io/package/generate-unique-id.md) ^2.0.1
- [inquirer-table-prompt](https://npm.io/package/inquirer-table-prompt.md) ^0.2.1
- [listr-update-renderer](https://npm.io/package/listr-update-renderer.md) ^0.5.0
- [@kubernetes/client-node](https://npm.io/package/@kubernetes/client-node.md) ^0.13.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.0.8 (latest) — 2021-11-09
- 0.0.7 — 2021-11-03
- 0.0.6 — 2021-11-03
- 0.0.5 — 2021-11-03
- 0.0.4 — 2021-11-03
- 0.0.3 — 2021-11-02
- 0.0.2 — 2021-11-02
- 0.0.1 — 2021-11-02
- 0.0.0 — 2021-11-01

## README

# 💨🔥💨  Create Smoke Test (create-smktest)


#### ✅ Kubernetes, ✅ Automatic-test, ✅ Smoke Test, ✅  Ephemeral service

Smoke Master is a service dedicated to conducting smoke testing on kubernetes pipelines. It does not require any configuration in the cluster. The service accesses the cluster by SSH performs the tests and then is automatically destroyed, which makes it totally secure.
The smoke tests focus on validating the stability of the cluster. It is highly recommended when combining multiple projects in a single kubernetes server.It can be run 100% from the gitlab pipeline.

## Table of Contents

- [Smoke Master configuration options](#smoke-master-configuration-options)
- [Table of Commands Smoke-Master](#table-of-commands-smoke-master)
- [Connect test remote kubernetes cluster](#connect-test-remote-kubernetes-cluster)
- [Available smoke test types](#available-smoke-test-types)
  - [Check Ingress](#check-ingress)
  - [Check Conditions](#check-conditions)
  - [Check Logs Inside of the Pods](#check-logs-inside-of-the-pods)
  - [Assert with CURL petitions](#assert-with-curl-petitions)
  - [Check Volumes](#check-volumes)
  - [Check publics apis using SWAGGER](#check-publics-apis-using-swagger)
  - [Check publics apis using SWAGGER with Authentication](#check-publics-apis-using-swagger-with-authentication)
  - [Check notwork from services](#check-notwork-from-services)

## Criteria content:

| Criteria name         | Inputs | Criterial Command       | Criteria content                                                                                    |
| :-------------------- | :----- | :---------------------- | :-------------------------------------------------------------------------------------------------- |
| Cluster Coverage      | 🟢     | --cluster-coverage      | --check-cluster, --check-nodes, --check-cluster-info, --check-internet-access, --check-main-ingress |
| Service Coverage      | 🟢     | --service-coverage      | --services-up, --check-pods-running                                                                 |
| Resources Up          | 🟢     | --resources-up          | --volume-conditions, --volume-persistent                                                            |
| Dependencies Coverage | 🟢     | --dependencies-coverage | --images-not-latest                                                                                 |

##### 🟢 - Inputs not required

##### 🟠 - Input required

## Library status:

| Type of Test                       | Inputs | Command                                       |
| :--------------------------------- | :----- | :-------------------------------------------- |
| Check Logs Content                 | 🟢     | --check-pods-logs                             |
| Check Pods Status                  | 🟢     | --check-pods-running                          |
| Check if Ingress are active        | 🟢     | --check-ingress                               |
| Check endpoint                     | 🟢     | --assert-curl                                 |
| Check volume                       | 🟢     | --check-volumes                               |
| Check networks                     | 🟢     | --check-networks-from-service                 |
| Check Publics Apis with Swagger    | 🟠     | --check-swagger-publics-apis                  |
| Check Swagger [GET]/Apis with Auth | 🟠     | --check-swagger-apis and --swagger-login-curl |
| Check dependencies                 | 🟠     | pending                                       |
| Add Smoke criterial                | 🟠     | pending                                       |

##### 🟢 - Inputs not required

##### 🟠 - Input required

#### Example how to use the smoke-test structure inside of one pipeline:

It is recommended to use a first test to validate the conditions of the cluster as shown in the example with the step "checkCluster" This will check that the cluster is in proper conditions

![toolss_500px](docs/examplePipeline.png)

The rest of the test cases can be applied right after the deployment of the service. This will help verify that the system is in proper condition before executing other types of tests.

## Smoke Master configuration options:

This section mentions the options related to general configuration services. You can use these commands to activate the test context or give you access to the services in your kubernetes cluster using SSH.
It is important to activate the rest of the test.

| Console command | Environment Variable | Environment Variable                                             |
| :-------------- | :------------------- | :--------------------------------------------------------------- |
| --context       | SMKTEST_CONTEXT      | Context of the test for example kubernetes, docker               |
| --environment   | SMKTEST_ENVIRONMENT  | Environment when the test is running example: localhost, develop |
| --project-name  | SMKTEST_PROJECT_NAME | Name of the project when the test go to running                  |
| --namespace     | SMKTEST_NAMPESPACE   | Namespace of the kubernetes node                                 |

## Table of Commands Smoke Master:

These are the parameters to enable the different types of smoke tests

| Console command               | Environment Variable                 | Context    | Environment Variable                                                        |
| :---------------------------- | :----------------------------------- | :--------- | :-------------------------------------------------------------------------- | --- |
| --check-endpoints             | SMKTEST_CHECK_INGRESS                | Kubernetes | Verify that the income is available and without errors                      |
| --check-pods-running          | SMKTEST_CHECK_IF_ALL_PODS_ARE_ACTIVE | Kubernetes | Check if all pods are active                                                |
| --check-cluster               | SMKTEST_CHECK_CONDITIONS             | Kubernetes | Check cluster condition (MemoryPressure, PIDPressure)                       |
| --check-pods-logs             | SMKTEST_CHECK_PODS_LOGS              | Kubernetes | Check if exist logs error inside of Pods                                    |
| --assert-curl                 | SMKTEST_ASSERT_CURL                  | all        | Check respose using Curl petitions                                          | `   |
| --check-ingress               | SMKTEST_CHECK_INGRESS                | Kubernetes | Check ingress and load balancer                                             |
| --check-volumes               | SMKTEST_CHECK_VOLUMES                | Kubernetes | Check that the available space is less than 80% percent                     |
| --check-swagger-publics-apis  | SMKTEST_CHECK_SWAGGER_PUBLICS_APIS   | all        | Check if exist 500 status response code in swagger apis                     |
| --check-swagger-apis          | SMKTEST_CHECK_SWAGGER_APIS           | all        | Check if exist 500 status response code in swagger apis with authentication |
| --swagger-login-curl          | SMKTEST_SWAGGER_LOGIN_CURL           | all        | Add the configuration parameters                                            |
| --check-networks-from-service | SMKTEST_CHECK_NETWORKS_FROM_SERVICES | kubernetes | Check network connection using other service how bridge                     |

## Connect test remote kubernetes cluster.

To connect the test to a remote cluster you must perform the following steps.

#### 1. Copy the cluster credentials in this format

Name of the variable of environment: KUBERNETES_TOKEN

apiVersion: v1
kind: Config
clusters:

- name: "serverName"
  cluster:
  server: "https://server-example"
  certificate-authority-data: "VGhlIEFkdmFuY2VkIEVuY3J5cHRpb24gU3RhbmRhcmQgKEFFUyksIGFsc28ga25vd24gYnkgaXRzIG9yaWdpbmFsIG5hbWUgUmlqbmRhZWwgKER1dGNoIHByb251bmNpYXRpb246IFvLiHLJm2luZGHLkGxdKSxbM10gaXMgYSBzcGVjaWZpY2F0aW9uIGZvciB0aGUgZW5jcnlwdGlvbiBvZiBlbGVjdHJvbmljIGRhdGEgZXN0YWJsaXNoZWQgYnkgdGhlIFUuUy4gTmF0aW9uYWwgSW5zdGl0dXRlIG9mIFN0YW5kYXJkcyBhb
- name: "serverName"
  cluster:
  server: "ServerExample"
  certificate-authority-data: "VGhlIEFkdmFuY2VkIEVuY3J5cHRpb24gU3RhbmRhcmQgKEFFUyksIGFsc28ga25vd24gYnkgaXRzIG9yaWdpbmFsIG5hbWUgUmlqbmRhZWwgKER1dGNoIHByb251bmNpYXRpb246IFvLiHLJm2luZGHLkGxdKSxbM10gaXMgYSBzcGVjaWZpY2F0aW9uIGZvciB0aGUgZW5jcnlwdGlvbiBvZiBlbGVjdHJvbmljIGRhdGEgZXN0YWJsaXNoZWQgYnkgdGhlIFUuUy4gTmF0aW9uYWwgSW5zdGl0dXRlIG9mIFN0YW5kYXJkcyBhb
  users: - name: "EXAMPLE"
  user:
  token: "TOKEN CLUSTER EXAMPLE"

contexts: - name: "USER NAME EXAMPLE"
context:
user: "USER_NAME"
cluster: CLUSTER_NAME

- name: "server example name"
  context:
  user: "name"
  cluster: "server example name"
  current-context: CONTEXTNAME

#### 2. Encode the data with Base of 64bits.

    Example of the Result

    DQogICAgYXBpVmVyc2lvbjogdjENCiAgICBraW5kOiBDb25maWcNCiAgICBjbHVzdGVyczoNCiAgICAtIG5hbWU6ICJzZXJ2ZXJOYW1lIg0KICAgIGNsdXN0ZXI6DQogICAgICAgIHNlcnZlcjogImh0dHBzOi8vc2VydmVyLWV4YW1wbGUiDQogICAgICAgIGNlcnRpZmljYXRlLWF1dGhvcml0eS1kYXRhOiAiVkdobElFRmtkbUZ1WTJWa0lFVnVZM0o1Y0hScGIyNGdVM1JoYm1SaGNtUWdLRUZGVXlrc0lHRnNjMjhnYTI1dmQyNGdZbmtnYVhSeklHOXlhV2RwYm1Gc0lHNWhiV1VnVW1scWJtUmhaV3dnS0VSMWRHTm9JSEJ5YjI1MWJtTnBZWFJwYjI0NklGdkxpSExKbTJsdVpHSExrR3hkS1N4Yk0xMGdhWE1nWVNCemNHVmphV1pwWTJGMGFXOXVJR1p2Y2lCMGFHVWdaVzVqY25sd2RHbHZiaUJ2WmlCbGJHVmpkSEp2Ym1saklHUmhkR0VnWlhOMFlXSnNhWE5vWldRZ1lua2dkR2hsSUZVdVV5NGdUbUYwYVc5dVlXd2dTVzV6ZEdsMGRYUmxJRzltSUZOMFlXNWtZWEprY3lCaGJtUWdWR1ZqYUc1dmJHOW5lU0FvVGtsVFZDa2dhVzRnTWpBd01TNWJORjBOQ2cwS1FVVlRJR2x6SUdFZ2MzVmljMlYwSUc5bUlIUm9aU0JTYVdwdVpHRmxiQ0JpYkc5amF5QmphWEJvWlhKYk0xMGdaR1YyWld4dmNHVmtJR0o1SUhSM2J5QkNaV3huYVdGdUlHTnllWEIwYjJkeVlYQm9aWEp6TENCV2FXNWpaVzUwSUZKcGFtMWxiaUJoYm1RZ1NtOWhiaUJFWVdWdFpXNHNJSGRvYnlCemRXSnRhWFIwWldRZ1lTQndjbTl3YjNOaGJGczFYU0IwYnlCT1NWTlVJR1IxY21sdVp5QjBhR1VnUVVWVElITmxiR1ZqZEdsdmJpQndjbTlqWlhOekxsczJYU0JTYVdwdVpHRmxiQ0JwY3lCaElHWmhiV2xzZVNCdlppQmphWEJvWlhKeklIZHBkR2dnWkdsbVptVnlaVzUwSUd0bGVTQmhibVFnWW14dlkyc2djMmw2WlhNdUlFWnZjaUJCUlZNc0lFNUpVMVFnYzJWc1pXTjBaV1FnZEdoeVpXVWdiV1Z0WW1WeWN5

3. Create one Environment variable with the name KUBERNETES_TOKEN and the last step results

# Available smoke test types

## Check Ingress.

- Automatic Test: 🦾

This test validates that the ingress exposed in the cluster are active. The test consists of making a CURL request and verifying that they are operatively
![toolss_500px](docs/ingress.png)

#### Command Kubectl:

    kubectl get ingress --namespace=NAME_SPACE -o json

#### Command smoke-master:

    --check-ingress

#### Example:

    create-smktest --namespace=NAME_SPACE --check-ingress

#### Gitlab Pipeline example:

#### Example how connect one remote cluster

    checkIngress:
    image:
        name: registry.gitlab.com/phdactivities/smoke-master:master
    stage: kubernetes
    variables:
        SMKTEST_PROJECT_NAME: 'SmokeMaster'
        SMKTEST_ENVIRONMENT: 'master'
        SMKTEST_CONTEXT: 'kubernetes'
        SMKTEST_NAMESPACE: 'nodespace'
        SMKTEST_MODE_AUTO: 'true'
    script:
        # Create cluster remote configuration file.
        - echo $KUBERNETES_TOKEN | base64 -d > /etc/deploy/config
        - create-smktest --check-ingress=true
    only:
        - master

## Check if all pods are Active:

- Automatic Test: 🦾

![toolss_500px](docs/pods.png)
This test verifies that all pods are operational.

### Descriptions:

Verify if all Pods are running and are active

### Gitlab pipeline example:

    podsActive:
    image:
        name: registry.gitlab.com/phdactivities/smoke-master:master
    stage: kubernetes
    variables:
        SMKTEST_PROJECT_NAME: 'SmokeMaster'
        SMKTEST_ENVIRONMENT: 'master'
        SMKTEST_CONTEXT: 'kubernetes'
        SMKTEST_NAMESPACE: 'nodespace'
        SMKTEST_MODE_AUTO: 'true'
    script:
        # Create cluster remote configuration file.
        - echo $KUBERNETES_TOKEN | base64 -d > /etc/deploy/config
        - create-smktest --check-pods-running=true
    only:
        - master

## Check Conditions.

    * Automatic Test: 🦾

This command checks that those that do not exist alert in the cluster. These alerts can cause instability in all the nodes involved.
![toolss_500px](docs/nodes.png)

#### Command Kubectl:

    kubectl describe nodes


      Type             Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
    ----             ------  -----------------                 ------------------                ------                       -------
    MemoryPressure   False   Wed, 16 Jun 2021 13:48:07 +0200   Thu, 26 Sep 2019 12:13:47 +0200   KubeletHasSufficientMemory   kubelet has sufficient memory available
    DiskPressure     False   Wed, 16 Jun 2021 13:48:07 +0200   Mon, 01 Mar 2021 18:01:45 +0100   KubeletHasNoDiskPressure     kubelet has no disk pressure
    PIDPressure      False   Wed, 16 Jun 2021 13:48:07 +0200   Thu, 26 Sep 2019 12:13:47 +0200   KubeletHasSufficientPID      kubelet has sufficient PID available
    Ready            True    Wed, 16 Jun 2021 13:48:07 +0200   Tue, 08 Jun 2021 14:12:12 +0200   KubeletReady                 kubelet is posting ready status

#### Command smoke-master:

    --check-cluster

#### Example:

    create-smktest --check-cluster

#### Gitlab Pipeline example:

    conditionsCluster:
    image:
        name: registry.gitlab.com/phdactivities/smoke-master:master
    stage: kubernetes
    variables:
        SMKTEST_PROJECT_NAME: 'SmokeMaster'
        SMKTEST_ENVIRONMENT: 'master'
        SMKTEST_CONTEXT: 'kubernetes'
        SMKTEST_NAMESPACE: 'nodespace'
        SMKTEST_MODE_AUTO: 'true'
    script:
        # Create cluster remote configuration file.
        - echo $KUBERNETES_TOKEN | base64 -d > /etc/deploy/config
        - create-smktest --check-cluster=true
    only:
        - master

## Check Logs Inside of the Pods.

#### Command Kubectl:

    kubectl logs ${name} --namespace=${namespace} --since=2m

#### Example:

    create-smktest --project-name=test --environment=develop --context=kubernetes --namespace=smokeMaster --mode-auto=true --check-pods-logs=true

#### Gitlab Pipeline example:

    logsPods:
    image:
        name: registry.gitlab.com/phdactivities/smoke-master:master
    stage: kubernetes
    variables:
        SMKTEST_PROJECT_NAME: 'SmokeMaster'
        SMKTEST_ENVIRONMENT: 'master'
        SMKTEST_CONTEXT: 'kubernetes'
        SMKTEST_NAMESPACE: 'edutelling-develop'
        SMKTEST_MODE_AUTO: 'true'
    script:
        # Create cluster remote configuration file.
        - echo $KUBERNETES_TOKEN | base64 -d > /etc/deploy/config
        - create-smktest --check-pods-logs=true
    only:
        - master

## Assert with CURL petitions.

- Input required: 💪

This test is based on CURL requests. They can be used to check if an api is available or a website. Example. It can be used to verify that the login page is enabled

#### Command smoke-master:

    --assert-curl="www.google.com"

#### Example:

    create-smktest --check-cluster=true

#### Gitlab pipeline

    checkLogin:
    <<: *smoke-test-curl
    variables:
        SMKTEST_ASSERT_CURL: 'curl -X POST "https://edutelling-api-develop.openshift.techgap.it/api/v1/auth/authentication" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"email\": \"formazione@edutelling.it\", \"password\": \"Passw0rd\", \"stayLogged\": false }"'
    script:
        - create-smktest --context=remote-server

## Check Volumes.

- Automatic Test: 🦾

This test verifies that the volume has free space
![toolss_500px](docs/volume.png)

#### Command smoke-master:

    --check-volumes=true

#### Example:

    create-smktest --check-volumes=true

#### Gitlab pipeline

    volumeSpace:
    <<: *smoke-test-kubernetes
    script:
        - create-smktest --check-volumes=true
    only:
        - master

## Check publics apis using SWAGGER

This test automatically obtains the public apis that do not require parameters from the Swagger documentation. If any api returns a status of number 500 the test fails. It is designed to obtain instabilities in apis automatically.
![toolss_500px](docs/swaggerGetPublic.png)

#### Command smoke-master:

    --check-swagger-public-apis="https://petstore.swagger.io/v2/swagger.json"

#### Example:

    create-smktest --check-swagger-public-apis="https://petstore.swagger.io/v2/swagger.json"

#### Gitlab pipeline

    pubAPetStore:
    <<: *smoke-test-kubernetes
    stage: swagger
    script:
        - create-smktest --check-swagger-public-apis="https://petstore.swagger.io/v2/swagger.json"
    only:
        - master

## Check publics apis using SWAGGER with Authentication

This test obtains the list of apis [GET] that do not require parameters and makes a request to each one of the APIs using the authentication intended by the user in the form of CURL.

#### Command smoke-master:

    --check-swagger-apis=https://petstore.swagger.io/v2/swagger.json
    --swagger-login-curl=curl LOGIN WITH LOGIN ACCESS

#### Example:

    create-smktest --check-swagger-public-apis="https://petstore.swagger.io/v2/swagger.json" --swagger-login-curl=curl LOGIN WITH LOGIN ACCESS

## Check notwork from services:

With this test, a PING_TCP request can be made through a service within the cluster. It is necessary to do it this way in order to access the internal networks of the cluster

![toolss_500px](docs/checkNetworksFromService.png)

#### Command smoke-master:

    --check-networks-from-service=SERVICE_NAME

#### Gitlab pipeline

    networks:
    <<: *smoke-test-kubernetes
    stage: swagger
    script:
        - create-smktest --check-networks-from-service=SEVICE_NAME
    only:
        - master

#### Example:

    create-smktest --check-networks-from-service=SERVICE_NAME

## Build Image steps

    1. Login with:
        docker login --username $DOCKER_USER -p $DOCKER_TOKEN
    2. Build base imagen:
        docker build -t smktesting/smoke-master:latest -f Dockerfile .
    3. docker push smktesting/smoke-master:latest

## Build Image steps

    1. Login with:
        docker login --username $DOCKER_USER -p $DOCKER_TOKEN
    2. Build base imagen:
        docker build -t smktesting/smoke-master:latest -f Dockerfile .

    3. docker push smktesting/smoke-master:latest

---
_Source: https://npm.io/package/create-smktest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
