@@ -44,26 +44,11 @@ func TestGetProviderConfigSpec(t *testing.T) {
4444 if len (vllmCap .ServingModes ) != 2 {
4545 t .Fatalf ("expected vllm to support 2 serving modes, got %d" , len (vllmCap .ServingModes ))
4646 }
47- expectedVLLMFormats := []airunwayv1alpha1.APIFormat {
47+ assertAPIFormats ( t , "vllm" , vllmCap . APIFormats , []airunwayv1alpha1.APIFormat {
4848 airunwayv1alpha1 .APIFormatOpenAIChat ,
4949 airunwayv1alpha1 .APIFormatOpenAIResponses ,
5050 airunwayv1alpha1 .APIFormatAnthropicMessages ,
51- }
52- if len (vllmCap .APIFormats ) != len (expectedVLLMFormats ) {
53- t .Fatalf ("expected vllm to support %d API formats, got %d" , len (expectedVLLMFormats ), len (vllmCap .APIFormats ))
54- }
55- for _ , expected := range expectedVLLMFormats {
56- found := false
57- for _ , actual := range vllmCap .APIFormats {
58- if actual == expected {
59- found = true
60- break
61- }
62- }
63- if ! found {
64- t .Errorf ("expected vllm to support API format %s" , expected )
65- }
66- }
51+ })
6752
6853 sglangCap := spec .Capabilities .GetEngineCapability (airunwayv1alpha1 .EngineTypeSGLang )
6954 if sglangCap == nil {
@@ -75,25 +60,10 @@ func TestGetProviderConfigSpec(t *testing.T) {
7560 if len (sglangCap .ServingModes ) != 2 {
7661 t .Fatalf ("expected sglang to support 2 serving modes, got %d" , len (sglangCap .ServingModes ))
7762 }
78- expectedSGLangFormats := []airunwayv1alpha1.APIFormat {
63+ assertAPIFormats ( t , "sglang" , sglangCap . APIFormats , []airunwayv1alpha1.APIFormat {
7964 airunwayv1alpha1 .APIFormatOpenAIChat ,
8065 airunwayv1alpha1 .APIFormatAnthropicMessages ,
81- }
82- if len (sglangCap .APIFormats ) != len (expectedSGLangFormats ) {
83- t .Fatalf ("expected sglang to support %d API formats, got %d" , len (expectedSGLangFormats ), len (sglangCap .APIFormats ))
84- }
85- for _ , expected := range expectedSGLangFormats {
86- found := false
87- for _ , actual := range sglangCap .APIFormats {
88- if actual == expected {
89- found = true
90- break
91- }
92- }
93- if ! found {
94- t .Errorf ("expected sglang to support API format %s" , expected )
95- }
96- }
66+ })
9767
9868 trtllmCap := spec .Capabilities .GetEngineCapability (airunwayv1alpha1 .EngineTypeTRTLLM )
9969 if trtllmCap == nil {
@@ -105,25 +75,10 @@ func TestGetProviderConfigSpec(t *testing.T) {
10575 if len (trtllmCap .ServingModes ) != 1 || trtllmCap .ServingModes [0 ] != airunwayv1alpha1 .ServingModeAggregated {
10676 t .Errorf ("expected trtllm to support only aggregated serving mode" )
10777 }
108- expectedTRTLLMFormats := []airunwayv1alpha1.APIFormat {
78+ assertAPIFormats ( t , "trtllm" , trtllmCap . APIFormats , []airunwayv1alpha1.APIFormat {
10979 airunwayv1alpha1 .APIFormatOpenAIChat ,
11080 airunwayv1alpha1 .APIFormatOpenAIResponses ,
111- }
112- if len (trtllmCap .APIFormats ) != len (expectedTRTLLMFormats ) {
113- t .Fatalf ("expected trtllm to support %d API formats, got %d" , len (expectedTRTLLMFormats ), len (trtllmCap .APIFormats ))
114- }
115- for _ , expected := range expectedTRTLLMFormats {
116- found := false
117- for _ , actual := range trtllmCap .APIFormats {
118- if actual == expected {
119- found = true
120- break
121- }
122- }
123- if ! found {
124- t .Errorf ("expected trtllm to support API format %s" , expected )
125- }
126- }
81+ })
12782
12883 if len (spec .SelectionRules ) != 4 {
12984 t .Fatalf ("expected 4 selection rules, got %d" , len (spec .SelectionRules ))
@@ -372,3 +327,22 @@ func TestUpdateStatusNotFound(t *testing.T) {
372327 t .Fatal ("expected error when config not found" )
373328 }
374329}
330+
331+ func assertAPIFormats (t * testing.T , engine string , got , expected []airunwayv1alpha1.APIFormat ) {
332+ t .Helper ()
333+ if len (got ) != len (expected ) {
334+ t .Fatalf ("expected %s to support %d API formats, got %d: %v" , engine , len (expected ), len (got ), got )
335+ }
336+ for _ , e := range expected {
337+ found := false
338+ for _ , a := range got {
339+ if a == e {
340+ found = true
341+ break
342+ }
343+ }
344+ if ! found {
345+ t .Errorf ("expected %s to support API format %s" , engine , e )
346+ }
347+ }
348+ }
0 commit comments