Skip to content

Commit 7ce959b

Browse files
authored
Merge pull request #37 from nimblehq/release/1.0.0
Release 1.0.0
2 parents 402ef77 + 917e124 commit 7ce959b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2367
-3
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test
2+
3+
on: push
4+
5+
env:
6+
BRANCH_NAME: ${GITHUB_REF#refs/heads/}
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2.3.4
14+
15+
- name: Install cookiecutter
16+
run: sudo apt-get install cookiecutter
17+
18+
- name: Setup Go environment
19+
uses: actions/setup-go@v2.1.3
20+
with:
21+
go-version: 1.16.x
22+
23+
- name: Linters
24+
uses: golangci/golangci-lint-action@v2
25+
with:
26+
version: v1.29
27+
28+
- name: Test
29+
env:
30+
GOPATH: /home/runner/go
31+
run: BRANCH=${{env.BRANCH_NAME}} make test

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014-2020 Nimble.
1+
Copyright (c) 2014 and onwards Nimble.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.PHONY: test
2+
3+
test:
4+
BRANCH=$(BRANCH) go test -v -p 1 -count=1 ./...

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,46 @@
1010

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

13+
Check this [wiki](https://github.com/nimblehq/gin-templates/wiki/Directories) for more information about the template structure.
14+
1315
## Get Started
1416

17+
### Prerequisite
18+
19+
- [Python interpreter](https://docs.python.org/3/using/index.html)
20+
- Cookiecutter
21+
- Mac: `brew install cookiecutter`
22+
- Debian/Ubuntu: `sudo apt-get install cookiecutter`
23+
- Go version >= 1.16
24+
1525
## Usage
1626

17-
Clone the repository
27+
- Download **latest** version of gin-templates.
28+
```
29+
go get github.com/nimblehq/gin-templates
30+
```
31+
32+
- Build the binary file.
33+
```
34+
go build -o $GOPATH/bin/nimble-gin github.com/nimblehq/gin-templates
35+
```
36+
37+
- 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.
38+
```
39+
nimble-gin create
40+
```
41+
42+
- Follow the instructions in the terminal.
43+
44+
- Your new application is created 🎉 .
45+
46+
## Test
47+
48+
- 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.
1849

19-
`git clone git@github.com:nimblehq/git-template.git`
50+
```sh
51+
make test
52+
```
2053

2154
## License
2255

cmd/cmd_suite_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cmd_test
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/nimblehq/gin-templates/tests"
8+
9+
. "github.com/onsi/ginkgo"
10+
. "github.com/onsi/gomega"
11+
)
12+
13+
var TemplateGeneratedPath string
14+
15+
func TestTemplate(t *testing.T) {
16+
RegisterFailHandler(Fail)
17+
RunSpecs(t, "Template Suite")
18+
}
19+
20+
var _ = BeforeSuite(func() {
21+
tests.DownloadGinTemplate()
22+
tests.BuildGinTemplate()
23+
tests.RemoveCookiecuttersCache()
24+
TemplateGeneratedPath = tests.CreateProjectFromGinTemplate()
25+
})
26+
27+
var _ = AfterSuite(func() {
28+
os.RemoveAll(TemplateGeneratedPath + "/test-gin-templates")
29+
})

cmd/create.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright (c) 2014 and onwards Nimble.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"log"
20+
"os"
21+
"os/exec"
22+
23+
"github.com/spf13/cobra"
24+
)
25+
26+
// createCmd generates the project using cookiecutter
27+
var (
28+
branchFlag string
29+
30+
createCmd = &cobra.Command{
31+
Use: "create",
32+
Short: "Create the gin project with your own app name.",
33+
Run: func(cmd *cobra.Command, args []string) {
34+
shCmd := exec.Command("cookiecutter", "https://github.com/nimblehq/gin-templates.git", "--checkout", branchFlag)
35+
shCmd.Stdout = os.Stdout
36+
shCmd.Stdin = os.Stdin
37+
38+
err := shCmd.Run()
39+
if err != nil {
40+
log.Fatal("Gin project created unsuccessfully: ", err)
41+
} else {
42+
log.Print("Gin project created successfully.")
43+
}
44+
},
45+
}
46+
)
47+
48+
func init() {
49+
createCmd.PersistentFlags().StringVarP(&branchFlag, "branch", "b", "main", "template branch")
50+
rootCmd.AddCommand(createCmd)
51+
}

cmd/create_test.go

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
package cmd_test
2+
3+
import (
4+
"os"
5+
6+
"github.com/nimblehq/gin-templates/tests"
7+
8+
. "github.com/onsi/ginkgo"
9+
. "github.com/onsi/gomega"
10+
)
11+
12+
var _ = BeforeEach(func() {
13+
tests.ChangeDirectory(TemplateGeneratedPath + "/test-gin-templates")
14+
})
15+
16+
var _ = Describe("Create template", func() {
17+
Context("given the project directory", func() {
18+
It("contains project name", func() {
19+
dir, err := os.Getwd()
20+
if err != nil {
21+
Fail("Failed to get current directory: " + err.Error())
22+
}
23+
24+
expectedContent := "gin-templates/cmd/test-gin-templates"
25+
26+
Expect(dir).To(ContainSubstring(expectedContent))
27+
})
28+
})
29+
30+
Context("given .env.example", func() {
31+
It("contains project name at DATABASE_URL", func() {
32+
content := tests.ReadFile(".env.example")
33+
34+
expectedContent := "DATABASE_URL=postgres://postgres:postgres@0.0.0.0:5432/test-gin-templates_development?sslmode=disable"
35+
36+
Expect(content).To(ContainSubstring(expectedContent))
37+
})
38+
})
39+
40+
Context("given .env.test", func() {
41+
It("contains project name at DATABASE_URL", func() {
42+
content := tests.ReadFile(".env.test")
43+
44+
expectedContent := "DATABASE_URL=postgres://postgres:postgres@0.0.0.0:5433/test-gin-templates_test?sslmode=disable"
45+
46+
Expect(content).To(ContainSubstring(expectedContent))
47+
})
48+
})
49+
50+
Context("given docker-compose.dev.yml", func() {
51+
It("contains project name at container_name", func() {
52+
content := tests.ReadFile("docker-compose.dev.yml")
53+
54+
expectedContent := "container_name: test-gin-templates_db"
55+
56+
Expect(content).To(ContainSubstring(expectedContent))
57+
})
58+
59+
It("contains project name at postgres db env", func() {
60+
content := tests.ReadFile("docker-compose.dev.yml")
61+
62+
expectedContent := "- POSTGRES_DB=test-gin-templates_development"
63+
64+
Expect(content).To(ContainSubstring(expectedContent))
65+
})
66+
})
67+
68+
Context("given docker-compose.test.yml", func() {
69+
It("contains project name at container_name", func() {
70+
content := tests.ReadFile("docker-compose.test.yml")
71+
72+
expectedContent := "container_name: test-gin-templates_db_test"
73+
74+
Expect(content).To(ContainSubstring(expectedContent))
75+
})
76+
77+
It("contains project name at postgres db env", func() {
78+
content := tests.ReadFile("docker-compose.test.yml")
79+
80+
expectedContent := "- POSTGRES_DB=test-gin-templates_test"
81+
82+
Expect(content).To(ContainSubstring(expectedContent))
83+
})
84+
})
85+
86+
Context("given go.mod", func() {
87+
It("contains project name at module name", func() {
88+
content := tests.ReadFile("go.mod")
89+
90+
expectedContent := "module github.com/nimblehq/test-gin-templates"
91+
92+
Expect(content).To(ContainSubstring(expectedContent))
93+
})
94+
})
95+
96+
Context("given bootstrap/database.go", func() {
97+
It("contains project name at helpers import", func() {
98+
content := tests.ReadFile("bootstrap/database.go")
99+
100+
expectedContent := `"github.com/nimblehq/test-gin-templates/helpers"`
101+
102+
Expect(content).To(ContainSubstring(expectedContent))
103+
})
104+
})
105+
106+
Context("given bootstrap/router.go", func() {
107+
It("contains project name at api v1 routers import", func() {
108+
content := tests.ReadFile("bootstrap/router.go")
109+
110+
expectedContent := `apiv1router "github.com/nimblehq/test-gin-templates/lib/api/v1/routers"`
111+
112+
Expect(content).To(ContainSubstring(expectedContent))
113+
})
114+
})
115+
116+
Context("given cmd/api/main.go", func() {
117+
It("contains project name at bootstrap import", func() {
118+
content := tests.ReadFile("cmd/api/main.go")
119+
120+
expectedContent := `"github.com/nimblehq/test-gin-templates/bootstrap"`
121+
122+
Expect(content).To(ContainSubstring(expectedContent))
123+
})
124+
})
125+
126+
Context("given config/app.toml", func() {
127+
It("contains project name at app_name", func() {
128+
content := tests.ReadFile("config/app.toml")
129+
130+
expectedContent := `app_name = "test-gin-templates"`
131+
132+
Expect(content).To(ContainSubstring(expectedContent))
133+
})
134+
135+
It("contains project name at debug db name", func() {
136+
content := tests.ReadFile("config/app.toml")
137+
138+
expectedContent := `db_name = "test-gin-templates_development"`
139+
140+
Expect(content).To(ContainSubstring(expectedContent))
141+
})
142+
143+
It("contains project name at test db name", func() {
144+
content := tests.ReadFile("config/app.toml")
145+
146+
expectedContent := `db_name = "test-gin-templates_test"`
147+
148+
Expect(content).To(ContainSubstring(expectedContent))
149+
})
150+
})
151+
152+
Context("given helpers/config_test.go", func() {
153+
It("contains project name at helpers import", func() {
154+
content := tests.ReadFile("helpers/config_test.go")
155+
156+
expectedContent := `"github.com/nimblehq/test-gin-templates/helpers"`
157+
158+
Expect(content).To(ContainSubstring(expectedContent))
159+
})
160+
})
161+
162+
Context("given helpers/helpers_suite_test.go", func() {
163+
It("contains project name at test import", func() {
164+
content := tests.ReadFile("helpers/helpers_suite_test.go")
165+
166+
expectedContent := `"github.com/nimblehq/test-gin-templates/test"`
167+
168+
Expect(content).To(ContainSubstring(expectedContent))
169+
})
170+
})
171+
172+
Context("given lib/api/v1/controllers/controllers_suite_test.go", func() {
173+
It("contains project name at test import", func() {
174+
content := tests.ReadFile("lib/api/v1/controllers/controllers_suite_test.go")
175+
176+
expectedContent := `"github.com/nimblehq/test-gin-templates/test"`
177+
178+
Expect(content).To(ContainSubstring(expectedContent))
179+
})
180+
})
181+
182+
Context("given lib/api/v1/controllers/health_test.go", func() {
183+
It("contains project name at test import", func() {
184+
content := tests.ReadFile("lib/api/v1/controllers/health_test.go")
185+
186+
expectedContent := `"github.com/nimblehq/test-gin-templates/test"`
187+
188+
Expect(content).To(ContainSubstring(expectedContent))
189+
})
190+
})
191+
192+
Context("given lib/api/v1/routers/router.go", func() {
193+
It("contains project name at api v1 controllers import", func() {
194+
content := tests.ReadFile("lib/api/v1/routers/router.go")
195+
196+
expectedContent := `"github.com/nimblehq/test-gin-templates/lib/api/v1/controllers"`
197+
198+
Expect(content).To(ContainSubstring(expectedContent))
199+
})
200+
})
201+
202+
Context("given test/test.go", func() {
203+
It("contains project name at bootstrap import", func() {
204+
content := tests.ReadFile("test/test.go")
205+
206+
expectedContent := `"github.com/nimblehq/test-gin-templates/bootstrap"`
207+
208+
Expect(content).To(ContainSubstring(expectedContent))
209+
})
210+
})
211+
})

0 commit comments

Comments
 (0)