mirror of
https://github.com/rancher/steve.git
synced 2025-09-24 21:08:03 +00:00
Add an attribute observedgeneration (#714)
* Add an attribute observedgeneration * add unit tests
This commit is contained in:
committed by
GitHub
parent
a020084518
commit
6946ffe8aa
@@ -77,5 +77,27 @@ func forVersion(group, kind string, version v1.CustomResourceDefinitionVersion,
|
||||
}
|
||||
if version.Schema != nil && version.Schema.OpenAPIV3Schema != nil {
|
||||
schema.Description = version.Schema.OpenAPIV3Schema.Description
|
||||
|
||||
if hasObservedGeneration(version.Schema.OpenAPIV3Schema) {
|
||||
schemas.SetHasObservedGeneration(schema.Schema, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hasObservedGeneration(schema *v1.JSONSchemaProps) bool {
|
||||
if schema == nil {
|
||||
return false
|
||||
}
|
||||
if schema.Properties == nil {
|
||||
return false
|
||||
}
|
||||
status, ok := schema.Properties["status"]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if status.Properties == nil {
|
||||
return false
|
||||
}
|
||||
_, found := status.Properties["observedGeneration"]
|
||||
return found
|
||||
}
|
||||
|
@@ -306,3 +306,73 @@ func TestAddCustomResources(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestHasObservedGeneration(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
schema *v1.JSONSchemaProps
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "nil schema",
|
||||
schema: nil,
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "nil properties",
|
||||
schema: &v1.JSONSchemaProps{},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "no status property",
|
||||
schema: &v1.JSONSchemaProps{
|
||||
Properties: map[string]v1.JSONSchemaProps{
|
||||
"foo": {},
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "status property without properties",
|
||||
schema: &v1.JSONSchemaProps{
|
||||
Properties: map[string]v1.JSONSchemaProps{
|
||||
"status": {},
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "status property with properties but no observedGeneration",
|
||||
schema: &v1.JSONSchemaProps{
|
||||
Properties: map[string]v1.JSONSchemaProps{
|
||||
"status": {
|
||||
Properties: map[string]v1.JSONSchemaProps{
|
||||
"foo": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "status property with observedGeneration",
|
||||
schema: &v1.JSONSchemaProps{
|
||||
Properties: map[string]v1.JSONSchemaProps{
|
||||
"status": {
|
||||
Properties: map[string]v1.JSONSchemaProps{
|
||||
"observedGeneration": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := hasObservedGeneration(tt.schema)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user