gitea源码

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2025 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "context"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/urfave/cli/v3"
  9. )
  10. func TestDefaultCommand(t *testing.T) {
  11. test := func(t *testing.T, args []string, expectedRetName string, expectedRetValid bool) {
  12. called := false
  13. cmd := &cli.Command{
  14. DefaultCommand: "test",
  15. Commands: []*cli.Command{
  16. {
  17. Name: "test",
  18. Action: func(ctx context.Context, command *cli.Command) error {
  19. retName, retValid := isValidDefaultSubCommand(command)
  20. assert.Equal(t, expectedRetName, retName)
  21. assert.Equal(t, expectedRetValid, retValid)
  22. called = true
  23. return nil
  24. },
  25. },
  26. },
  27. }
  28. assert.NoError(t, cmd.Run(t.Context(), args))
  29. assert.True(t, called)
  30. }
  31. test(t, []string{"./gitea"}, "", true)
  32. test(t, []string{"./gitea", "test"}, "", true)
  33. test(t, []string{"./gitea", "other"}, "other", false)
  34. }