Files
Atay-Makhzan/cmd/doctor_test.go
T

35 lines
995 B
Go
Raw Normal View History

2023-12-11 23:55:10 +08:00
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package cmd
import (
"context"
"testing"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/services/doctor"
2023-12-11 23:55:10 +08:00
"github.com/stretchr/testify/assert"
2025-06-10 14:35:12 +02:00
"github.com/urfave/cli/v3"
2023-12-11 23:55:10 +08:00
)
func TestDoctorRun(t *testing.T) {
doctor.Register(&doctor.Check{
Title: "Test Check",
Name: "test-check",
Run: func(ctx context.Context, logger log.Logger, autofix bool) error { return nil },
SkipDatabaseInitialization: true,
})
2025-06-10 14:35:12 +02:00
app := &cli.Command{
Commands: []*cli.Command{newDoctorCheckCommand()},
2025-06-10 14:35:12 +02:00
}
err := app.Run(t.Context(), []string{"./gitea", "check", "--run", "test-check"})
2023-12-11 23:55:10 +08:00
assert.NoError(t, err)
2025-06-10 14:35:12 +02:00
err = app.Run(t.Context(), []string{"./gitea", "check", "--run", "no-such"})
2023-12-11 23:55:10 +08:00
assert.ErrorContains(t, err, `unknown checks: "no-such"`)
2025-06-10 14:35:12 +02:00
err = app.Run(t.Context(), []string{"./gitea", "check", "--run", "test-check,no-such"})
2023-12-11 23:55:10 +08:00
assert.ErrorContains(t, err, `unknown checks: "no-such"`)
}