Skip to content

Commit

Permalink
Updated test
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Aug 26, 2024
1 parent 92fd1aa commit 4f83875
Show file tree
Hide file tree
Showing 5 changed files with 3,534 additions and 2,379 deletions.
1 change: 1 addition & 0 deletions api/v1beta1/auth_config_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1beta1

import (
"encoding/json"

"github.com/kuadrant/authorino/api/v1beta2"
"github.com/kuadrant/authorino/pkg/utils"
"github.com/tidwall/gjson"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1beta2
package v1beta1

import (
"encoding/json"
Expand All @@ -7,45 +7,46 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/kuadrant/authorino/api/v1beta1"
"github.com/kuadrant/authorino/api/v1beta2"
)

func TestConvertTo(t *testing.T) {
converted := &v1beta1.AuthConfig{}
authConfig().ConvertTo(converted)
converted := &v1beta2.AuthConfig{}
config := authConfig()
config.ConvertTo(converted)

sort.Slice(converted.Spec.Identity, func(i, j int) bool {
return converted.Spec.Identity[i].Name < converted.Spec.Identity[j].Name
sort.Slice(config.Spec.Identity, func(i, j int) bool {
return config.Spec.Identity[i].Name < config.Spec.Identity[j].Name
})
sort.Slice(converted.Spec.Metadata, func(i, j int) bool {
return converted.Spec.Metadata[i].Name < converted.Spec.Metadata[j].Name
sort.Slice(config.Spec.Metadata, func(i, j int) bool {
return config.Spec.Metadata[i].Name < config.Spec.Metadata[j].Name
})
sort.Slice(converted.Spec.Authorization, func(i, j int) bool {
return converted.Spec.Authorization[i].Name < converted.Spec.Authorization[j].Name
sort.Slice(config.Spec.Authorization, func(i, j int) bool {
return config.Spec.Authorization[i].Name < config.Spec.Authorization[j].Name
})
sort.Slice(converted.Spec.Response, func(i, j int) bool {
return converted.Spec.Response[i].Name < converted.Spec.Response[j].Name
sort.Slice(config.Spec.Response, func(i, j int) bool {
return config.Spec.Response[i].Name < config.Spec.Response[j].Name
})
for idx := range converted.Spec.Response {
if converted.Spec.Response[idx].Wristband != nil {
sort.Slice(converted.Spec.Response[idx].Wristband.CustomClaims, func(i, j int) bool {
return converted.Spec.Response[idx].Wristband.CustomClaims[i].Name < converted.Spec.Response[idx].Wristband.CustomClaims[j].Name
for idx := range config.Spec.Response {
if config.Spec.Response[idx].Wristband != nil {
sort.Slice(config.Spec.Response[idx].Wristband.CustomClaims, func(i, j int) bool {
return config.Spec.Response[idx].Wristband.CustomClaims[i].Name < config.Spec.Response[idx].Wristband.CustomClaims[j].Name
})
}
if converted.Spec.Response[idx].JSON != nil {
sort.Slice(converted.Spec.Response[idx].JSON.Properties, func(i, j int) bool {
return converted.Spec.Response[idx].JSON.Properties[i].Name < converted.Spec.Response[idx].JSON.Properties[j].Name
if config.Spec.Response[idx].JSON != nil {
sort.Slice(config.Spec.Response[idx].JSON.Properties, func(i, j int) bool {
return config.Spec.Response[idx].JSON.Properties[i].Name < config.Spec.Response[idx].JSON.Properties[j].Name
})
}
}
sort.Slice(converted.Spec.Callbacks, func(i, j int) bool {
return converted.Spec.Callbacks[i].Name < converted.Spec.Callbacks[j].Name
sort.Slice(config.Spec.Callbacks, func(i, j int) bool {
return config.Spec.Callbacks[i].Name < config.Spec.Callbacks[j].Name
})
sort.Slice(converted.Spec.DenyWith.Unauthenticated.Headers, func(i, j int) bool {
return converted.Spec.DenyWith.Unauthenticated.Headers[i].Name < converted.Spec.DenyWith.Unauthenticated.Headers[j].Name
sort.Slice(config.Spec.DenyWith.Unauthenticated.Headers, func(i, j int) bool {
return config.Spec.DenyWith.Unauthenticated.Headers[i].Name < config.Spec.DenyWith.Unauthenticated.Headers[j].Name
})
sort.Slice(converted.Spec.DenyWith.Unauthorized.Headers, func(i, j int) bool {
return converted.Spec.DenyWith.Unauthorized.Headers[i].Name < converted.Spec.DenyWith.Unauthorized.Headers[j].Name
sort.Slice(config.Spec.DenyWith.Unauthorized.Headers, func(i, j int) bool {
return config.Spec.DenyWith.Unauthorized.Headers[i].Name < config.Spec.DenyWith.Unauthorized.Headers[j].Name
})

expected := hubAuthConfig()
Expand All @@ -63,8 +64,8 @@ func TestConvertFrom(t *testing.T) {
}
}

func authConfig() *AuthConfig {
authConfig := &AuthConfig{}
func hubAuthConfig() *v1beta2.AuthConfig {
authConfig := &v1beta2.AuthConfig{}
err := json.Unmarshal([]byte(`
{
"metadata": {
Expand Down Expand Up @@ -477,8 +478,8 @@ func authConfig() *AuthConfig {
return authConfig
}

func hubAuthConfig() *v1beta1.AuthConfig {
authConfig := &v1beta1.AuthConfig{}
func authConfig() *AuthConfig {
authConfig := &AuthConfig{}
err := json.Unmarshal([]byte(`
{
"metadata": {
Expand Down
Loading

0 comments on commit 4f83875

Please sign in to comment.