All checks were successful
Check / check (push) Successful in 4s
Bumps golangci-lint from v2.10.1 to v2.12.2 everywhere it is pinned and installs the canonical `.golangci.yml`, then fixes every finding the new linter surfaces so `make check` is green. ## Version pins - `Dockerfile` lint stage: `golangci/golangci-lint:v2.12.2` (Debian-based), tag plus digest pin - `script/bootstrap`: `GOLANGCI_LINT_VERSION=2.12.2` with updated `linux-amd64`/`linux-arm64` release-archive sha256 pins ## Config `.golangci.yml` replaced with the canonical config. Material change: the old file declared `version: "2"` but kept settings under the legacy top-level `linters-settings` key, which golangci-lint v2 ignores — so the intended thresholds (`lll` 88, `funlen` 80/50, `cyclop` 15, `dupl` 100) were not being applied. The canonical file moves them under `linters.settings` and drops `issues.exclude-use-default`. ## Lint fixes (216 findings) - `lll` (96): wrapped lines to the 88-column limit - `noctx` (46): `httptest.NewRequestWithContext` with `t.Context()` throughout the tests - `goconst` (24): shared constants for template/JSON keys in `internal/handlers` and repeated test literals - `gosec` (23): app-page redirects now go through a `redirectToApp` helper that path-escapes the app ID (G710 open redirect); `http.ServeFile` of the internally derived deployment log path annotated like the adjacent `os.Stat` (G703) - `dupl` (22): extracted a generic `findAllByAppID` in `internal/models`, a `deleteAppResource` helper in `internal/handlers`, a shared `parsePush` in `internal/service/webhook`, and table-driven/helper-based dedup in tests - `nolintlint` (5): removed `//nolint:funlen` directives made obsolete by the new limits (plus one more that became obsolete after refactoring) - `nilerr` (3, surfaced during fixing): resource-delete lookups now propagate the find error to the caller No behavior changes intended; all tests pass and `make check` is green. Note: golangci-lint v2.12 warns that `gomodguard` is deprecated in favor of `gomodguard_v2` — a future canonical-config update should address this centrally. Co-authored-by: sneak <sneak@sneak.berlin> Reviewed-on: #187 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org>
633 lines
16 KiB
Go
633 lines
16 KiB
Go
package app_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/fx"
|
|
|
|
"sneak.berlin/go/upaas/internal/config"
|
|
"sneak.berlin/go/upaas/internal/database"
|
|
"sneak.berlin/go/upaas/internal/globals"
|
|
"sneak.berlin/go/upaas/internal/logger"
|
|
"sneak.berlin/go/upaas/internal/models"
|
|
"sneak.berlin/go/upaas/internal/service/app"
|
|
)
|
|
|
|
// testRepoURL is the default repository URL used across tests.
|
|
const testRepoURL = "git@example.com:user/repo.git"
|
|
|
|
// giteaRepoURL is the gitea repository URL used across tests.
|
|
const giteaRepoURL = "git@gitea.example.com:user/repo.git"
|
|
|
|
func setupTestService(t *testing.T) (*app.Service, func()) {
|
|
t.Helper()
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
globals.SetAppname("upaas-test")
|
|
globals.SetVersion("test")
|
|
|
|
globalsInst, err := globals.New(fx.Lifecycle(nil))
|
|
require.NoError(t, err)
|
|
|
|
loggerInst, err := logger.New(
|
|
fx.Lifecycle(nil),
|
|
logger.Params{Globals: globalsInst},
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
cfg := &config.Config{
|
|
Port: 8080,
|
|
DataDir: tmpDir,
|
|
SessionSecret: "test-secret-key-at-least-32-chars",
|
|
}
|
|
|
|
dbInst, err := database.New(fx.Lifecycle(nil), database.Params{
|
|
Logger: loggerInst,
|
|
Config: cfg,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
svc, err := app.New(fx.Lifecycle(nil), app.ServiceParams{
|
|
Logger: loggerInst,
|
|
Database: dbInst,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
// t.TempDir() automatically cleans up after test
|
|
cleanup := func() {}
|
|
|
|
return svc, cleanup
|
|
}
|
|
|
|
// deleteItemTestHelper is a generic helper for testing delete operations.
|
|
// It creates an app, adds an item, verifies it exists, deletes it, and
|
|
// verifies it's gone.
|
|
func deleteItemTestHelper(
|
|
t *testing.T,
|
|
appName string,
|
|
addItem func(ctx context.Context, svc *app.Service, appID string) error,
|
|
getCount func(ctx context.Context, application *models.App) (int, error),
|
|
deleteItem func(ctx context.Context, svc *app.Service, application *models.App) error,
|
|
) {
|
|
t.Helper()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: appName,
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
err = addItem(context.Background(), svc, createdApp.ID)
|
|
require.NoError(t, err)
|
|
|
|
count, err := getCount(context.Background(), createdApp)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 1, count)
|
|
|
|
err = deleteItem(context.Background(), svc, createdApp)
|
|
require.NoError(t, err)
|
|
|
|
count, err = getCount(context.Background(), createdApp)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 0, count)
|
|
}
|
|
|
|
// runDeleteItemTest adapts typed list/delete callbacks so delete tests for
|
|
// different item types can share deleteItemTestHelper.
|
|
func runDeleteItemTest[T any](
|
|
t *testing.T,
|
|
appName string,
|
|
addItem func(ctx context.Context, svc *app.Service, appID string) error,
|
|
listItems func(ctx context.Context, application *models.App) ([]T, error),
|
|
deleteFirst func(ctx context.Context, svc *app.Service, item T) error,
|
|
) {
|
|
t.Helper()
|
|
|
|
deleteItemTestHelper(t, appName,
|
|
addItem,
|
|
func(ctx context.Context, application *models.App) (int, error) {
|
|
items, err := listItems(ctx, application)
|
|
|
|
return len(items), err
|
|
},
|
|
func(ctx context.Context, svc *app.Service, application *models.App) error {
|
|
items, err := listItems(ctx, application)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return deleteFirst(ctx, svc, items[0])
|
|
},
|
|
)
|
|
}
|
|
|
|
func TestCreateAppWithGeneratedKeys(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
input := app.CreateAppInput{
|
|
Name: "test-app",
|
|
RepoURL: giteaRepoURL,
|
|
Branch: "main",
|
|
DockerfilePath: "Dockerfile",
|
|
}
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), input)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, createdApp)
|
|
|
|
assert.Equal(t, "test-app", createdApp.Name)
|
|
assert.Equal(t, giteaRepoURL, createdApp.RepoURL)
|
|
assert.Equal(t, "main", createdApp.Branch)
|
|
assert.Equal(t, "Dockerfile", createdApp.DockerfilePath)
|
|
assert.NotEmpty(t, createdApp.ID)
|
|
assert.NotEmpty(t, createdApp.WebhookSecret)
|
|
assert.NotEmpty(t, createdApp.SSHPrivateKey)
|
|
assert.NotEmpty(t, createdApp.SSHPublicKey)
|
|
assert.Contains(t, createdApp.SSHPrivateKey, "-----BEGIN OPENSSH PRIVATE KEY-----")
|
|
assert.Contains(t, createdApp.SSHPublicKey, "ssh-ed25519")
|
|
assert.Equal(t, models.AppStatusPending, createdApp.Status)
|
|
}
|
|
|
|
func TestCreateAppDefaults(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
input := app.CreateAppInput{
|
|
Name: "test-app-defaults",
|
|
RepoURL: giteaRepoURL,
|
|
}
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), input)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "main", createdApp.Branch)
|
|
assert.Equal(t, "Dockerfile", createdApp.DockerfilePath)
|
|
}
|
|
|
|
func TestCreateAppOptionalFields(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
input := app.CreateAppInput{
|
|
Name: "test-app-full",
|
|
RepoURL: giteaRepoURL,
|
|
Branch: "develop",
|
|
DockerNetwork: "my-network",
|
|
NtfyTopic: "https://ntfy.sh/my-topic",
|
|
SlackWebhook: "https://hooks.slack.com/services/xxx",
|
|
}
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), input)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, createdApp.DockerNetwork.Valid)
|
|
assert.Equal(t, "my-network", createdApp.DockerNetwork.String)
|
|
assert.True(t, createdApp.NtfyTopic.Valid)
|
|
assert.Equal(t, "https://ntfy.sh/my-topic", createdApp.NtfyTopic.String)
|
|
assert.True(t, createdApp.SlackWebhook.Valid)
|
|
}
|
|
|
|
func TestUpdateApp(testingT *testing.T) {
|
|
testingT.Parallel()
|
|
|
|
testingT.Run("updates app fields", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "original-name",
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
err = svc.UpdateApp(context.Background(), createdApp, app.UpdateAppInput{
|
|
Name: "updated-name",
|
|
RepoURL: "git@example.com:user/new-repo.git",
|
|
Branch: "develop",
|
|
DockerfilePath: "docker/Dockerfile",
|
|
DockerNetwork: "prod-network",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
// Reload and verify
|
|
reloaded, err := svc.GetApp(context.Background(), createdApp.ID)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "updated-name", reloaded.Name)
|
|
assert.Equal(t, "git@example.com:user/new-repo.git", reloaded.RepoURL)
|
|
assert.Equal(t, "develop", reloaded.Branch)
|
|
assert.Equal(t, "docker/Dockerfile", reloaded.DockerfilePath)
|
|
assert.Equal(t, "prod-network", reloaded.DockerNetwork.String)
|
|
})
|
|
|
|
testingT.Run("clears optional fields when empty", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "test-clear",
|
|
RepoURL: testRepoURL,
|
|
NtfyTopic: "https://ntfy.sh/topic",
|
|
SlackWebhook: "https://slack.com/hook",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
err = svc.UpdateApp(context.Background(), createdApp, app.UpdateAppInput{
|
|
Name: "test-clear",
|
|
RepoURL: testRepoURL,
|
|
Branch: "main",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
reloaded, err := svc.GetApp(context.Background(), createdApp.ID)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, reloaded.NtfyTopic.Valid)
|
|
assert.False(t, reloaded.SlackWebhook.Valid)
|
|
})
|
|
}
|
|
|
|
func TestDeleteApp(testingT *testing.T) {
|
|
testingT.Parallel()
|
|
|
|
testingT.Run("deletes app and returns nil on lookup", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "to-delete",
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
err = svc.DeleteApp(context.Background(), createdApp)
|
|
require.NoError(t, err)
|
|
|
|
deleted, err := svc.GetApp(context.Background(), createdApp.ID)
|
|
require.NoError(t, err)
|
|
assert.Nil(t, deleted)
|
|
})
|
|
}
|
|
|
|
func TestGetApp(testingT *testing.T) {
|
|
testingT.Parallel()
|
|
|
|
testingT.Run("finds existing app", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
created, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "findable-app",
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
found, err := svc.GetApp(context.Background(), created.ID)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, found)
|
|
|
|
assert.Equal(t, created.ID, found.ID)
|
|
assert.Equal(t, "findable-app", found.Name)
|
|
})
|
|
|
|
testingT.Run("returns nil for non-existent app", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
found, err := svc.GetApp(context.Background(), "non-existent-id")
|
|
require.NoError(t, err)
|
|
assert.Nil(t, found)
|
|
})
|
|
}
|
|
|
|
func TestGetAppByWebhookSecret(testingT *testing.T) {
|
|
testingT.Parallel()
|
|
|
|
testingT.Run("finds app by webhook secret", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
created, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "webhook-app",
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
found, err := svc.GetAppByWebhookSecret(context.Background(), created.WebhookSecret)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, found)
|
|
|
|
assert.Equal(t, created.ID, found.ID)
|
|
})
|
|
|
|
testingT.Run("returns nil for invalid secret", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
found, err := svc.GetAppByWebhookSecret(context.Background(), "invalid-secret")
|
|
require.NoError(t, err)
|
|
assert.Nil(t, found)
|
|
})
|
|
}
|
|
|
|
func TestListApps(testingT *testing.T) {
|
|
testingT.Parallel()
|
|
|
|
testingT.Run("returns empty list when no apps", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
apps, err := svc.ListApps(context.Background())
|
|
require.NoError(t, err)
|
|
assert.Empty(t, apps)
|
|
})
|
|
|
|
testingT.Run("returns all apps ordered by name", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
_, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "charlie",
|
|
RepoURL: "git@example.com:user/c.git",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
_, err = svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "alpha",
|
|
RepoURL: "git@example.com:user/a.git",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
_, err = svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "bravo",
|
|
RepoURL: "git@example.com:user/b.git",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
apps, err := svc.ListApps(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, apps, 3)
|
|
|
|
assert.Equal(t, "alpha", apps[0].Name)
|
|
assert.Equal(t, "bravo", apps[1].Name)
|
|
assert.Equal(t, "charlie", apps[2].Name)
|
|
})
|
|
}
|
|
|
|
func TestEnvVarsAddAndRetrieve(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "env-test",
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
err = svc.AddEnvVar(
|
|
context.Background(),
|
|
createdApp.ID,
|
|
"DATABASE_URL",
|
|
"postgres://localhost/db",
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
err = svc.AddEnvVar(
|
|
context.Background(),
|
|
createdApp.ID,
|
|
"API_KEY",
|
|
"secret123",
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
envVars, err := createdApp.GetEnvVars(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, envVars, 2)
|
|
|
|
keys := make(map[string]string)
|
|
for _, envVar := range envVars {
|
|
keys[envVar.Key] = envVar.Value
|
|
}
|
|
|
|
assert.Equal(t, "postgres://localhost/db", keys["DATABASE_URL"])
|
|
assert.Equal(t, "secret123", keys["API_KEY"])
|
|
}
|
|
|
|
// addDeletableEnvVar seeds the env var removed in the delete test.
|
|
func addDeletableEnvVar(
|
|
ctx context.Context, svc *app.Service, appID string,
|
|
) error {
|
|
return svc.AddEnvVar(ctx, appID, "TO_DELETE", "value")
|
|
}
|
|
|
|
func TestEnvVarsDelete(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
runDeleteItemTest(t, "env-delete-test", addDeletableEnvVar,
|
|
func(ctx context.Context, application *models.App) ([]*models.EnvVar, error) {
|
|
return application.GetEnvVars(ctx)
|
|
},
|
|
func(ctx context.Context, svc *app.Service, item *models.EnvVar) error {
|
|
return svc.DeleteEnvVar(ctx, item.ID)
|
|
},
|
|
)
|
|
}
|
|
|
|
// addDeletableLabel seeds the label removed in the delete test.
|
|
func addDeletableLabel(
|
|
ctx context.Context, svc *app.Service, appID string,
|
|
) error {
|
|
return svc.AddLabel(ctx, appID, "to.delete", "value")
|
|
}
|
|
|
|
func TestLabels(testingT *testing.T) {
|
|
testingT.Parallel()
|
|
|
|
testingT.Run("adds and retrieves labels", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "label-test",
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
err = svc.AddLabel(context.Background(), createdApp.ID, "traefik.enable", "true")
|
|
require.NoError(t, err)
|
|
|
|
err = svc.AddLabel(
|
|
context.Background(),
|
|
createdApp.ID,
|
|
"com.example.env",
|
|
"production",
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
labels, err := createdApp.GetLabels(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, labels, 2)
|
|
})
|
|
|
|
testingT.Run("deletes label", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
runDeleteItemTest(t, "label-delete-test", addDeletableLabel,
|
|
func(ctx context.Context, application *models.App) ([]*models.Label, error) {
|
|
return application.GetLabels(ctx)
|
|
},
|
|
func(ctx context.Context, svc *app.Service, item *models.Label) error {
|
|
return svc.DeleteLabel(ctx, item.ID)
|
|
},
|
|
)
|
|
})
|
|
}
|
|
|
|
func TestVolumesAddAndRetrieve(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "volume-test",
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
err = svc.AddVolume(
|
|
context.Background(),
|
|
createdApp.ID,
|
|
"/host/data",
|
|
"/app/data",
|
|
false,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
err = svc.AddVolume(
|
|
context.Background(),
|
|
createdApp.ID,
|
|
"/host/config",
|
|
"/app/config",
|
|
true,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
volumes, err := createdApp.GetVolumes(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, volumes, 2)
|
|
|
|
// Find readonly volume
|
|
var readonlyVolume *models.Volume
|
|
|
|
for _, vol := range volumes {
|
|
if vol.ReadOnly {
|
|
readonlyVolume = vol
|
|
|
|
break
|
|
}
|
|
}
|
|
|
|
require.NotNil(t, readonlyVolume)
|
|
assert.Equal(t, "/host/config", readonlyVolume.HostPath)
|
|
assert.Equal(t, "/app/config", readonlyVolume.ContainerPath)
|
|
}
|
|
|
|
func TestVolumesDelete(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "volume-delete-test",
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
err = svc.AddVolume(
|
|
context.Background(),
|
|
createdApp.ID,
|
|
"/host/path",
|
|
"/container/path",
|
|
false,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
volumes, err := createdApp.GetVolumes(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, volumes, 1)
|
|
|
|
err = svc.DeleteVolume(context.Background(), volumes[0].ID)
|
|
require.NoError(t, err)
|
|
|
|
volumes, err = createdApp.GetVolumes(context.Background())
|
|
require.NoError(t, err)
|
|
assert.Empty(t, volumes)
|
|
}
|
|
|
|
func TestUpdateAppStatus(testingT *testing.T) {
|
|
testingT.Parallel()
|
|
|
|
testingT.Run("updates app status", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
svc, cleanup := setupTestService(t)
|
|
defer cleanup()
|
|
|
|
createdApp, err := svc.CreateApp(context.Background(), app.CreateAppInput{
|
|
Name: "status-test",
|
|
RepoURL: testRepoURL,
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, models.AppStatusPending, createdApp.Status)
|
|
|
|
err = svc.UpdateAppStatus(
|
|
context.Background(),
|
|
createdApp,
|
|
models.AppStatusBuilding,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
reloaded, err := svc.GetApp(context.Background(), createdApp.ID)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, models.AppStatusBuilding, reloaded.Status)
|
|
})
|
|
}
|