Skip to content

Commit

Permalink
chore: reorganize files and directories (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonitienda authored Apr 30, 2024
1 parent 76e14fa commit a5164bb
Show file tree
Hide file tree
Showing 51 changed files with 152 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Another option is to create one backend for each language and endpoint, creating
Although this is a lab project, in the real world we would choose one technology and language for each service so we will follow this approach.

We will name each service with the naming convention `backend-<language>-<technology>`.
For example: `backend-golang-rest`, `backend-golang-htmx`, `backend-csharp-rest`, ...
For example: `backend-rest-go`, `backend-golang-htmx`, `backend-csharp-rest`, ...
11 changes: 6 additions & 5 deletions .github/workflows/build-run-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ jobs:
matrix:
service:
[
backend-golang-rest,
backend-js-rest,
webapp-golang-htmx,
backend-rest-go,
backend-rest-js,
webapp-htmx-go,
webapp-nextjs,
e2e-cypress,
bdd-go,
]
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -53,7 +54,7 @@ jobs:
strategy:
matrix:
runner: [cypress]
frontend: [next, golang-htmx]
frontend: [nextjs, htmx-go]
backend: [go, js]
db: [inmemory, mongo]
steps:
Expand All @@ -66,7 +67,7 @@ jobs:
- name: Run E2E tests
run: just test-${{ matrix.runner }}-${{ matrix.frontend }}-${{ matrix.backend }}-${{ matrix.db }}
- name: Upload test screenshots
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4.3.3
with:
name: e2e-screenshots-${{ matrix.e2e_runner }}-${{ matrix.frontend }}-${{ matrix.backend }}-${{ matrix.db }}
path: e2e-cypress/cypress/screenshots
19 changes: 8 additions & 11 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ name: Unit Test
on: [push]

jobs:
build:
unit-test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.21.3"]

component: ["backend-rest-go", "backend-rest-js"]
steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
- name: Setup Go 1.21.3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
# You can test your matrix by printing the current Go version
- name: Display Go version
run: go version
- name: Run unit tests
run: cd backend-golang-rest && GIN_MODE=test go test -v ./...
go-version: 1.21.3
- uses: extractions/setup-just@v2
- name: Run unit tests ${{ matrix.component }}
run: cd ${{ matrix.component }} && just unit-test
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os"

"github.com/gin-gonic/gin"
"github.com/tonitienda/kadai/backend-golang-rest/pkg/authentication"
"github.com/tonitienda/kadai/backend-golang-rest/pkg/common"
"github.com/tonitienda/kadai/backend-golang-rest/pkg/db"
"github.com/tonitienda/kadai/backend-golang-rest/pkg/tasks"
"github.com/tonitienda/kadai/backend-rest-go/pkg/authentication"
"github.com/tonitienda/kadai/backend-rest-go/pkg/common"
"github.com/tonitienda/kadai/backend-rest-go/pkg/db"
"github.com/tonitienda/kadai/backend-rest-go/pkg/tasks"
)

const (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/tonitienda/kadai/backend-golang-rest/pkg/tasks"
"github.com/tonitienda/kadai/backend-rest-go/pkg/tasks"
)

func TestGetTasksAnonymousUser(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion backend-golang-rest/go.mod → backend-rest-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/tonitienda/kadai/backend-golang-rest
module github.com/tonitienda/kadai/backend-rest-go

go 1.22.1

Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions backend-rest-go/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unit-test:
GIN_MODE=test go test -v ./...
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/tonitienda/kadai/backend-golang-rest/pkg/common"
"github.com/tonitienda/kadai/backend-rest-go/pkg/common"
)

func TestAuthenticateNewUser(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"time"

"github.com/tonitienda/kadai/backend-golang-rest/pkg/tasks"
"github.com/tonitienda/kadai/backend-rest-go/pkg/tasks"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tasks
import (
"sync"

"github.com/tonitienda/kadai/backend-golang-rest/pkg/common"
"github.com/tonitienda/kadai/backend-rest-go/pkg/common"
)

type InMemoryTasksDB struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/tonitienda/kadai/backend-golang-rest/pkg/common"
"github.com/tonitienda/kadai/backend-rest-go/pkg/common"
)

const (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "backend-js-rest",
"name": "backend-rest-js",
"version": "1.0.0",
"description": "Backend for the Kadai application",
"main": "src/index.js",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion bdd-go/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/cucumber/godog"
"github.com/tonitienda/kadai/acceptance-go/pkg/api"
"github.com/tonitienda/kadai/bdd-go/pkg/api"
)

