mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test: Increase test coverage on auditable resources (#7038)
* test: Increase test coverage on auditable resources When adding a new audit resource, we also need to add it to the function switch statements. This is a likely mistake, now a unit test will check this for you
This commit is contained in:
@@ -78,6 +78,8 @@ func ResourceTarget[T Auditable](tgt T) string {
|
||||
return ""
|
||||
case database.License:
|
||||
return strconv.Itoa(int(typed.ID))
|
||||
case database.WorkspaceProxy:
|
||||
return typed.Name
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown resource %T", tgt))
|
||||
}
|
||||
@@ -103,13 +105,15 @@ func ResourceID[T Auditable](tgt T) uuid.UUID {
|
||||
return typed.UserID
|
||||
case database.License:
|
||||
return typed.UUID
|
||||
case database.WorkspaceProxy:
|
||||
return typed.ID
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown resource %T", tgt))
|
||||
}
|
||||
}
|
||||
|
||||
func ResourceType[T Auditable](tgt T) database.ResourceType {
|
||||
switch any(tgt).(type) {
|
||||
switch typed := any(tgt).(type) {
|
||||
case database.Template:
|
||||
return database.ResourceTypeTemplate
|
||||
case database.TemplateVersion:
|
||||
@@ -128,8 +132,10 @@ func ResourceType[T Auditable](tgt T) database.ResourceType {
|
||||
return database.ResourceTypeApiKey
|
||||
case database.License:
|
||||
return database.ResourceTypeLicense
|
||||
case database.WorkspaceProxy:
|
||||
return database.ResourceTypeWorkspaceProxy
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown resource %T", tgt))
|
||||
panic(fmt.Sprintf("unknown resource %T", typed))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user