Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,22 @@ Coverage profiles are written to `coverage-unit.out` and

### Running e2e tests locally

Requires Docker. Creates and destroys a Kind cluster named `deployah`.
You need Docker. The suite creates a Kind cluster named `deployah` and
deletes it afterwards.

```sh
DEPLOYAH_E2E_FORCE=1 nix run .#test-e2e
```

Skips automatically when no container engine is found (unless `CI=true`).
Set `DEPLOYAH_E2E_DUMP=1` with `-v` to print live objects when adding a scenario.
Without Docker the suite skips. With `CI=true` it fails.
Put `e2e.yaml` in `scenarios/<name>/` to run that spec on Kind. Generate a
skeleton with:

```sh
go test ./internal/e2e/ -tags e2e -run TestE2EFixtures/<name> -e2e.scaffold
```

`-e2e.preserve` keeps the namespace after a failure.

### Build and run

Expand All @@ -528,11 +536,10 @@ nix run .#publish-demo # sync docs/assets/ to R2 (needs R2_* env vars)
### CI

GitHub Actions runs flake validation, lint/fmt/tidy checks, `nix run .#test-unit`,
`nix run .#test-integration`, and `nix run .#test-e2e` on every pull request and
push to `main`.
Scenario fixtures under `scenarios/` and e2e fixtures under
`internal/e2e/testdata/` (including `deployah.yaml`, `deployah.platform.yaml`,
and `.deployah/`) are tracked so tests can run on a clean checkout.
`nix run .#test-integration`, and `nix run .#test-e2e` on pull requests and
pushes to `main`.
Commit `deployah.yaml`, `expected/`, `e2e.yaml`, and `.deployah/` under
`scenarios/`. CI reads those files from a clean checkout.