type TestsImpl interface {
Expand Down
2 changes: 1 addition & 1 deletion bdd-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/tonitienda/kadai/acceptance-go
module github.com/tonitienda/kadai/bdd-go

go 1.22.1

Expand Down
3 changes: 1 addition & 2 deletions compose.go-backend.yaml → compose.backend-go.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: '3.7'
services:
backend:
build:
context: ./backend-golang-rest
context: ./backend-rest-go
dockerfile: Dockerfile
env_file:
- .env
3 changes: 1 addition & 2 deletions compose.js-backend.yaml → compose.backend-js.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: '3.7'
services:
backend:
build:
context: ./backend-js-rest
context: ./backend-rest-js
dockerfile: Dockerfile
env_file:
- .env
1 change: 0 additions & 1 deletion compose.db-inmemory.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
backend:
environment:
Expand Down
1 change: 0 additions & 1 deletion compose.db-mongo.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
backend:
environment:
Expand Down
1 change: 0 additions & 1 deletion compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
webapp:
build:
Expand Down
1 change: 0 additions & 1 deletion compose.e2e-cypress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
e2e:
build:
Expand Down
1 change: 0 additions & 1 deletion compose.expose-ports.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
backend:
ports:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: '3.7'
services:
webapp:
build:
context: ./webapp-golang-htmx
context: ./webapp-htmx-go
dockerfile: Dockerfile
depends_on:
- backend
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
webapp:
build:
Expand Down
1 change: 0 additions & 1 deletion compose.e2e-bdd-go.yaml → compose.system-bdd-go.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
e2e:
build:
Expand Down
45 changes: 15 additions & 30 deletions generate-justfile.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,35 @@
const fs = require("node:fs");

const frontEnds = ["next", "golang-htmx"];
const frontEnds = ["nextjs", "htmx-go"];
const backends = ["go", "js"];
const e2eRunners = ["cypress"];
const apiRunners = ["bdd-go"];
const systemtests = ["bdd-go"];
const dbs = ["inmemory", "mongo"];

const makeJustE2ETestTasks = ({ frontend, backend, runner, db }) => `
test-${runner}-${frontend}-${backend}-${db}:
docker compose \\
-f compose.${frontend}-frontend.yaml \\
-f compose.${backend}-backend.yaml \\
-f compose.db-${db}.yaml \\
-f compose.e2e-${runner}.yaml \\
config
COMPOSE_PROJECT_NAME="kadai-${runner}-${frontend}-${backend}-${db}" docker compose \\
-f compose.${frontend}-frontend.yaml \\
-f compose.${backend}-backend.yaml \\
-f compose.frontend-${frontend}.yaml \\
-f compose.backend-${backend}.yaml \\
-f compose.db-${db}.yaml \\
-f compose.e2e-${runner}.yaml \\
up --build --exit-code-from e2e
`;

const makeJustApiTestTasks = ({ backend, runner, db }) => `
const makeJustSystemTestTasks = ({ backend, runner, db }) => `
test-${runner}-${backend}-${db}:
docker compose \\
-f compose.${backend}-backend.yaml \\
-f compose.db-${db}.yaml \\
-f compose.e2e-${runner}.yaml \\
config
COMPOSE_PROJECT_NAME="kadai-${runner}-${backend}-${db}" docker compose \\
-f compose.${backend}-backend.yaml \\
-f compose.backend-${backend}.yaml \\
-f compose.db-${db}.yaml \\
-f compose.e2e-${runner}.yaml \\
-f compose.system-${runner}.yaml \\
up --build --exit-code-from e2e
`;

const makeJustStartTasks = ({ frontend, backend, db }) => `
start-${frontend}-${backend}-${db}:
docker compose \\
-f compose.${frontend}-frontend.yaml \\
-f compose.${backend}-backend.yaml \\
-f compose.db-${db}.yaml \\
config
COMPOSE_PROJECT_NAME="kadai-${frontend}-${backend}-${db}" docker compose \\
-f compose.${frontend}-frontend.yaml \\
-f compose.${backend}-backend.yaml \\
Expand All @@ -72,8 +53,8 @@ const appCombinations = frontEnds.flatMap((f) =>
}))
);

const apiTestsCombinations = apiCombinations.flatMap((a) =>
apiRunners.flatMap((r) => ({
const systemTestsCombinations = apiCombinations.flatMap((a) =>
systemtests.flatMap((r) => ({
...a,
runner: r,
}))
Expand All @@ -87,6 +68,10 @@ const e2eTestsCombinations = appCombinations.flatMap((a) =>
);

const contents =
`
unit-test:
@echo "No unit tests found"
` +
appCombinations.reduce(
(contents, combination) => contents + makeJustStartTasks(combination),
""
Expand All @@ -95,8 +80,8 @@ const contents =
(contents, combination) => contents + makeJustE2ETestTasks(combination),
""
) +
apiTestsCombinations.reduce(
(contents, combination) => contents + makeJustApiTestTasks(combination),
systemTestsCombinations.reduce(
(contents, combination) => contents + makeJustSystemTestTasks(combination),
""
);

Expand Down
Loading

0 comments on commit a5164bb

Please sign in to comment.