Add Go service/handler tests for API contract parity (#16905)

This commit is contained in:
euvre
2026-07-20 20:02:41 +08:00
committed by GitHub
parent 2f7c2eb53c
commit f45f03a016
46 changed files with 1553 additions and 214 deletions

View File

@@ -68,7 +68,7 @@ func (s *DocumentService) DownloadDocument(datasetID, docID string) (*DownloadDo
}
doc, err := s.documentDAO.GetByID(docID)
if err != nil || doc.KbID != datasetID {
return nil, fmt.Errorf("The dataset not own the document %s.", docID)
return nil, fmt.Errorf("Document not found!")
}
bucket, name, err := s.GetDocumentStorageAddress(doc)
if err != nil {

View File

@@ -232,8 +232,13 @@ func (s *DocumentService) validateDatasetDocumentUpdate(datasetID, documentID, u
if present["token_count"] && req.TokenCount != nil && *req.TokenCount != 0 && *req.TokenCount != doc.TokenNum {
return common.CodeDataError, errors.New("Can't change `token_count`.")
}
if present["progress"] && req.Progress != nil && *req.Progress != 0 && math.Abs(*req.Progress-doc.Progress) > 1e-9 {
return common.CodeDataError, errors.New("Can't change `progress`.")
if present["progress"] && req.Progress != nil {
if *req.Progress > 1 {
return common.CodeDataError, fmt.Errorf("Field: <progress> - Message: <Input should be less than or equal to 1> - Value: <%v>", *req.Progress)
}
if *req.Progress != 0 && math.Abs(*req.Progress-doc.Progress) > 1e-9 {
return common.CodeDataError, errors.New("Can't change `progress`.")
}
}
if present["enabled"] {

View File

@@ -288,7 +288,7 @@ func (s *DocumentService) validateDocsInDataset(docIDs []string, datasetID strin
}
}
if len(invalid) > 0 {
return nil, fmt.Errorf("these documents do not belong to dataset %s: %v", datasetID, invalid)
return nil, fmt.Errorf("These documents do not belong to dataset %s: %v", datasetID, invalid)
}
return docs, nil
}