Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
//go:build unit
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type updatingProxyRepoStub struct {
|
||||
*proxyRepoStub
|
||||
proxy *Proxy
|
||||
updateCalls int
|
||||
}
|
||||
|
||||
func (s *updatingProxyRepoStub) GetByID(context.Context, int64) (*Proxy, error) {
|
||||
copy := *s.proxy
|
||||
return ©, nil
|
||||
}
|
||||
|
||||
func (s *updatingProxyRepoStub) Update(_ context.Context, proxy *Proxy) error {
|
||||
s.updateCalls++
|
||||
copy := *proxy
|
||||
s.proxy = ©
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestBothProxyUpdateServicesUseRepositoryUpdateBoundary(t *testing.T) {
|
||||
t.Run("ProxyService", func(t *testing.T) {
|
||||
repo := &updatingProxyRepoStub{
|
||||
proxyRepoStub: &proxyRepoStub{},
|
||||
proxy: &Proxy{ID: 9, Protocol: "http", Host: "old.example", Port: 8080, Status: StatusActive},
|
||||
}
|
||||
svc := NewProxyService(repo)
|
||||
host := "new.example"
|
||||
|
||||
_, err := svc.Update(context.Background(), 9, UpdateProxyRequest{Host: &host})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, repo.updateCalls)
|
||||
require.Equal(t, host, repo.proxy.Host)
|
||||
})
|
||||
|
||||
t.Run("adminService", func(t *testing.T) {
|
||||
repo := &updatingProxyRepoStub{
|
||||
proxyRepoStub: &proxyRepoStub{},
|
||||
proxy: &Proxy{
|
||||
ID: 9,
|
||||
Protocol: "http",
|
||||
Host: "old.example",
|
||||
Port: 8080,
|
||||
Status: StatusActive,
|
||||
FallbackMode: FallbackModeNone,
|
||||
ExpiryWarnDays: 7,
|
||||
},
|
||||
}
|
||||
svc := &adminServiceImpl{proxyRepo: repo}
|
||||
|
||||
_, err := svc.UpdateProxy(context.Background(), 9, &UpdateProxyInput{
|
||||
Host: "new.example",
|
||||
FallbackMode: FallbackModeNone,
|
||||
ExpiryWarnDays: 7,
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, repo.updateCalls)
|
||||
require.Equal(t, "new.example", repo.proxy.Host)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user