119 lines
2.6 KiB
Go
119 lines
2.6 KiB
Go
package lang
|
|
|
|
// Server and entity comparison functions for parser tests
|
|
|
|
func serverEqual(got, want Server) bool {
|
|
if got.Name != want.Name {
|
|
return false
|
|
}
|
|
|
|
if len(got.Settings) != len(want.Settings) {
|
|
return false
|
|
}
|
|
|
|
for i, setting := range got.Settings {
|
|
if !serverSettingEqual(setting, want.Settings[i]) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func serverSettingEqual(got, want ServerSetting) bool {
|
|
return configValueEqual(got.Host, want.Host) &&
|
|
intValueEqual(got.Port, want.Port) &&
|
|
configValueEqual(got.DatabaseURL, want.DatabaseURL) &&
|
|
configValueEqual(got.APIKey, want.APIKey) &&
|
|
configValueEqual(got.SSLCert, want.SSLCert) &&
|
|
configValueEqual(got.SSLKey, want.SSLKey)
|
|
}
|
|
|
|
func configValueEqual(got, want *ConfigValue) bool {
|
|
if got == nil && want == nil {
|
|
return true
|
|
}
|
|
if got == nil || want == nil {
|
|
return false
|
|
}
|
|
|
|
// Check literal values
|
|
if got.Literal != nil && want.Literal != nil {
|
|
return *got.Literal == *want.Literal
|
|
}
|
|
if got.Literal != nil || want.Literal != nil {
|
|
return false
|
|
}
|
|
|
|
// Check environment variables
|
|
if got.EnvVar != nil && want.EnvVar != nil {
|
|
return envVarEqual(*got.EnvVar, *want.EnvVar)
|
|
}
|
|
return got.EnvVar == nil && want.EnvVar == nil
|
|
}
|
|
|
|
func intValueEqual(got, want *IntValue) bool {
|
|
if got == nil && want == nil {
|
|
return true
|
|
}
|
|
if got == nil || want == nil {
|
|
return false
|
|
}
|
|
|
|
// Check literal values
|
|
if got.Literal != nil && want.Literal != nil {
|
|
return *got.Literal == *want.Literal
|
|
}
|
|
if got.Literal != nil || want.Literal != nil {
|
|
return false
|
|
}
|
|
|
|
// Check environment variables
|
|
if got.EnvVar != nil && want.EnvVar != nil {
|
|
return envVarEqual(*got.EnvVar, *want.EnvVar)
|
|
}
|
|
return got.EnvVar == nil && want.EnvVar == nil
|
|
}
|
|
|
|
func envVarEqual(got, want EnvVar) bool {
|
|
if got.Name != want.Name {
|
|
return false
|
|
}
|
|
if got.Required != want.Required {
|
|
return false
|
|
}
|
|
return stringPtrEqual(got.Default, want.Default)
|
|
}
|
|
|
|
func entityEqual(got, want Entity) bool {
|
|
if got.Name != want.Name {
|
|
return false
|
|
}
|
|
|
|
if !stringPtrEqual(got.Description, want.Description) {
|
|
return false
|
|
}
|
|
|
|
if len(got.Fields) != len(want.Fields) {
|
|
return false
|
|
}
|
|
|
|
for i, field := range got.Fields {
|
|
if !fieldEqual(field, want.Fields[i]) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func endpointEqual(got, want Endpoint) bool {
|
|
return got.Method == want.Method &&
|
|
got.Path == want.Path &&
|
|
stringPtrEqual(got.Entity, want.Entity) &&
|
|
stringPtrEqual(got.Description, want.Description) &&
|
|
got.Auth == want.Auth &&
|
|
stringPtrEqual(got.CustomLogic, want.CustomLogic)
|
|
// TODO: Add params and response comparison if needed
|
|
}
|