Fix: broken ci and tests
All checks were successful
All checks were successful
This commit is contained in:
@@ -35,13 +35,12 @@ jobs:
|
|||||||
runs-on: imgbuilder
|
runs-on: imgbuilder
|
||||||
env:
|
env:
|
||||||
COMPOSE_ARGS: '-p go2025-backend'
|
COMPOSE_ARGS: '-p go2025-backend'
|
||||||
|
DOCKER_BUILD_ARGS: '--quiet'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Run docker compose
|
- name: Run docker compose
|
||||||
run: make docker-quiet
|
run: make docker-quiet
|
||||||
- name: Reset states
|
|
||||||
run: make reset
|
|
||||||
- name: Run go test
|
- name: Run go test
|
||||||
run: make test
|
run: make test
|
||||||
cleanup-go-test:
|
cleanup-go-test:
|
||||||
@@ -57,6 +56,8 @@ jobs:
|
|||||||
needs:
|
needs:
|
||||||
- run-go-test
|
- run-go-test
|
||||||
runs-on: imgbuilder
|
runs-on: imgbuilder
|
||||||
|
env:
|
||||||
|
COMPOSE_ARGS: '-p go2025-backend'
|
||||||
steps:
|
steps:
|
||||||
- name: Build and push image
|
- name: Build and push image
|
||||||
uses: https://gitea.konchin.com/action/docker@main
|
uses: https://gitea.konchin.com/action/docker@main
|
||||||
|
|||||||
12
Makefile
12
Makefile
@@ -1,8 +1,9 @@
|
|||||||
.PHONY: all swagger install postgres test mac reset \
|
.PHONY: all swagger install postgres test mac \
|
||||||
docker docker-quiet docker-clean
|
docker docker-quiet docker-clean
|
||||||
|
|
||||||
SWAG ?= go run github.com/swaggo/swag/cmd/swag@v1.16.4
|
SWAG ?= go run github.com/swaggo/swag/cmd/swag@v1.16.4
|
||||||
DOCKER ?= docker
|
DOCKER ?= docker
|
||||||
|
DOCKER_BUILD_ARGS +=
|
||||||
COMPOSE_ARGS += --progress plain
|
COMPOSE_ARGS += --progress plain
|
||||||
COMPOSE ?= $(DOCKER) compose $(COMPOSE_ARGS)
|
COMPOSE ?= $(DOCKER) compose $(COMPOSE_ARGS)
|
||||||
|
|
||||||
@@ -14,20 +15,19 @@ all: swagger docker-build-native docker
|
|||||||
|
|
||||||
mac: swagger docker-build-run docker
|
mac: swagger docker-build-run docker
|
||||||
|
|
||||||
reset:
|
|
||||||
$(COMPOSE) exec backend reset
|
|
||||||
|
|
||||||
swagger:
|
swagger:
|
||||||
$(SWAG) fmt
|
$(SWAG) fmt
|
||||||
$(SWAG) init -o docs -g cmds/serve.go -pdl 1
|
$(SWAG) init -o docs -g cmds/serve.go -pdl 1
|
||||||
|
|
||||||
docker-build-native: $(TARGET)
|
docker-build-native: $(TARGET)
|
||||||
$(DOCKER) build . --target native \
|
$(DOCKER) build . $(DOCKER_BUILD_ARGS) \
|
||||||
|
--target native \
|
||||||
-t go2025/backend:native \
|
-t go2025/backend:native \
|
||||||
-t go2025/backend:latest
|
-t go2025/backend:latest
|
||||||
|
|
||||||
docker-build-run:
|
docker-build-run:
|
||||||
$(DOCKER) build . --target build-run \
|
$(DOCKER) build . $(DOCKER_BUILD_ARGS) \
|
||||||
|
--target build-run \
|
||||||
-t go2025/backend:build-run \
|
-t go2025/backend:build-run \
|
||||||
-t go2025/backend:latest
|
-t go2025/backend:latest
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func Test_01_Login(t *testing.T) {
|
|||||||
t.Run("check preshared key failed", func(t *testing.T) {
|
t.Run("check preshared key failed", func(t *testing.T) {
|
||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
SetBody(`{"userId": "testuser1"}`).
|
SetBody(`{"userId": "testuser1"}`).
|
||||||
Post("http://localhost:8080/auth/gen-login-url")
|
Post("/auth/gen-login-url")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("request failed")
|
t.Fatal("request failed")
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func Test_01_Login(t *testing.T) {
|
|||||||
SetBody(`{"userId": "testuser1"}`).
|
SetBody(`{"userId": "testuser1"}`).
|
||||||
SetAuthToken("poop").
|
SetAuthToken("poop").
|
||||||
SetResult(&payload).
|
SetResult(&payload).
|
||||||
Post("http://localhost:8080/auth/gen-login-url")
|
Post("/auth/gen-login-url")
|
||||||
|
|
||||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||||
t.Fatal("failed to get login url")
|
t.Fatal("failed to get login url")
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func Test_02_PostImage(t *testing.T) {
|
|||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
SetBody(rawImage).
|
SetBody(rawImage).
|
||||||
SetResult(&image).
|
SetResult(&image).
|
||||||
Post("http://localhost:8080/api/image")
|
Post("/api/image")
|
||||||
|
|
||||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||||
t.Logf("%+v", resp)
|
t.Logf("%+v", resp)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package tests
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,8 +18,7 @@ func Test_03_PutImageAliases(t *testing.T) {
|
|||||||
}
|
}
|
||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
SetBody(payload).
|
SetBody(payload).
|
||||||
Put(fmt.Sprintf("http://localhost:8080/api/image/%d/aliases",
|
Put(fmt.Sprintf("/api/image/%d/aliases", image.Id))
|
||||||
image.Id))
|
|
||||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||||
t.Logf("%+v", resp)
|
t.Logf("%+v", resp)
|
||||||
t.Fatal("failed to put image alias")
|
t.Fatal("failed to put image alias")
|
||||||
@@ -61,6 +61,11 @@ func Test_03_PutImageAliases(t *testing.T) {
|
|||||||
for _, alias := range aliases {
|
for _, alias := range aliases {
|
||||||
if alias.Name == "testalias2" {
|
if alias.Name == "testalias2" {
|
||||||
t.Logf("%+v", resp)
|
t.Logf("%+v", resp)
|
||||||
|
resp, _ = client.R().
|
||||||
|
SetQueryParam("aliases",
|
||||||
|
strconv.FormatInt(alias.Id, 10)).
|
||||||
|
Get("/api/images")
|
||||||
|
t.Logf("%+v", resp)
|
||||||
t.Fatal("alias should be deleted")
|
t.Fatal("alias should be deleted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,22 @@ func InitDB(ctx context.Context, db *bun.DB) error {
|
|||||||
(*models.Image)(nil),
|
(*models.Image)(nil),
|
||||||
(*models.Session)(nil),
|
(*models.Session)(nil),
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
modls := []any{
|
||||||
|
(*models.AliasImage)(nil),
|
||||||
|
(*models.Alias)(nil),
|
||||||
|
(*models.Image)(nil),
|
||||||
|
(*models.Session)(nil),
|
||||||
|
}
|
||||||
|
for _, model := range modls {
|
||||||
|
_, err := db.NewCreateTable().
|
||||||
|
Model(model).
|
||||||
|
IfNotExists().
|
||||||
|
Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user