test(integration): reorganize test structure and add runner script

- Move integration tests and mock upstream resources from `integration/` to `test/` directory.
- Add `test/integration.sh` script to orchestrate environment setup and test execution.
- Update build context in `docker-compose.integration.yml` to match new structure.
- Add documentation for local development and integration testing workflows in README.
This commit is contained in:
zenfun
2025-12-02 15:56:17 +08:00
parent a0f13d55c1
commit d147f3ab04
8 changed files with 41 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
package main
import (
"encoding/json"
"log"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})
mux.HandleFunc("/v1/chat/completions", func(w http.ResponseWriter, r *http.Request) {
resp := map[string]interface{}{
"id": "mock-completion",
"object": "chat.completion",
"choices": []map[string]interface{}{
{
"index": 0,
"message": map[string]string{
"role": "assistant",
"content": "hello from mock",
},
"finish_reason": "stop",
},
},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(resp)
})
mux.HandleFunc("/v1/models", func(w http.ResponseWriter, r *http.Request) {
resp := map[string]interface{}{
"object": "list",
"data": []map[string]string{
{"id": "mock-model", "object": "model", "owned_by": "mock"},
},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(resp)
})
log.Println("mock-upstream listening on :8082")
if err := http.ListenAndServe(":8082", mux); err != nil {
log.Fatalf("mock-upstream failed: %v", err)
}
}