Compare commits
10 Commits
c9fe4f4bf1
...
002fdd87a7
| Author | SHA1 | Date | |
|---|---|---|---|
| 002fdd87a7 | |||
| 7c879fc6f4 | |||
| 7045ffb469 | |||
| 91645bee3b | |||
| ae2611f027 | |||
| c6268132fa | |||
| 28f014ce95 | |||
| dc638a07f1 | |||
|
|
0e8efe1043 | ||
|
|
0ed2d02dfe |
@ -1,11 +1,11 @@
|
|||||||
# Build stage
|
# Build stage
|
||||||
FROM golang:1.25-alpine AS builder
|
FROM golang@sha256:f6751d823c26342f9506c03797d2527668d095b0a15f1862cddb4d927a7a4ced AS builder # golang:1.25-alpine
|
||||||
|
|
||||||
RUN apk add --no-cache git make gcc musl-dev
|
RUN apk add --no-cache git make gcc musl-dev
|
||||||
|
|
||||||
# Install golangci-lint v2
|
# Install golangci-lint v2
|
||||||
RUN go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
|
RUN go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@5d1e709b7be35cb2025444e19de266b056b7b7ee # v2.10.1
|
||||||
RUN go install golang.org/x/tools/cmd/goimports@latest
|
RUN go install golang.org/x/tools/cmd/goimports@009367f5c17a8d4c45a961a3a509277190a9a6f0 # v0.42.0
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
@ -20,7 +20,7 @@ RUN make check
|
|||||||
RUN make build
|
RUN make build
|
||||||
|
|
||||||
# Runtime stage
|
# Runtime stage
|
||||||
FROM alpine:3.19
|
FROM alpine@sha256:6baf43584bcb78f2e5847d1de515f23499913ac9f12bdf834811a3145eb11ca1 # alpine:3.19
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates tzdata git openssh-client docker-cli
|
RUN apk add --no-cache ca-certificates tzdata git openssh-client docker-cli
|
||||||
|
|
||||||
|
|||||||
41
internal/database/testing.go
Normal file
41
internal/database/testing.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.eeqj.de/sneak/upaas/internal/config"
|
||||||
|
"git.eeqj.de/sneak/upaas/internal/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewTestDatabase creates an in-memory Database for testing.
|
||||||
|
// It runs migrations so all tables are available.
|
||||||
|
func NewTestDatabase(t *testing.T) *Database {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
|
cfg := &config.Config{
|
||||||
|
DataDir: tmpDir,
|
||||||
|
}
|
||||||
|
|
||||||
|
log := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||||
|
logWrapper := logger.NewForTest(log)
|
||||||
|
|
||||||
|
db, err := New(nil, Params{
|
||||||
|
Logger: logWrapper,
|
||||||
|
Config: cfg,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create test database: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Cleanup(func() {
|
||||||
|
if db.database != nil {
|
||||||
|
_ = db.database.Close()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return db
|
||||||
|
}
|
||||||
11
internal/logger/testing.go
Normal file
11
internal/logger/testing.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import "log/slog"
|
||||||
|
|
||||||
|
// NewForTest creates a Logger wrapping the given slog.Logger, for use in tests.
|
||||||
|
func NewForTest(log *slog.Logger) *Logger {
|
||||||
|
return &Logger{
|
||||||
|
log: log,
|
||||||
|
level: new(slog.LevelVar),
|
||||||
|
}
|
||||||
|
}
|
||||||
45
internal/service/deploy/deploy_container_test.go
Normal file
45
internal/service/deploy/deploy_container_test.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package deploy_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.eeqj.de/sneak/upaas/internal/database"
|
||||||
|
"git.eeqj.de/sneak/upaas/internal/domain"
|
||||||
|
"git.eeqj.de/sneak/upaas/internal/models"
|
||||||
|
"git.eeqj.de/sneak/upaas/internal/service/deploy"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBuildContainerOptionsUsesImageID(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDatabase(t)
|
||||||
|
|
||||||
|
app := models.NewApp(db)
|
||||||
|
app.Name = "myapp"
|
||||||
|
|
||||||
|
err := app.Save(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to save app: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||||
|
svc := deploy.NewTestService(log)
|
||||||
|
|
||||||
|
const expectedImageID = domain.ImageID("sha256:abc123def456")
|
||||||
|
|
||||||
|
opts, err := svc.BuildContainerOptionsExported(context.Background(), app, expectedImageID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("buildContainerOptions returned error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.Image != string(expectedImageID) {
|
||||||
|
t.Errorf("expected Image=%q, got %q", expectedImageID, opts.Image)
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.Name != "upaas-myapp" {
|
||||||
|
t.Errorf("expected Name=%q, got %q", "upaas-myapp", opts.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,6 +10,8 @@ import (
|
|||||||
|
|
||||||
"git.eeqj.de/sneak/upaas/internal/config"
|
"git.eeqj.de/sneak/upaas/internal/config"
|
||||||
"git.eeqj.de/sneak/upaas/internal/docker"
|
"git.eeqj.de/sneak/upaas/internal/docker"
|
||||||
|
"git.eeqj.de/sneak/upaas/internal/domain"
|
||||||
|
"git.eeqj.de/sneak/upaas/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTestService creates a Service with minimal dependencies for testing.
|
// NewTestService creates a Service with minimal dependencies for testing.
|
||||||
@ -80,3 +82,12 @@ func (svc *Service) CleanupCancelledDeploy(
|
|||||||
func (svc *Service) GetBuildDirExported(appName string) string {
|
func (svc *Service) GetBuildDirExported(appName string) string {
|
||||||
return svc.GetBuildDir(appName)
|
return svc.GetBuildDir(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildContainerOptionsExported exposes buildContainerOptions for testing.
|
||||||
|
func (svc *Service) BuildContainerOptionsExported(
|
||||||
|
ctx context.Context,
|
||||||
|
app *models.App,
|
||||||
|
imageID domain.ImageID,
|
||||||
|
) (docker.CreateContainerOptions, error) {
|
||||||
|
return svc.buildContainerOptions(ctx, app, imageID)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user