mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-04 07:45:30 +00:00
Replace server startup panics with returned errors, print actionable CLI messages with exit status 1, and clarify the API token flags. Add regressions for missing web authentication credentials. Fixes GopeedLab/gopeed#1614
36 lines
886 B
Go
36 lines
886 B
Go
package cmd
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/GopeedLab/gopeed/pkg/rest/model"
|
|
)
|
|
|
|
func TestStartInvalidWebAPITokenReturnsError(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
webAuth *model.WebAuth
|
|
}{
|
|
{name: "no credentials"},
|
|
{name: "missing username", webAuth: &model.WebAuth{Password: "secret"}},
|
|
{name: "missing password", webAuth: &model.WebAuth{Username: "gopeed"}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := Start(&model.StartConfig{
|
|
WebEnable: true,
|
|
ApiToken: "test-token",
|
|
WebAuth: tt.webAuth,
|
|
})
|
|
if err == nil {
|
|
t.Fatal("Start() error = nil, want web authentication validation error")
|
|
}
|
|
if !strings.Contains(err.Error(), "web authentication username and password are required") {
|
|
t.Fatalf("Start() error = %q, want missing web authentication credentials", err)
|
|
}
|
|
})
|
|
}
|
|
}
|