tests: update cli help/json checks
This commit is contained in:
@@ -3,14 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
|
||||||
"flag"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"goyco/cmd/goyco/commands"
|
||||||
"goyco/internal/config"
|
"goyco/internal/config"
|
||||||
"goyco/internal/database"
|
"goyco/internal/database"
|
||||||
"goyco/internal/handlers"
|
"goyco/internal/handlers"
|
||||||
@@ -267,25 +266,24 @@ func TestConfigLoadingInCLI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFlagParsingInCLI(t *testing.T) {
|
func TestFlagParsingInCLI(t *testing.T) {
|
||||||
originalArgs := os.Args
|
|
||||||
defer func() {
|
|
||||||
os.Args = originalArgs
|
|
||||||
}()
|
|
||||||
|
|
||||||
t.Run("help flag", func(t *testing.T) {
|
t.Run("help flag", func(t *testing.T) {
|
||||||
os.Args = []string{"goyco", "--help"}
|
cmd := buildRootCommand(testutils.NewTestConfig())
|
||||||
fs := flag.NewFlagSet("goyco", flag.ContinueOnError)
|
err := cmd.Run(context.Background(), []string{"goyco", "--help"})
|
||||||
fs.SetOutput(os.Stderr)
|
if err != nil {
|
||||||
showHelp := fs.Bool("help", false, "show help")
|
|
||||||
|
|
||||||
err := fs.Parse([]string{"--help"})
|
|
||||||
if err != nil && !errors.Is(err, flag.ErrHelp) {
|
|
||||||
t.Errorf("Expected help flag parsing, got error: %v", err)
|
t.Errorf("Expected help flag parsing, got error: %v", err)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if !*showHelp {
|
t.Run("json flag", func(t *testing.T) {
|
||||||
t.Error("Expected help flag to be true")
|
cmd := buildRootCommand(testutils.NewTestConfig())
|
||||||
|
err := cmd.Run(context.Background(), []string{"goyco", "--json"})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Expected json flag parsing, got error: %v", err)
|
||||||
}
|
}
|
||||||
|
if !commands.IsJSONOutput() {
|
||||||
|
t.Error("Expected json output to be enabled")
|
||||||
|
}
|
||||||
|
commands.SetJSONOutput(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("command dispatch", func(t *testing.T) {
|
t.Run("command dispatch", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user