Skip to content

Commit

Permalink
Merge pull request #37 from nimblehq/release/1.0.0
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
gutakk authored Mar 8, 2021
2 parents 402ef77 + 917e124 commit 7ce959b
Show file tree
Hide file tree
Showing 55 changed files with 2,367 additions and 3 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test

on: push

env:
BRANCH_NAME: ${GITHUB_REF#refs/heads/}

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- name: Install cookiecutter
run: sudo apt-get install cookiecutter

- name: Setup Go environment
uses: actions/[email protected]
with:
go-version: 1.16.x

- name: Linters
uses: golangci/golangci-lint-action@v2
with:
version: v1.29

- name: Test
env:
GOPATH: /home/runner/go
run: BRANCH=${{env.BRANCH_NAME}} make test
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2020 Nimble.
Copyright (c) 2014 and onwards Nimble.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: test

test:
BRANCH=$(BRANCH) go test -v -p 1 -count=1 ./...
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,46 @@

Our templates offer a rich boilerplate to jump start Go Gin-based application development.

Check this [wiki](https://github.com/nimblehq/gin-templates/wiki/Directories) for more information about the template structure.

## Get Started

### Prerequisite

- [Python interpreter](https://docs.python.org/3/using/index.html)
- Cookiecutter
- Mac: `brew install cookiecutter`
- Debian/Ubuntu: `sudo apt-get install cookiecutter`
- Go version >= 1.16

## Usage

Clone the repository
- Download **latest** version of gin-templates.
```
go get github.com/nimblehq/gin-templates
```

- Build the binary file.
```
go build -o $GOPATH/bin/nimble-gin github.com/nimblehq/gin-templates
```

- Create the project using gin-templates. Note that the **main** branch is being used by default. Refer to [this wiki page](https://github.com/nimblehq/gin-templates/wiki/Commands) for instructions on how to use a different branch.
```
nimble-gin create
```

- Follow the instructions in the terminal.

- Your new application is created 🎉 .

## Test

- Execute all unit tests. Note that the **main** branch is being used by default. Refer to [this wiki page](https://github.com/nimblehq/gin-templates/wiki/Commands) for instructions on how to use a different branch.

`git clone [email protected]:nimblehq/git-template.git`
```sh
make test
```

## License

Expand Down
29 changes: 29 additions & 0 deletions cmd/cmd_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd_test

import (
"os"
"testing"

"github.com/nimblehq/gin-templates/tests"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var TemplateGeneratedPath string

func TestTemplate(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Template Suite")
}

var _ = BeforeSuite(func() {
tests.DownloadGinTemplate()
tests.BuildGinTemplate()
tests.RemoveCookiecuttersCache()
TemplateGeneratedPath = tests.CreateProjectFromGinTemplate()
})

var _ = AfterSuite(func() {
os.RemoveAll(TemplateGeneratedPath + "/test-gin-templates")
})
51 changes: 51 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright (c) 2014 and onwards Nimble.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"log"
"os"
"os/exec"

"github.com/spf13/cobra"
)

// createCmd generates the project using cookiecutter
var (
branchFlag string

createCmd = &cobra.Command{
Use: "create",
Short: "Create the gin project with your own app name.",
Run: func(cmd *cobra.Command, args []string) {
shCmd := exec.Command("cookiecutter", "https://github.com/nimblehq/gin-templates.git", "--checkout", branchFlag)
shCmd.Stdout = os.Stdout
shCmd.Stdin = os.Stdin

err := shCmd.Run()
if err != nil {
log.Fatal("Gin project created unsuccessfully: ", err)
} else {
log.Print("Gin project created successfully.")
}
},
}
)

func init() {
createCmd.PersistentFlags().StringVarP(&branchFlag, "branch", "b", "main", "template branch")
rootCmd.AddCommand(createCmd)
}
211 changes: 211 additions & 0 deletions cmd/create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
package cmd_test

import (
"os"

"github.com/nimblehq/gin-templates/tests"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = BeforeEach(func() {
tests.ChangeDirectory(TemplateGeneratedPath + "/test-gin-templates")
})

var _ = Describe("Create template", func() {
Context("given the project directory", func() {
It("contains project name", func() {
dir, err := os.Getwd()
if err != nil {
Fail("Failed to get current directory: " + err.Error())
}

expectedContent := "gin-templates/cmd/test-gin-templates"

Expect(dir).To(ContainSubstring(expectedContent))
})
})

Context("given .env.example", func() {
It("contains project name at DATABASE_URL", func() {
content := tests.ReadFile(".env.example")

expectedContent := "DATABASE_URL=postgres://postgres:[email protected]:5432/test-gin-templates_development?sslmode=disable"

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given .env.test", func() {
It("contains project name at DATABASE_URL", func() {
content := tests.ReadFile(".env.test")

expectedContent := "DATABASE_URL=postgres://postgres:[email protected]:5433/test-gin-templates_test?sslmode=disable"

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given docker-compose.dev.yml", func() {
It("contains project name at container_name", func() {
content := tests.ReadFile("docker-compose.dev.yml")

expectedContent := "container_name: test-gin-templates_db"

Expect(content).To(ContainSubstring(expectedContent))
})

It("contains project name at postgres db env", func() {
content := tests.ReadFile("docker-compose.dev.yml")

expectedContent := "- POSTGRES_DB=test-gin-templates_development"

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given docker-compose.test.yml", func() {
It("contains project name at container_name", func() {
content := tests.ReadFile("docker-compose.test.yml")

expectedContent := "container_name: test-gin-templates_db_test"

Expect(content).To(ContainSubstring(expectedContent))
})

It("contains project name at postgres db env", func() {
content := tests.ReadFile("docker-compose.test.yml")

expectedContent := "- POSTGRES_DB=test-gin-templates_test"

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given go.mod", func() {
It("contains project name at module name", func() {
content := tests.ReadFile("go.mod")

expectedContent := "module github.com/nimblehq/test-gin-templates"

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given bootstrap/database.go", func() {
It("contains project name at helpers import", func() {
content := tests.ReadFile("bootstrap/database.go")

expectedContent := `"github.com/nimblehq/test-gin-templates/helpers"`

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given bootstrap/router.go", func() {
It("contains project name at api v1 routers import", func() {
content := tests.ReadFile("bootstrap/router.go")

expectedContent := `apiv1router "github.com/nimblehq/test-gin-templates/lib/api/v1/routers"`

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given cmd/api/main.go", func() {
It("contains project name at bootstrap import", func() {
content := tests.ReadFile("cmd/api/main.go")

expectedContent := `"github.com/nimblehq/test-gin-templates/bootstrap"`

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given config/app.toml", func() {
It("contains project name at app_name", func() {
content := tests.ReadFile("config/app.toml")

expectedContent := `app_name = "test-gin-templates"`

Expect(content).To(ContainSubstring(expectedContent))
})

It("contains project name at debug db name", func() {
content := tests.ReadFile("config/app.toml")

expectedContent := `db_name = "test-gin-templates_development"`

Expect(content).To(ContainSubstring(expectedContent))
})

It("contains project name at test db name", func() {
content := tests.ReadFile("config/app.toml")

expectedContent := `db_name = "test-gin-templates_test"`

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given helpers/config_test.go", func() {
It("contains project name at helpers import", func() {
content := tests.ReadFile("helpers/config_test.go")

expectedContent := `"github.com/nimblehq/test-gin-templates/helpers"`

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given helpers/helpers_suite_test.go", func() {
It("contains project name at test import", func() {
content := tests.ReadFile("helpers/helpers_suite_test.go")

expectedContent := `"github.com/nimblehq/test-gin-templates/test"`

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given lib/api/v1/controllers/controllers_suite_test.go", func() {
It("contains project name at test import", func() {
content := tests.ReadFile("lib/api/v1/controllers/controllers_suite_test.go")

expectedContent := `"github.com/nimblehq/test-gin-templates/test"`

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given lib/api/v1/controllers/health_test.go", func() {
It("contains project name at test import", func() {
content := tests.ReadFile("lib/api/v1/controllers/health_test.go")

expectedContent := `"github.com/nimblehq/test-gin-templates/test"`

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given lib/api/v1/routers/router.go", func() {
It("contains project name at api v1 controllers import", func() {
content := tests.ReadFile("lib/api/v1/routers/router.go")

expectedContent := `"github.com/nimblehq/test-gin-templates/lib/api/v1/controllers"`

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given test/test.go", func() {
It("contains project name at bootstrap import", func() {
content := tests.ReadFile("test/test.go")

expectedContent := `"github.com/nimblehq/test-gin-templates/bootstrap"`

Expect(content).To(ContainSubstring(expectedContent))
})
})
})
Loading

0 comments on commit 7ce959b

Please sign in to comment.