mirror of
https://github.com/alibaba/higress.git
synced 2026-05-25 05:07:26 +08:00
test(ai-proxy): expand wasm integration tests, coverage, and provider matrix (#3790)
Signed-off-by: jingze <daijingze.djz@alibaba-inc.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateHeaders(t *testing.T) {
|
||||
h := CreateHeaders("Content-Type", "application/json", ":status", "200")
|
||||
if len(h) != 2 {
|
||||
t.Fatalf("len=%d", len(h))
|
||||
}
|
||||
if h[0][0] != "Content-Type" || h[0][1] != "application/json" {
|
||||
t.Fatalf("first pair: %v", h[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeaderToSliceAndSliceToHeader_roundTrip(t *testing.T) {
|
||||
src := make(http.Header)
|
||||
src.Set("A", "1")
|
||||
src.Add("A", "2")
|
||||
src.Set("B", "3")
|
||||
|
||||
slice := HeaderToSlice(src)
|
||||
round := SliceToHeader(slice)
|
||||
|
||||
if !reflect.DeepEqual(src["A"], round["A"]) || !reflect.DeepEqual(src["B"], round["B"]) {
|
||||
t.Fatalf("roundTrip mismatch: %#v vs %#v", src, round)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverwriteRequestPathHeader(t *testing.T) {
|
||||
h := make(http.Header)
|
||||
OverwriteRequestPathHeader(h, "/v1/chat/completions")
|
||||
if h.Get(":path") != "/v1/chat/completions" {
|
||||
t.Fatalf("path=%q", h.Get(":path"))
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,33 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMatchStatus(t *testing.T) {
|
||||
defaultRetryPatterns := []string{"4.*", "5.*"}
|
||||
tests := []struct {
|
||||
name string
|
||||
status string
|
||||
patterns []string
|
||||
want bool
|
||||
}{
|
||||
{"200_no_match", "200", defaultRetryPatterns, false},
|
||||
{"201_no_match", "201", defaultRetryPatterns, false},
|
||||
{"429_matches_4xx", "429", defaultRetryPatterns, true},
|
||||
{"400_matches_4xx", "400", defaultRetryPatterns, true},
|
||||
{"503_matches_5xx", "503", defaultRetryPatterns, true},
|
||||
{"500_matches_5xx", "500", defaultRetryPatterns, true},
|
||||
{"exact_503_pattern", "503", []string{"503"}, true},
|
||||
{"exact_503_miss", "502", []string{"503"}, false},
|
||||
{"empty_patterns", "500", []string{}, false},
|
||||
{"empty_status", "", defaultRetryPatterns, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := MatchStatus(tt.status, tt.patterns)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeUnicodeEscapes(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user