Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker coverage documentation #433

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ div[class^="sidebar_"] .button svg {
@apply font-bold text-[color:var(--ifm-color-primary)];
}

th, #lang {
text-align: center;
}

.docs-wrapper aside {
@apply border-0;
}
Expand Down
12 changes: 0 additions & 12 deletions versioned_docs/version-2.0.0/server/sdk-installation/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ keyword:
- Go Test
---

import WhatAreKeployFeatures from './index.md'

<WhatAreKeployFeatures/>

## Usage

For keploy test coverage the binary must built with `-cover` flag:

```go
go build -cover
```

To get the coverage data for unit tests :

```go
Expand Down
86 changes: 77 additions & 9 deletions versioned_docs/version-2.0.0/server/sdk-installation/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: index
title: Pre-requites 🛠️
title: Test Coverage Generation
tags:
- coverage
keyword:
Expand All @@ -24,6 +24,8 @@ To get the coverage report, first make sure all the requirements are met and the
keploy test -c "your_application_command"
```

In case of **docker** command, you would need to set `--skipCoverage` flag to false as by default coverage is disabled. Also language must be explicitly passed through `--language` flag.

After successful execution of this command, A coverage report would be generated inside the test-run folder of keploy/reports.

```sh
Expand All @@ -39,20 +41,86 @@ keploy
└── test-2.yaml
```

**Note**: In case of java application, before running test subcommand, you need to clean the project by removing any previously generated file, and run install command.

:::note
In case of java application, before running test subcommand, you need to clean the target folder by removing any previously generated file, and then running install command. Else you may get [class mismatch error](https://www.eclemma.org/jacoco/trunk/doc/classids.html) or total coverage percentage would come out to be 0.
```bash
mvn clean install -Dmaven.test.skip=true
```
:::


## 🛠️ Language Specific Requirements

| Programming Language | Prerequisites |
| :------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| go | 1. The application should have a graceful shutdown to stop the API server on `SIGTERM` or `SIGINT` signals. Refer [appendix](#graceful-shutdown) for basic implementation of graceful shutdown function. <br/> 2. The go binary should be built with `-cover` flag. |
| python | [Python 3 and above](https://www.python.org/downloads/) <br/> [coverage.py](https://coverage.readthedocs.io/en/7.4.1/install.html) |
| javascript | [nyc](https://www.npmjs.com/package/nyc) |
| java | [Jacoco 0.8.8](https://mvnrepository.com/artifact/org.jacoco/jacoco-maven-plugin/0.8.8) |
<table>
<tr>
<th rowspan="2">
Programming Language
</th>
<th colspan="2" width="80%">
Prerequisites
</th>
</tr>
<tr>
<th>Native</th>
<th>Docker</th>
</tr>
<tr>
<td id="lang">
go
</td>
<td colspan="2">
1. The application should have a graceful shutdown to stop the API server on `SIGTERM` or `SIGINT` signals. Refer [appendix](#graceful-shutdown) for basic implementation of graceful shutdown function.
2. The go binary should be built with `-cover` flag.
</td>
</tr>
<tr>
<td id="lang">
python
</td>
<td>
[coverage.py v7.6.0 and above](https://coverage.readthedocs.io/en/7.6.0/install.html)
</td>
<td>
update your CMD instruction to:<br/>
`CMD ["sh", "-c", "python3 -m coverage run $APPEND --data-file=.coverage.keploy app.py"]`,<br/>
where app.py will be the program to run.
</td>
</tr>
<tr>
<td id="lang">
javascript
</td>
<td>
[nyc](https://www.npmjs.com/package/nyc)
</td>
<td>
1. Add a new script to package.json: <br/>
`"keploy-coverage": "nyc --clean=$CLEAN npm run start",`
2. Change the CMD instruction to: <br/>
`CMD [ "npm", "run", "keploy-coverage" ]`
</td>
</tr>
<tr>
<td id="lang">
java
</td>
<td>
[Jacoco](https://mvnrepository.com/artifact/org.jacoco/jacoco-maven-plugin/0.8.8)
</td>
<td>
Update the CMD instruction to:<br/>
`CMD ["sh", "-c", "java $JACOCOAGENT -jar <your_application_jar_path>"]`
</td>
</tr>
</table>

:::note
If container fails to stop after keploy test-set run, then include the below instructions in your dockerfile:
```sh
RUN apt-get install -y dumb-init
ENTRYPOINT [ "dumb-init", "--" ]
```
:::

## Graceful Shutdown

Expand Down
6 changes: 0 additions & 6 deletions versioned_docs/version-2.0.0/server/sdk-installation/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ keyword:
- Junit
---

import WhatAreKeployFeatures from './index.md'

<WhatAreKeployFeatures/>

## Usage

### Update `pom.xml` file

You will need to add the following plugins in `pom.xml` file of your application. :-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ keywords:
- Typescript
---

import WhatAreKeployFeatures from './index.md'

<WhatAreKeployFeatures/>

## Usage

### Update package file

Update the `package.json` file that runs the application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ keyword:
- Pytest
---

import WhatAreKeployFeatures from './index.md'

<WhatAreKeployFeatures/>

## Usage

To get the coverage data for your unit tests:

```sh
Expand Down
4 changes: 4 additions & 0 deletions versioned_sidebars/version-2.0.0-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"label": "Test Coverage Generation",
"collapsible": true,
"collapsed": true,
"link": {
"type": "doc",
"id": "server/sdk-installation/index"
},
"items": [
"server/sdk-installation/go",
"server/sdk-installation/java",
Expand Down