Skip to content
Open
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Configuration lives in `.core/build.yaml` (targets, ldflags) and `.core/release.
## Coding Standards

- **UK English**: colour, organisation, centre
- **Tests**: testify assert/require, `_Good`/`_Bad`/`_Ugly` naming convention
- **Tests**: standard `testing` checks only; no testify. Use `_Good`/`_Bad`/`_Ugly` naming convention
- **Conventional commits**: `feat(ansible):`, `fix(infra):`, `refactor(build):`
- **Co-Author**: `Co-Authored-By: Virgil <virgil@lethean.io>`
- **Licence**: EUPL-1.2
Expand Down
39 changes: 39 additions & 0 deletions cmd/deploy/ax7_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package deploy

import (
core "dappco.re/go"
"dappco.re/go/cli/pkg/cli"
)

func TestAX7_AddDeployCommands_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddDeployCommands(root)
commands := root.Commands()

core.AssertLen(t, commands, 1)
core.AssertEqual(t, "deploy", commands[0].Use)
}

func TestAX7_AddDeployCommands_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddDeployCommands(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddDeployCommands_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
root.AddCommand(&cli.Command{Use: "existing"})
AddDeployCommands(root)

foundExisting := false
foundDeploy := false
for _, cmd := range root.Commands() {
foundExisting = foundExisting || cmd.Use == "existing"
foundDeploy = foundDeploy || cmd.Use == "deploy"
}
core.AssertLen(t, root.Commands(), 2)
core.AssertTrue(t, foundExisting)
core.AssertTrue(t, foundDeploy)
}
80 changes: 80 additions & 0 deletions cmd/dev/ax7_bundle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package dev

import core "dappco.re/go"

func TestAX7_NewWorkBundle_Good(t *core.T) {
bundle, err := NewWorkBundle(WorkBundleOptions{})
core.AssertNoError(t, err)

core.AssertNotNil(t, bundle)
core.AssertNotNil(t, bundle.Core)
}

func TestAX7_NewWorkBundle_Bad(t *core.T) {
bundle, err := NewWorkBundle(WorkBundleOptions{RegistryPath: "\x00"})
core.AssertNoError(t, err)

core.AssertNotNil(t, bundle)
core.AssertNotNil(t, bundle.Core)
}

func TestAX7_NewWorkBundle_Ugly(t *core.T) {
first, err := NewWorkBundle(WorkBundleOptions{})
core.RequireNoError(t, err)
second, err := NewWorkBundle(WorkBundleOptions{})

core.AssertNoError(t, err)
core.AssertFalse(t, first.Core == second.Core)
}

func TestAX7_WorkBundle_Start_Good(t *core.T) {
bundle, err := NewWorkBundle(WorkBundleOptions{})
core.RequireNoError(t, err)

core.AssertNoError(t, bundle.Start(core.Background()))
core.AssertNoError(t, bundle.Stop(core.Background()))
}

func TestAX7_WorkBundle_Start_Bad(t *core.T) {
var bundle *WorkBundle
core.AssertPanics(t, func() {
_ = bundle.Start(core.Background())
})
core.AssertNil(t, bundle)
}

func TestAX7_WorkBundle_Start_Ugly(t *core.T) {
bundle, err := NewWorkBundle(WorkBundleOptions{})
core.RequireNoError(t, err)
err = bundle.Start(core.Background())

core.AssertNoError(t, err)
core.AssertNoError(t, bundle.Start(core.Background()))
core.AssertNoError(t, bundle.Stop(core.Background()))
}

func TestAX7_WorkBundle_Stop_Good(t *core.T) {
bundle, err := NewWorkBundle(WorkBundleOptions{})
core.RequireNoError(t, err)
core.RequireNoError(t, bundle.Start(core.Background()))

err = bundle.Stop(core.Background())
core.AssertNoError(t, err)
}

func TestAX7_WorkBundle_Stop_Bad(t *core.T) {
var bundle *WorkBundle
core.AssertPanics(t, func() {
_ = bundle.Stop(core.Background())
})
core.AssertNil(t, bundle)
}

func TestAX7_WorkBundle_Stop_Ugly(t *core.T) {
bundle, err := NewWorkBundle(WorkBundleOptions{})
core.RequireNoError(t, err)

err = bundle.Stop(core.Background())
core.AssertNoError(t, err)
core.AssertNotNil(t, bundle.Core)
}
249 changes: 249 additions & 0 deletions cmd/dev/ax7_commands_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
package dev

import (
core "dappco.re/go"
"dappco.re/go/cli/pkg/cli"
)

func ax7Command(root *cli.Command, use string) *cli.Command {
for _, cmd := range root.Commands() {
if cmd.Use == use || core.HasPrefix(cmd.Use, use+" ") {
return cmd
}
}
return nil
}

func TestAX7_AddDevCommands_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddDevCommands(root)
devCmd := ax7Command(root, "dev")

core.AssertNotNil(t, devCmd)
core.AssertGreaterOrEqual(t, len(devCmd.Commands()), 10)
}

func TestAX7_AddDevCommands_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddDevCommands(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddDevCommands_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
root.AddCommand(&cli.Command{Use: "existing"})
AddDevCommands(root)

core.AssertLen(t, root.Commands(), 2)
core.AssertNotNil(t, ax7Command(root, "dev"))
}

func TestAX7_AddApplyCommand_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddApplyCommand(root)
cmd := ax7Command(root, "apply")

core.AssertNotNil(t, cmd)
core.AssertNotNil(t, cmd.Flag("command"))
}

func TestAX7_AddApplyCommand_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddApplyCommand(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddApplyCommand_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
AddApplyCommand(root)
AddApplyCommand(root)

core.AssertLen(t, root.Commands(), 2)
core.AssertNotNil(t, ax7Command(root, "apply"))
}

func TestAX7_AddFileSyncCommand_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddFileSyncCommand(root)
cmd := ax7Command(root, "sync")

core.AssertNotNil(t, cmd)
core.AssertNotNil(t, cmd.Flag("to"))
}

func TestAX7_AddFileSyncCommand_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddFileSyncCommand(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddFileSyncCommand_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
AddFileSyncCommand(root)
AddFileSyncCommand(root)

core.AssertLen(t, root.Commands(), 2)
core.AssertNotNil(t, ax7Command(root, "sync"))
}

func TestAX7_AddPushCommand_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddPushCommand(root)
cmd := ax7Command(root, "push")

core.AssertNotNil(t, cmd)
core.AssertNotNil(t, cmd.Flag("force"))
}

func TestAX7_AddPushCommand_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddPushCommand(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddPushCommand_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
root.AddCommand(&cli.Command{Use: "existing"})
AddPushCommand(root)

core.AssertLen(t, root.Commands(), 2)
core.AssertNotNil(t, ax7Command(root, "push"))
}

func TestAX7_AddWorkCommand_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddWorkCommand(root)
cmd := ax7Command(root, "work")

core.AssertNotNil(t, cmd)
core.AssertNotNil(t, cmd.Flag("status"))
}

func TestAX7_AddWorkCommand_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddWorkCommand(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddWorkCommand_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
AddWorkCommand(root)
AddWorkCommand(root)

core.AssertLen(t, root.Commands(), 2)
core.AssertNotNil(t, ax7Command(root, "work"))
}

func TestAX7_AddCommitCommand_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddCommitCommand(root)
cmd := ax7Command(root, "commit")

core.AssertNotNil(t, cmd)
core.AssertNotNil(t, cmd.Flag("all"))
}

func TestAX7_AddCommitCommand_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddCommitCommand(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddCommitCommand_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
root.AddCommand(&cli.Command{Use: "existing"})
AddCommitCommand(root)

core.AssertLen(t, root.Commands(), 2)
core.AssertNotNil(t, ax7Command(root, "commit"))
}

func TestAX7_AddHealthCommand_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddHealthCommand(root)
cmd := ax7Command(root, "health")

core.AssertNotNil(t, cmd)
core.AssertNotNil(t, cmd.Flag("verbose"))
}

func TestAX7_AddHealthCommand_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddHealthCommand(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddHealthCommand_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
AddHealthCommand(root)
AddHealthCommand(root)

core.AssertLen(t, root.Commands(), 2)
core.AssertNotNil(t, ax7Command(root, "health"))
}

func TestAX7_AddTagCommand_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddTagCommand(root)
cmd := ax7Command(root, "tag")

core.AssertNotNil(t, cmd)
core.AssertNotNil(t, cmd.Flag("dry-run"))
}

func TestAX7_AddTagCommand_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddTagCommand(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddTagCommand_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
root.AddCommand(&cli.Command{Use: "existing"})
AddTagCommand(root)

core.AssertLen(t, root.Commands(), 2)
core.AssertNotNil(t, ax7Command(root, "tag"))
}

func TestAX7_AddPullCommand_Good(t *core.T) {
root := &cli.Command{Use: "root"}
AddPullCommand(root)
cmd := ax7Command(root, "pull")

core.AssertNotNil(t, cmd)
core.AssertNotNil(t, cmd.Flag("all"))
}

func TestAX7_AddPullCommand_Bad(t *core.T) {
var root *cli.Command
core.AssertPanics(t, func() {
AddPullCommand(root)
})
core.AssertNil(t, root)
}

func TestAX7_AddPullCommand_Ugly(t *core.T) {
root := &cli.Command{Use: "root"}
AddPullCommand(root)
AddPullCommand(root)

core.AssertLen(t, root.Commands(), 2)
core.AssertNotNil(t, ax7Command(root, "pull"))
}
2 changes: 1 addition & 1 deletion cmd/dev/cmd_api.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev

import (
"dappco.re/go/i18n"
"dappco.re/go/cli/pkg/cli"
"dappco.re/go/i18n"
)

// addAPICommands adds the 'api' command and its subcommands to the given parent command.
Expand Down
Loading