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 3852e37 commit 187bf1d
Show file tree
Hide file tree
Showing 5 changed files with 3,523 additions and 2,367 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,12 +7,23 @@ 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)

expected := hubAuthConfig()
if !reflect.DeepEqual(expected, converted) {
t.Error(cmp.Diff(expected, converted))
}
}

func TestConvertFrom(t *testing.T) {
converted := &AuthConfig{}
converted.ConvertFrom(hubAuthConfig())

sort.Slice(converted.Spec.Identity, func(i, j int) bool {
return converted.Spec.Identity[i].Name < converted.Spec.Identity[j].Name
Expand Down Expand Up @@ -48,23 +59,14 @@ func TestConvertTo(t *testing.T) {
return converted.Spec.DenyWith.Unauthorized.Headers[i].Name < converted.Spec.DenyWith.Unauthorized.Headers[j].Name
})

expected := hubAuthConfig()
if !reflect.DeepEqual(expected, converted) {
t.Error(cmp.Diff(expected, converted))
}
}

func TestConvertFrom(t *testing.T) {
converted := &AuthConfig{}
converted.ConvertFrom(hubAuthConfig())
expected := authConfig()
if !reflect.DeepEqual(expected, converted) {
t.Error(cmp.Diff(expected, converted))
}
}

func authConfig() *AuthConfig {
authConfig := &AuthConfig{}
func hubAuthConfig() *v1beta2.AuthConfig {
authConfig := &v1beta2.AuthConfig{}
err := json.Unmarshal([]byte(`
{
"metadata": {
Expand Down Expand Up @@ -477,8 +479,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 187bf1d

Please sign in to comment.