Add singular/plural titles to config.SupportedResources()

This commit is contained in:
Pieter Noordhuis 2024-10-17 15:58:04 +02:00
parent 13049a555b
commit 2c8bb75bc4
No known key found for this signature in database
GPG Key ID: 12ACCCC104CF2930
2 changed files with 65 additions and 16 deletions

View File

@ -130,20 +130,71 @@ func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error)
} }
type ResourceDescription struct { type ResourceDescription struct {
// Singular and plural name when used to refer to the configuration.
SingularName string SingularName string
PluralName string
// Singular and plural title when used in summaries / terminal UI.
SingularTitle string
PluralTitle string
} }
// The keys of the map corresponds to the resource key in the bundle configuration. // The keys of the map corresponds to the resource key in the bundle configuration.
func SupportedResources() map[string]ResourceDescription { func SupportedResources() map[string]ResourceDescription {
return map[string]ResourceDescription{ return map[string]ResourceDescription{
"jobs": {SingularName: "job"}, "jobs": {
"pipelines": {SingularName: "pipeline"}, SingularName: "job",
"models": {SingularName: "model"}, PluralName: "jobs",
"experiments": {SingularName: "experiment"}, SingularTitle: "Job",
"model_serving_endpoints": {SingularName: "model_serving_endpoint"}, PluralTitle: "Jobs",
"registered_models": {SingularName: "registered_model"}, },
"quality_monitors": {SingularName: "quality_monitor"}, "pipelines": {
"schemas": {SingularName: "schema"}, SingularName: "pipeline",
"clusters": {SingularName: "cluster"}, PluralName: "pipelines",
SingularTitle: "Pipeline",
PluralTitle: "Pipelines",
},
"models": {
SingularName: "model",
PluralName: "models",
SingularTitle: "Model",
PluralTitle: "Models",
},
"experiments": {
SingularName: "experiment",
PluralName: "experiments",
SingularTitle: "Experiment",
PluralTitle: "Experiments",
},
"model_serving_endpoints": {
SingularName: "model_serving_endpoint",
PluralName: "model_serving_endpoints",
SingularTitle: "Model Serving Endpoint",
PluralTitle: "Model Serving Endpoints",
},
"registered_models": {
SingularName: "registered_model",
PluralName: "registered_models",
SingularTitle: "Registered Model",
PluralTitle: "Registered Models",
},
"quality_monitors": {
SingularName: "quality_monitor",
PluralName: "quality_monitors",
SingularTitle: "Quality Monitor",
PluralTitle: "Quality Monitors",
},
"schemas": {
SingularName: "schema",
PluralName: "schemas",
SingularTitle: "Schema",
PluralTitle: "Schemas",
},
"clusters": {
SingularName: "cluster",
PluralName: "clusters",
SingularTitle: "Cluster",
PluralTitle: "Clusters",
},
} }
} }

View File

@ -83,16 +83,14 @@ func TestResourcesAllResourcesCompleteness(t *testing.T) {
} }
func TestSupportedResources(t *testing.T) { func TestSupportedResources(t *testing.T) {
expected := map[string]ResourceDescription{} // Please add your resource to the SupportedResources() function in resources.go if you add a new resource.
actual := SupportedResources()
typ := reflect.TypeOf(Resources{}) typ := reflect.TypeOf(Resources{})
for i := 0; i < typ.NumField(); i++ { for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i) field := typ.Field(i)
jsonTags := strings.Split(field.Tag.Get("json"), ",") jsonTags := strings.Split(field.Tag.Get("json"), ",")
singularName := strings.TrimSuffix(jsonTags[0], "s") pluralName := jsonTags[0]
expected[jsonTags[0]] = ResourceDescription{SingularName: singularName} assert.Equal(t, actual[pluralName].PluralName, pluralName)
} }
// Please add your resource to the SupportedResources() function in resources.go
// if you are adding a new resource.
assert.Equal(t, expected, SupportedResources())
} }