Skip to content

Commit

Permalink
docs: update README & CONTRIBUTING.md 📝
Browse files Browse the repository at this point in the history
  • Loading branch information
kareemmahlees committed Feb 17, 2024
1 parent 61d37c3 commit e2e3b25
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 112 deletions.
38 changes: 0 additions & 38 deletions .air.toml

This file was deleted.

65 changes: 43 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Thank you for being interested in contributing to MySQL Meta
Thank you for being interested in contributing to MetaX

## Local Development
## Getting Started

Start by cloning the repo:

Expand All @@ -12,32 +12,53 @@ the `--depth` flag specifies the number of commits you want to clone with the re

You will find in the [Makefile](Makefile) some useful scripts:

- watch: will start the database container and run the application in watch mode
- swag: will generate the required swagger documentation
- generate: will generate the required graphql code, e.g resolvers.
- `build`: builds the code and produce a binary.
- `run`: builds the code and runs it.
- `test`: runs the test suite, make sure to startup docker first because we use **TestContainers**.
- `swag`: will generate the required swagger documentation.
- `generate`: will generate the required graphql code, e.g resolvers.

## Testing
## Codebase overview

You can setup the testing containers by running the following:
### CLI

```shell
make setup_test
```
**MetaX** uses [cobra](https://github.com/spf13/cobra) to parse CLI arguments, commands, etc.
All **MetaX's** commands are located under the `cmd` directory.

then run the tests:
### REST API

```shell
make test
```
We use [fiber](https://gofiber.io) as our framework. All the routes are located under the `internal/rest` directory.

or, for verbose output:
### GraphQL

```shell
make testv
```
We use [gqlgen](https://gqlgen.com/) as our graphql server. All GraphQL related stuff are located under `internal/graph`.

after your are done, remember to cleanup afterwards:
Each time you make a change in the schema, make sure you run `make generate` to generate the resolvers and models.

```shell
make cleanup_test
```
### Swagger

We use [swag](https://github.com/swaggo/swag) to generate swagger documentation for the REST endpoints.

Each time you make a change in the endpoints documentation, make sure your run `make swag` to formate the comments and generate the required data.

### Other

#### /lib

Contains logic related to validation, constants, and http errors.

#### /models

Contains structs that define the shape of requests and responses.

#### /utils

Some utilities for encoding/decoding http payloads, test helpers and styled printing

## Testing

We use [TestContainers](https://testcontainers.com/) to create and terminate docker containers in the `setup`&`teardown` of our test suites.

So if you want to run the tests after making any change, make sure to startup docker first.

Please make sure that any change you make is accompanied with sufficient test cases.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build:
@go build -o bin/
run: build
@./bin/meta-x.exe
@./bin/meta-x.exe --help

# make sure to run docker first
test:
Expand Down
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@

- ### Download the binary

You can download the binary from the [releases page](https://github.com/kareemmahlees/meta-x/releases).
You can download the binary from the [releases page](https://github.com/kareemmahlees/meta-x/releases/latest).

Make sure you add the executable to your `PATH` environment variable.
Make sure you add the executable to your `PATH` environment variable.

- ### Go Install
- ### Building from source

You can use the `go install` command to install like so:
First clone the repo:

```shell
go install github.com/kareemmahlees/mysql-meta
git clone github.com/kareemmahlees/meta-x --depth=1
```

And then install the tool:

```shell
go install
```

And it will automatically be added to your `PATH`

## Running

Once you [installed](#installation) the binary, _MetaX_ comes with subocommands to each you can supply your database connection parameters as command line flags.
Expand Down Expand Up @@ -78,12 +86,14 @@ Additionally, you can playaround with the GraphQL version by jumping into the pl
- [ ] delete views
- [ ] query by views
- Config
- [ ] get mysql version
- [ ] get version

## Contributing

We strongly encourage anyone who wants to contribute to go ahead, not matter what skill level your are.
We strongly encourage anyone who wants to contribute to go ahead, no matter what skill level your are.

Contributions can be as small as suggesting a feature, reporting a bug or enhancing the docs.

For more details, please visit [CONTRIBUTING.md]()
**Want to contribute but don't know where to start?**

Checkout our [Codebase Overview](./CONTRIBUTING.md#codebase-overview) section in [CONTRIBUTING.md](./CONTRIBUTING.md), then head to our [issues](https://github.com/kareemmahlees/meta-x/issues) section and pick an issue to work on 🚀.
15 changes: 0 additions & 15 deletions lib/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var validate *validator.Validate

func init() {
validate = validator.New(validator.WithRequiredStructEnabled())
_ = validate.RegisterValidation("notEmpty", notEmtpy)
}

func ValidateStruct(data interface{}) []ErrorResponse {
Expand All @@ -36,17 +35,3 @@ func ValidateStruct(data interface{}) []ErrorResponse {

return validationErrors
}

func ValidateVar(value interface{}, tags string) error {

err := validate.Var(value, tags)

if err != nil {
return err
}
return nil
}

func notEmtpy(fl validator.FieldLevel) bool {
return fl.Field().Len() != 0
}
28 changes: 0 additions & 28 deletions lib/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,3 @@ func TestValidateStruct(t *testing.T) {
assert.Contains(t, failedTags, test.FailureTag)
}
}

func TestValidateVar(t *testing.T) {
const validationTags = "required,alpha,min=3"

err := ValidateVar("kareem", validationTags)
assert.Nil(t, err)

err = ValidateVar(123, validationTags)
assert.Error(t, err)
}

func TestNotEmpty(t *testing.T) {
testStructs := []struct {
Names []string `validate:"notEmpty"`
}{
{Names: []string{"foo", "bar", "baz"}},
{Names: []string{}},
}
for idx, test := range testStructs {
errs := ValidateStruct(test)
if idx == 0 {
assert.Zero(t, len(errs))
} else if idx == 1 {
assert.Greater(t, len(errs), 0)
assert.Equal(t, errs[0].Tag, "notEmpty")
}
}
}

0 comments on commit e2e3b25

Please sign in to comment.