```sh
nix flake check # runs the pre-commit hooks (lint, markdownlint, links, tidy, nixfmt)
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

buildGoModule' = pkgs.buildGoModule.override { inherit go; };

deployahVendorHash = "sha256-8nj4lEfjnl8xnNRCM0P32zXAxATUOh4XPJql4gqxvYE=";
deployahVendorHash = "sha256-zltKCgHj7sC3FSTbuAFxBjS03XaU/d6Vz5BKH8wgkbc=";

inherit (pkgs) golangci-lint gopls;

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
k8s.io/apimachinery v0.36.4
k8s.io/client-go v0.36.4
mvdan.cc/sh/v3 v3.13.1
nabat.dev v0.8.0
nabat.dev v0.9.0
sigs.k8s.io/e2e-framework v0.7.0
sigs.k8s.io/kind v0.32.0
sigs.k8s.io/yaml v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ k8s.io/utils v0.0.0-20260707023825-cf1189d6abe3 h1:jVkFFVfXdXP74B/zbO3hM3hpSFD0x
k8s.io/utils v0.0.0-20260707023825-cf1189d6abe3/go.mod h1:M2s5JB1lIYP3jzZdorPLHXIPJzt9vv2muW5a6L9DtNM=
mvdan.cc/sh/v3 v3.13.1 h1:DP3TfgZhDkT7lerUdnp6PTGKyxxzz6T+cOlY/xEvfWk=
mvdan.cc/sh/v3 v3.13.1/go.mod h1:lXJ8SexMvEVcHCoDvAGLZgFJ9Wsm2sulmoNEXGhYZD0=
nabat.dev v0.8.0 h1:8tilU5GFZQHC0R7SzTtFO0a5xi9CMuQEG7ZMuYpUCrg=
nabat.dev v0.8.0/go.mod h1:S44WwDY/h4hQgAPrtEmazmFuQUO8eKISu1CR0Ea/nJE=
nabat.dev v0.9.0 h1:uWkVsLJXct8Bnm+wAfiEY5yqKDP3BxMEIohJRIcgD8k=
nabat.dev v0.9.0/go.mod h1:S44WwDY/h4hQgAPrtEmazmFuQUO8eKISu1CR0Ea/nJE=
oras.land/oras-go/v2 v2.6.2 h1:N04RXngAp1LJKTG6ifz3xHPipasEkWr+hFmInja5YKo=
oras.land/oras-go/v2 v2.6.2/go.mod h1:PlTtg4JTDJkDe8yVHpM2wz7/YDc00GVas+i4jAW2TZ4=
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
Expand Down
8 changes: 5 additions & 3 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ func NewApp(opts ...nabat.Option) *nabat.App {

rtOpts := []session.Option{
session.WithNamespace(opts.Namespace),
session.WithKubeconfig(opts.Kubeconfig),
session.WithKubeContext(opts.Context),
session.WithSpecPath(opts.Spec),
session.WithSpecPath(c.Abs(opts.Spec)),
session.WithDebug(opts.Debug),
session.WithTimeout(opts.Timeout),
}
if opts.Kubeconfig != "" {
rtOpts = append(rtOpts, session.WithKubeconfig(c.Abs(opts.Kubeconfig)))
}
if opts.PlatformFile != "" {
rtOpts = append(rtOpts, session.WithPlatformFile(opts.PlatformFile))
rtOpts = append(rtOpts, session.WithPlatformFile(c.Abs(opts.PlatformFile)))
}
if localKubeconfig != "" {
rtOpts = append(rtOpts, session.WithExtraKubeconfigPaths(localKubeconfig))
Expand Down
140 changes: 140 additions & 0 deletions internal/cmd/root_dir_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 2025 The Deployah Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd_test

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"nabat.dev/nabat"
"nabat.dev/nabat/nabattest"

"deployah.dev/deployah/internal/cmd"
)

const specWithImageVar = `apiVersion: v1-alpha.5
project: withdir
components:
web:
image: ${IMAGE}
port: 80
environments: [dev]
environments:
dev:
envFile: .env.dev
`

const specLiteralImage = `apiVersion: v1-alpha.5
project: withdir
components:
web:
image: nginx:latest
port: 80
environments: [dev]
environments:
dev: {}
`

func writeWithDirFixture(t *testing.T, specFile, spec, envBody string) string {
t.Helper()
dir := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(dir, specFile), []byte(spec), 0o600))
if envBody != "" {
require.NoError(t, os.WriteFile(filepath.Join(dir, ".env.dev"), []byte(envBody), 0o600))
}
return dir
}

// TestWithDirResolvesSpecAndEnvFile checks that nabattest.WithDir and
// c.Abs resolve --spec and .env files against the virtual directory
// rather than the process working directory. The test never calls [os.Chdir].
func TestWithDirResolvesSpecAndEnvFile(t *testing.T) {
t.Parallel()

tests := []struct {
name string
spec string
specFile string
envBody string
args []string
}{
{
name: "env file relative to virtual dir",
spec: specWithImageVar,
specFile: "deployah.yaml",
envBody: "DPY_VAR_IMAGE=nginx:1.27\n",
args: []string{"plan", "dev", "--offline"},
},
{
name: "explicit --spec is Abs against virtual dir",
spec: specWithImageVar,
specFile: "app.yaml",
envBody: "DPY_VAR_IMAGE=nginx:1.27\n",
args: []string{"plan", "dev", "--offline", "--spec", "app.yaml"},
},
{
name: "literal image without env file",
spec: specLiteralImage,
specFile: "deployah.yaml",
args: []string{"plan", "dev", "--offline"},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
dir := writeWithDirFixture(t, tt.specFile, tt.spec, tt.envBody)
appIO, _, _, errOut := nabattest.NewIO()
app := cmd.NewApp(nabat.WithIO(appIO))
err := nabattest.RunParallel(t, app, tt.args, nabattest.WithDir(dir))
require.NoErrorf(t, err, "plan --offline under WithDir\nstderr:\n%s", errOut.String())
})
}
}

func TestWithDirResolvesSpecAndEnvFile_Error(t *testing.T) {
t.Parallel()

tests := []struct {
name string
spec string
specFile string
args []string
wantErr string
}{
{
name: "missing env file fails substitution",
spec: specWithImageVar,
specFile: "deployah.yaml",
args: []string{"plan", "dev", "--offline"},
wantErr: "environment file",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
dir := writeWithDirFixture(t, tt.specFile, tt.spec, "")
appIO, _, _, _ := nabattest.NewIO()
app := cmd.NewApp(nabat.WithIO(appIO))
err := nabattest.RunParallel(t, app, tt.args, nabattest.WithDir(dir))
require.Error(t, err)
assert.ErrorContains(t, err, tt.wantErr)
})
}
}
11 changes: 6 additions & 5 deletions internal/e2e/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package e2e holds Deployah's end-to-end suite, which drives the CLI
// in-process against a live Kind cluster.
// Package e2e drives the Deployah CLI in-process against a live Kind cluster.
//
// The tests are gated behind the "e2e" build tag and need a container engine;
// run them with `nix run .#test-e2e`. This file intentionally carries no build
// tag so `go list ./...` and golangci-lint can resolve the package without it.
// TestE2EFixtures runs every scenarios/*/e2e.yaml. TestCRDLifecycle mutates
// CRD files between CLI calls. The suite uses the "e2e" build tag and needs
// a container engine (`nix run .#test-e2e`).
// This file has no build tag so `go list ./...` and golangci-lint can
// resolve the package without the tag.
package e2e
Loading
Loading