go-blockchain/commands_test.go
Snider aa3d8270a2 feat: modernise CLI — AddChainCommands, explorer/sync subcommands, core-chain binary
Migrate from stdlib flag to cli.Main() + WithCommands() pattern:
- AddChainCommands() registration with persistent --data-dir/--seed/--testnet flags
- Explorer subcommand (TUI block explorer, replaces old default mode)
- Sync subcommand with headless foreground and --daemon/--stop modes
- sync_service.go extracts syncLoop/syncOnce from old main.go
- cmd/core-chain/main.go standalone binary entry point
- Add go-process dependency for daemon lifecycle

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 16:21:42 +00:00

48 lines
1.2 KiB
Go

// Copyright (c) 2017-2026 Lethean (https://lt.hn)
//
// Licensed under the European Union Public Licence (EUPL) version 1.2.
// SPDX-License-Identifier: EUPL-1.2
package blockchain
import (
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAddChainCommands_Good_RegistersParent(t *testing.T) {
root := &cobra.Command{Use: "test"}
AddChainCommands(root)
chainCmd, _, err := root.Find([]string{"chain"})
require.NoError(t, err)
assert.Equal(t, "chain", chainCmd.Name())
}
func TestAddChainCommands_Good_HasSubcommands(t *testing.T) {
root := &cobra.Command{Use: "test"}
AddChainCommands(root)
chainCmd, _, _ := root.Find([]string{"chain"})
var names []string
for _, sub := range chainCmd.Commands() {
names = append(names, sub.Name())
}
assert.Contains(t, names, "explorer")
assert.Contains(t, names, "sync")
}
func TestAddChainCommands_Good_PersistentFlags(t *testing.T) {
root := &cobra.Command{Use: "test"}
AddChainCommands(root)
chainCmd, _, _ := root.Find([]string{"chain"})
assert.NotNil(t, chainCmd.PersistentFlags().Lookup("data-dir"))
assert.NotNil(t, chainCmd.PersistentFlags().Lookup("seed"))
assert.NotNil(t, chainCmd.PersistentFlags().Lookup("testnet"))
}