code.gitea.io/gitea@v1.21.7/cmd/doctor_test.go (about)

     1  // Copyright 2023 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package cmd
     5  
     6  import (
     7  	"context"
     8  	"testing"
     9  
    10  	"code.gitea.io/gitea/modules/doctor"
    11  	"code.gitea.io/gitea/modules/log"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  	"github.com/urfave/cli/v2"
    15  )
    16  
    17  func TestDoctorRun(t *testing.T) {
    18  	doctor.Register(&doctor.Check{
    19  		Title: "Test Check",
    20  		Name:  "test-check",
    21  		Run:   func(ctx context.Context, logger log.Logger, autofix bool) error { return nil },
    22  
    23  		SkipDatabaseInitialization: true,
    24  	})
    25  	app := cli.NewApp()
    26  	app.Commands = []*cli.Command{cmdDoctorCheck}
    27  	err := app.Run([]string{"./gitea", "check", "--run", "test-check"})
    28  	assert.NoError(t, err)
    29  	err = app.Run([]string{"./gitea", "check", "--run", "no-such"})
    30  	assert.ErrorContains(t, err, `unknown checks: "no-such"`)
    31  	err = app.Run([]string{"./gitea", "check", "--run", "test-check,no-such"})
    32  	assert.ErrorContains(t, err, `unknown checks: "no-such"`)
    33  }