55 "net/http"
66 "net/http/httptest"
77 "testing"
8+ "time"
89
910 "github.com/openai/openai-go/v2"
1011 "github.com/openai/openai-go/v2/packages/pagination"
@@ -13,6 +14,7 @@ import (
1314 "github.com/opendatahub-io/maas-billing/maas-api/test/fixtures"
1415 "github.com/stretchr/testify/assert"
1516 "github.com/stretchr/testify/require"
17+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1618 "knative.dev/pkg/apis"
1719)
1820
@@ -51,6 +53,33 @@ func TestListingModels(t *testing.T) {
5153 }
5254 llmInferenceServices := fixtures .CreateLLMInferenceServices (llmTestScenarios ... )
5355
56+ //Add a model where .spec.model.name is unset; should default to metadata.name
57+ unsetSpecModelName := "unset-spec-model-name"
58+ unsetSpecModelNameNamespace := fixtures .TestNamespace
59+
60+ unsetSpecModelNameISVC := unstructured.Unstructured {
61+ Object : map [string ]any {
62+ "apiVersion" : "serving.kserve.io/v1beta1" ,
63+ "kind" : "InferenceService" ,
64+ "metadata" : map [string ]any {
65+ "name" : unsetSpecModelName ,
66+ "namespace" : unsetSpecModelNameNamespace ,
67+ "creationTimestamp" : time .Now ().UTC ().Format (time .RFC3339 ),
68+ },
69+ "spec" : map [string ]any {
70+ "model" : map [string ]any {
71+ //left out the "name" key
72+ },
73+ },
74+ "status" : map [string ]any {
75+ "url" : "http://" + unsetSpecModelName + "." + unsetSpecModelNameNamespace + ".acme.com/v1" ,
76+ },
77+ },
78+ }
79+
80+ // Append the model to the objects used by the fake server
81+ llmInferenceServices = append (llmInferenceServices , unsetSpecModelNameISVC )
82+
5483 config := fixtures.TestServerConfig {
5584 Objects : llmInferenceServices ,
5685 }
@@ -102,6 +131,20 @@ func TestListingModels(t *testing.T) {
102131 })
103132 }
104133
134+ //After loop that builds testCases from llmTestScenarios completes, append an expectedModel for the unsetSpecModelName case:
135+ testCases = append (testCases , expectedModel {
136+ name : unsetSpecModelName , // key used to pull from modelsByName
137+ expectedModel : models.Model {
138+ Model : openai.Model {
139+ ID : unsetSpecModelName , // should equal metadata.name because spec.model.name is missing
140+ Object : "model" ,
141+ OwnedBy : unsetSpecModelNameNamespace ,
142+ },
143+ URL : mustParseURL ("http://" + unsetSpecModelName + "." + unsetSpecModelNameNamespace + ".acme.com/v1" ),
144+ Ready : false ,
145+ },
146+ })
147+
105148 for _ , tc := range testCases {
106149 t .Run (tc .name , func (t * testing.T ) {
107150 actualModel , exists := modelsByName [tc .name ]
0 commit comments