|
| 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