-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from bhavyagupta3006/feat/mongo-crud-operations
feat: mongo crud operations added
- Loading branch information
Showing
4 changed files
with
148 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
MAKEFLAGS += --silent | ||
|
||
all: clean format test build | ||
|
||
## help: Prints a list of available build targets. | ||
help: | ||
echo "Usage: make <OPTIONS> ... <TARGETS>" | ||
echo "" | ||
echo "Available targets are:" | ||
echo '' | ||
sed -n 's/^##//p' ${PWD}/Makefile | column -t -s ':' | sed -e 's/^/ /' | ||
echo | ||
echo "Targets run by default are: `sed -n 's/^all: //p' ./Makefile | sed -e 's/ /, /g' | sed -e 's/\(.*\), /\1, and /'`" | ||
|
||
## clean: Removes any previously created build artifacts. | ||
clean: | ||
rm -f ./k6 | ||
|
||
## build: Builds a custom 'k6' with the local extension. | ||
build: | ||
go install go.k6.io/xk6/cmd/xk6@latest | ||
xk6 build --with $(shell go list -m)=. | ||
|
||
## format: Applies Go formatting to code. | ||
format: | ||
go fmt ./... | ||
|
||
## test: Executes any unit tests. | ||
test: | ||
go test -cover -race ./... | ||
|
||
.PHONY: build clean format help test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,55 @@ K6 extension to perform tests on mongo. | |
## Currently Supported Commands | ||
|
||
- Supports inserting a document. | ||
- Support findOne (Fetch by primary key) | ||
- Support checking query performance | ||
- Supports inserting document batch. | ||
- Supports find a document based on filter. | ||
- Supports find all documents of a collection. | ||
- Supports delete first document based on filter. | ||
- Supports deleting all documents for a specific filter. | ||
- Supports dropping a collection. | ||
|
||
# xk6-mongo | ||
A k6 extension for interacting with mongoDb while testing. | ||
|
||
## Build | ||
|
||
To build a custom `k6` binary with this extension, first ensure you have the prerequisites: | ||
|
||
- [Go toolchain](https://go101.org/article/go-toolchain.html) | ||
- Git | ||
|
||
1. Download [xk6](https://github.com/grafana/xk6): | ||
|
||
```bash | ||
go install go.k6.io/xk6/cmd/xk6@latest | ||
``` | ||
|
||
2. [Build the k6 binary](https://github.com/grafana/xk6#command-usage): | ||
|
||
```bash | ||
xk6 build --with github.com/GhMartingit/xk6-mongo | ||
``` | ||
|
||
This will create a k6 binary that includes the xk6-mongo extension in your local folder. This k6 binary can now run a k6 test. | ||
|
||
### Development | ||
To make development a little smoother, use the `Makefile` in the root folder. The default target will format your code, run tests, and create a `k6` binary with your local code rather than from GitHub. | ||
|
||
```shell | ||
git clone [email protected]/GhMartingit/xk6-mongo.git | ||
cd xk6-mongo | ||
make build | ||
``` | ||
|
||
Using the `k6` binary with `xk6-mongo`, run the k6 test as usual: | ||
|
||
```bash | ||
./k6 run k8s-test-script.js | ||
``` | ||
|
||
## Examples: | ||
|
||
### Document Insertion Test | ||
```js | ||
import xk6_mongo from 'k6/x/mongo'; | ||
|
@@ -28,4 +73,5 @@ export default ()=> { | |
client.insert("testdb", "testcollection", doc); | ||
} | ||
``` | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters