mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 08:14:55 +08:00
fix(release):完善当前分发证明与质量门禁
This commit is contained in:
+116
-8
@@ -91,11 +91,17 @@ func fixtureRPCBackend(t *testing.T, root string) *fakeBackend {
|
||||
doctor: &backendrpc.DoctorReport{Healthy: true, Status: "ok"},
|
||||
catalog: catalog,
|
||||
manifest: &backendrpc.ResourceManifestPage{
|
||||
Available: true,
|
||||
ResourceRoot: root,
|
||||
ManifestVersion: 1,
|
||||
TotalEntries: len(manifestEntries),
|
||||
Entries: manifestEntries,
|
||||
Available: true,
|
||||
Channel: "official",
|
||||
ReleaseID: "official-fixture",
|
||||
ResourceRoot: root,
|
||||
ManifestVersion: 1,
|
||||
PublicationIdentity: "fixture-publication-v1",
|
||||
MappingIdentity: "fixture-mapping-v1",
|
||||
ManifestIdentity: "fixture-manifest-v1",
|
||||
Generation: 1,
|
||||
TotalEntries: len(manifestEntries),
|
||||
Entries: manifestEntries,
|
||||
},
|
||||
releaseStatus: &backendrpc.ReleaseStatusReport{
|
||||
Status: "ready",
|
||||
@@ -821,13 +827,16 @@ type fakeBackend struct {
|
||||
statusCalls int
|
||||
doctorCalls int
|
||||
releaseStatusCalls int
|
||||
attestationCalls int
|
||||
status *backendrpc.DaemonStatusReport
|
||||
doctor *backendrpc.DoctorReport
|
||||
releaseStatus *backendrpc.ReleaseStatusReport
|
||||
releaseStatusErr error
|
||||
attestation *backendrpc.DistributionAttestation
|
||||
catalog json.RawMessage
|
||||
resource *backendrpc.ResourceState
|
||||
manifest *backendrpc.ResourceManifestPage
|
||||
manifestParams []backendrpc.ResourceManifestParams
|
||||
daemonLogs *backendrpc.LogsReport
|
||||
taskList *backendrpc.TaskList
|
||||
taskStatus *backendrpc.TaskRecord
|
||||
@@ -858,6 +867,77 @@ func (f *fakeBackend) ReleaseStatus(ctx context.Context) (*backendrpc.ReleaseSta
|
||||
OfficialDistributionReady: true,
|
||||
}, nil
|
||||
}
|
||||
func (f *fakeBackend) ReleaseAttestation(ctx context.Context) (*backendrpc.DistributionAttestation, error) {
|
||||
f.attestationCalls++
|
||||
// Keep the older test fixture controls useful while discovery moves to the
|
||||
// lightweight RPC: releaseStatus still supplies the desired ready/blocked
|
||||
// state unless a test explicitly installs an attestation.
|
||||
if f.attestation != nil {
|
||||
return f.attestation, nil
|
||||
}
|
||||
f.releaseStatusCalls++
|
||||
if f.releaseStatusErr != nil {
|
||||
return nil, f.releaseStatusErr
|
||||
}
|
||||
releaseStatus := f.releaseStatus
|
||||
if releaseStatus == nil {
|
||||
releaseStatus = &backendrpc.ReleaseStatusReport{
|
||||
Status: "ready",
|
||||
StatusCode: "distribution.ready",
|
||||
OfficialDistributionReady: true,
|
||||
}
|
||||
}
|
||||
releaseID := "fixture-release"
|
||||
resourceRoot := ""
|
||||
if f.manifest != nil {
|
||||
releaseID = f.manifest.ReleaseID
|
||||
resourceRoot = f.manifest.ResourceRoot
|
||||
}
|
||||
var catalog struct {
|
||||
Version struct {
|
||||
ID string `json:"id"`
|
||||
ResourceRoot string `json:"resource_root"`
|
||||
} `json:"version"`
|
||||
}
|
||||
if json.Unmarshal(f.catalog, &catalog) == nil {
|
||||
if catalog.Version.ID != "" {
|
||||
releaseID = catalog.Version.ID
|
||||
}
|
||||
if catalog.Version.ResourceRoot != "" {
|
||||
resourceRoot = catalog.Version.ResourceRoot
|
||||
}
|
||||
}
|
||||
if releaseStatus.OfficialCurrentReleaseID != "" {
|
||||
releaseID = releaseStatus.OfficialCurrentReleaseID
|
||||
}
|
||||
integrity := "verified"
|
||||
for _, release := range releaseStatus.Releases {
|
||||
if release.Channel == "official" && release.Current {
|
||||
integrity = release.DistributionIntegrityStatus
|
||||
break
|
||||
}
|
||||
}
|
||||
return &backendrpc.DistributionAttestation{
|
||||
Available: true,
|
||||
Channel: "official",
|
||||
ReleaseID: releaseID,
|
||||
ResourceRoot: resourceRoot,
|
||||
PublicationIdentity: "fixture-publication-v1",
|
||||
MappingIdentity: "fixture-mapping-v1",
|
||||
ManifestIdentity: "fixture-manifest-v1",
|
||||
EntryCount: func() int {
|
||||
if f.manifest == nil {
|
||||
return 0
|
||||
}
|
||||
return len(f.manifest.Entries)
|
||||
}(),
|
||||
IntegrityStatus: integrity,
|
||||
Status: releaseStatus.Status,
|
||||
StatusCode: releaseStatus.StatusCode,
|
||||
Ready: releaseStatus.OfficialDistributionReady,
|
||||
VerificationGeneration: 1,
|
||||
}, nil
|
||||
}
|
||||
func (f *fakeBackend) ResourceState(ctx context.Context) (*backendrpc.ResourceState, error) {
|
||||
if f.resource != nil {
|
||||
return f.resource, nil
|
||||
@@ -867,8 +947,33 @@ func (f *fakeBackend) ResourceState(ctx context.Context) (*backendrpc.ResourceSt
|
||||
func (f *fakeBackend) CatalogStatus(ctx context.Context) (json.RawMessage, error) {
|
||||
return f.catalog, nil
|
||||
}
|
||||
func (f *fakeBackend) ResourceManifest(ctx context.Context, offset int, limit int) (*backendrpc.ResourceManifestPage, error) {
|
||||
return f.manifest, nil
|
||||
func (f *fakeBackend) ResourceManifest(ctx context.Context, params backendrpc.ResourceManifestParams) (*backendrpc.ResourceManifestPage, error) {
|
||||
if f.manifest == nil {
|
||||
return nil, nil
|
||||
}
|
||||
f.manifestParams = append(f.manifestParams, params)
|
||||
page := *f.manifest
|
||||
if page.ReleaseID == "" {
|
||||
page.ReleaseID = params.ReleaseID
|
||||
}
|
||||
if page.ResourceRoot == "" {
|
||||
page.ResourceRoot = f.manifest.ResourceRoot
|
||||
}
|
||||
if page.PublicationIdentity == "" {
|
||||
page.PublicationIdentity = params.ExpectedPublicationIdentity
|
||||
}
|
||||
if page.ManifestIdentity == "" {
|
||||
page.ManifestIdentity = params.ExpectedManifestIdentity
|
||||
}
|
||||
if page.MappingIdentity == "" {
|
||||
page.MappingIdentity = "fixture-mapping-v1"
|
||||
}
|
||||
if page.Generation == 0 {
|
||||
page.Generation = 1
|
||||
}
|
||||
page.Offset = params.Offset
|
||||
page.Limit = params.Limit
|
||||
return &page, nil
|
||||
}
|
||||
func (f *fakeBackend) DaemonLogs(ctx context.Context, tail int) (*backendrpc.LogsReport, error) {
|
||||
if f.daemonLogs != nil {
|
||||
@@ -1762,9 +1867,12 @@ func (p *pollingBackend) ResourceState(ctx context.Context) (*backendrpc.Resourc
|
||||
func (p *pollingBackend) CatalogStatus(ctx context.Context) (json.RawMessage, error) {
|
||||
return nil, errors.New("unexpected catalog call")
|
||||
}
|
||||
func (p *pollingBackend) ResourceManifest(ctx context.Context, offset int, limit int) (*backendrpc.ResourceManifestPage, error) {
|
||||
func (p *pollingBackend) ResourceManifest(ctx context.Context, params backendrpc.ResourceManifestParams) (*backendrpc.ResourceManifestPage, error) {
|
||||
return nil, errors.New("unexpected manifest call")
|
||||
}
|
||||
func (p *pollingBackend) ReleaseAttestation(ctx context.Context) (*backendrpc.DistributionAttestation, error) {
|
||||
return nil, errors.New("unexpected attestation call")
|
||||
}
|
||||
|
||||
func TestStartRefreshLoopPollsBackend(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
|
||||
Reference in New Issue
Block a user