Skip to content

Commit

Permalink
test: update to fit the updated code
Browse files Browse the repository at this point in the history
This change update the tests to fit the changes (now depending on
Identity from platform-go-middlewares). Additionally, it is used pointy
methods to generate pointer to values.

Signed-off-by: Alejandro Visiedo <[email protected]>
  • Loading branch information
avisiedo committed Jan 5, 2024
1 parent 6cf4d46 commit b003581
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 160 deletions.
17 changes: 9 additions & 8 deletions associate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
"github.com/redhatinsights/platform-go-middlewares/identity"
"go.openly.dev/pointy"
)

func TestNewAssociate(t *testing.T) {
Expand All @@ -33,9 +34,9 @@ func TestNewAssociate(t *testing.T) {
description: "partial template",
seed: 100,
input: Associate{
Email: ptrstring("[email protected]"),
GivenName: ptrstring("John"),
Surname: ptrstring("Smith"),
Email: pointy.String("[email protected]"),
GivenName: pointy.String("John"),
Surname: pointy.String("Smith"),
},
want: &identity.Associate{
Email: "[email protected]",
Expand All @@ -49,11 +50,11 @@ func TestNewAssociate(t *testing.T) {
description: "full template",
seed: 100,
input: Associate{
Email: ptrstring("[email protected]"),
GivenName: ptrstring("John"),
RHatUUID: ptrstring("6208f878-b405-498e-979f-e85cd68d8a18"),
Role: ptrslicestring([]string{"a", "b"}),
Surname: ptrstring("Smith"),
Email: pointy.String("[email protected]"),
GivenName: pointy.String("John"),
RHatUUID: pointy.String("6208f878-b405-498e-979f-e85cd68d8a18"),
Role: &[]string{"a", "b"},
Surname: pointy.String("Smith"),
},
want: &identity.Associate{
Email: "[email protected]",
Expand Down
10 changes: 5 additions & 5 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ExampleAssociate() {
panic(err)
}
fmt.Println(string(data))
//Output: {"identity":{"associate":{"email":"[email protected]","givenName":"Cameron","rhatUUID":"00e3c758-1d7d-4ecd-98a2-997157e2d05c","Role":null,"surname":"Swift"},"auth_type":"basic-auth","employee_account_number":"02299","org_id":"41123","type":"Associate"}}
//Output: {"identity":{"employee_account_number":"02299","org_id":"41123","internal":{"org_id":""},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"[email protected]","givenName":"Cameron","rhatUUID":"00e3c758-1d7d-4ecd-98a2-997157e2d05c","surname":"Swift"},"x509":{"subject_dn":"","issuer_dn":""},"type":"Associate","auth_type":"basic-auth"}}
}

func ExampleInternal() {
Expand All @@ -32,7 +32,7 @@ func ExampleInternal() {
panic(err)
}
fmt.Println(string(data))
//Output: {"identity":{"auth_type":"basic-auth","internal":{"auth_time":-2978345425851500500,"cross_access":false,"org_id":"08321"},"org_id":"03797","type":"Internal"}}
//Output: {"identity":{"org_id":"03797","internal":{"org_id":"08321","auth_time":-2978345600000000000},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"type":"Internal","auth_type":"basic-auth"}}
}

func ExampleSystem() {
Expand All @@ -46,7 +46,7 @@ func ExampleSystem() {
panic(err)
}
fmt.Println(string(data))
//Output: {"identity":{"account_number":"16398","auth_type":"basic-auth","internal":{"org_id":"57572"},"org_id":"57572","system":{"cert_type":"consumer","cluster_id":"x8LdjPo","cn":"It6P"},"type":"System"}}
//Output: {"identity":{"account_number":"16398","org_id":"57572","internal":{"org_id":"57572"},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{"cn":"It6P","cert_type":"consumer","cluster_id":"x8LdjPo"},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"type":"System","auth_type":"basic-auth"}}
}

func ExampleUser() {
Expand All @@ -60,7 +60,7 @@ func ExampleUser() {
panic(err)
}
fmt.Println(string(data))
//Output: {"identity":{"auth_type":"cert-auth","internal":{"org_id":"23807"},"org_id":"23807","type":"User","user":{"email":"[email protected]","first_name":"Frankie","is_active":false,"is_internal":true,"is_org_admin":false,"last_name":"Collins","locale":"pi","user_id":"backset","username":"tycoon"}}}
//Output: {"identity":{"org_id":"23807","internal":{"org_id":"23807"},"user":{"username":"tycoon","email":"[email protected]","first_name":"Frankie","last_name":"Collins","is_active":false,"is_org_admin":false,"is_internal":true,"locale":"pi","user_id":"backset"},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"type":"User","auth_type":"cert-auth"}}
}

func ExampleX509() {
Expand All @@ -74,5 +74,5 @@ func ExampleX509() {
panic(err)
}
fmt.Println(string(data))
//Output: {"identity":{"auth_type":"cert-auth","org_id":"23807","type":"X509","x509":{"subject_dn":"2","issuer_dn":"3sfSj"}}}
//Output: {"identity":{"org_id":"23807","internal":{"org_id":""},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"2","issuer_dn":"3sfSj"},"type":"X509","auth_type":"cert-auth"}}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/pioz/faker v1.7.3
github.com/redhatinsights/platform-go-middlewares v0.20.0
github.com/sgreben/flagvar v1.10.1
go.openly.dev/pointy v1.3.0
)

require github.com/gobwas/glob v0.2.3 // indirect
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ github.com/sgreben/flagvar v1.10.1/go.mod h1:AxDmbFDIxZ4dHj2zg8LxuJn5CSwSS28iY/W
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.openly.dev/pointy v1.3.0 h1:keht3ObkbDNdY8PWPwB7Kcqk+MAlNStk5kXZTxukE68=
go.openly.dev/pointy v1.3.0/go.mod h1:rccSKiQDQ2QkNfSVT2KG8Budnfhf3At8IWxy/3ElYes=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
Expand Down Expand Up @@ -62,5 +64,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
113 changes: 41 additions & 72 deletions identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,111 +7,80 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
"github.com/redhatinsights/platform-go-middlewares/identity"
"go.openly.dev/pointy"
)

func TestNewIdentity(t *testing.T) {
tests := []struct {
type Tests struct {
description string
seed int64
input Identity
want *identity.Identity
want *identity.XRHID
wantError error
}{
}
tests := []Tests{
{
description: "empty template",
seed: 100,
input: Identity{},
want: &identity.Identity{
Identity: struct {
AccountNumber *string "json:\"account_number,omitempty\""
Associate *identity.Associate "json:\"associate,omitempty\""
AuthType string "json:\"auth_type,omitempty\""
EmployeeAccountNumber *string "json:\"employee_account_number,omitempty\""
Internal *identity.Internal "json:\"internal,omitempty\""
OrgID string "json:\"org_id\""
System *identity.System "json:\"system,omitempty\""
Type *string "json:\"type,omitempty\""
User *identity.User "json:\"user,omitempty\""
X509 *identity.X509 "json:\"x509,omitempty\""
}{
AccountNumber: nil,
Associate: nil,
want: &identity.XRHID{
Identity: identity.Identity{
AccountNumber: "",
Associate: identity.Associate{},
AuthType: "basic-auth",
EmployeeAccountNumber: ptrstring("02299"),
Internal: nil,
EmployeeAccountNumber: "02299",
Internal: identity.Internal{},
OrgID: "41123",
System: nil,
Type: ptrstring("50cQB"),
User: nil,
X509: nil,
System: identity.System{},
Type: "50cQB",
User: identity.User{},
X509: identity.X509{},
},
},
},
{
description: "partial template",
seed: 100,
input: Identity{
AccountNumber: ptrstring("1234"),
AccountNumber: pointy.String("1234"),
},
want: &identity.Identity{
Identity: struct {
AccountNumber *string "json:\"account_number,omitempty\""
Associate *identity.Associate "json:\"associate,omitempty\""
AuthType string "json:\"auth_type,omitempty\""
EmployeeAccountNumber *string "json:\"employee_account_number,omitempty\""
Internal *identity.Internal "json:\"internal,omitempty\""
OrgID string "json:\"org_id\""
System *identity.System "json:\"system,omitempty\""
Type *string "json:\"type,omitempty\""
User *identity.User "json:\"user,omitempty\""
X509 *identity.X509 "json:\"x509,omitempty\""
}{
AccountNumber: ptrstring("1234"),
Associate: nil,
want: &identity.XRHID{
Identity: identity.Identity{
AccountNumber: "1234",
Associate: identity.Associate{},
AuthType: "cert-auth",
EmployeeAccountNumber: ptrstring("00229"),
Internal: nil,
EmployeeAccountNumber: "00229",
Internal: identity.Internal{},
OrgID: "94112",
System: nil,
Type: ptrstring("M5"),
User: nil,
X509: nil,
System: identity.System{},
Type: "M5",
User: identity.User{},
X509: identity.X509{},
},
},
},
{
description: "full template",
seed: 100,
input: Identity{
AccountNumber: ptrstring("10001"),
AuthType: ptrstring("basic-auth"),
EmployeeAccountNumber: ptrstring("112233"),
OrgID: ptrstring("111111"),
Type: ptrstring("universal"),
AccountNumber: pointy.String("10001"),
AuthType: pointy.String("basic-auth"),
EmployeeAccountNumber: pointy.String("112233"),
OrgID: pointy.String("111111"),
Type: pointy.String("universal"),
},
want: &identity.Identity{
Identity: struct {
AccountNumber *string "json:\"account_number,omitempty\""
Associate *identity.Associate "json:\"associate,omitempty\""
AuthType string "json:\"auth_type,omitempty\""
EmployeeAccountNumber *string "json:\"employee_account_number,omitempty\""
Internal *identity.Internal "json:\"internal,omitempty\""
OrgID string "json:\"org_id\""
System *identity.System "json:\"system,omitempty\""
Type *string "json:\"type,omitempty\""
User *identity.User "json:\"user,omitempty\""
X509 *identity.X509 "json:\"x509,omitempty\""
}{
AccountNumber: ptrstring("10001"),
Associate: nil,
want: &identity.XRHID{
Identity: identity.Identity{
AccountNumber: "10001",
Associate: identity.Associate{},
AuthType: "basic-auth",
EmployeeAccountNumber: ptrstring("112233"),
Internal: nil,
EmployeeAccountNumber: "112233",
Internal: identity.Internal{},
OrgID: "111111",
System: nil,
Type: ptrstring("universal"),
User: nil,
X509: nil,
System: identity.System{},
Type: "universal",
User: identity.User{},
X509: identity.X509{},
},
},
},
Expand Down
26 changes: 14 additions & 12 deletions internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,51 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
"github.com/redhatinsights/platform-go-middlewares/identity"
"go.openly.dev/pointy"
)

func TestNewInternal(t *testing.T) {
tests := []struct {
type Tests struct {
description string
seed int64
input Internal
want *identity.Internal
wantError error
}{
}
tests := []Tests{
{
description: "empty template",
seed: 100,
input: Internal{},
want: &identity.Internal{
AuthTime: ptrfloat64(-1.6924639230312625e+18),
CrossAccess: ptrbool(true),
AuthTime: float32(-1.6924639230312625e+18),
CrossAccess: true,
OrgID: "00229",
},
},
{
description: "partial template",
seed: 100,
input: Internal{
AuthTime: ptrfloat64(1.0),
AuthTime: pointy.Float32(1.0),
},
want: &identity.Internal{
AuthTime: ptrfloat64(1.0),
CrossAccess: ptrbool(false),
AuthTime: 1.0,
CrossAccess: false,
OrgID: "80022",
},
},
{
description: "full template",
seed: 100,
input: Internal{
AuthTime: ptrfloat64(2.0),
CrossAccess: ptrbool(true),
OrgID: ptrstring("123456"),
AuthTime: pointy.Float32(2.0),
CrossAccess: pointy.Bool(true),
OrgID: pointy.String("123456"),
},
want: &identity.Internal{
AuthTime: ptrfloat64(2.0),
CrossAccess: ptrbool(true),
AuthTime: 2.0,
CrossAccess: true,
OrgID: "123456",
},
},
Expand Down
32 changes: 17 additions & 15 deletions system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,52 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
"github.com/redhatinsights/platform-go-middlewares/identity"
"go.openly.dev/pointy"
)

func TestNewSystem(t *testing.T) {
tests := []struct {
type Tests struct {
description string
seed int64
input System
want *identity.System
wantError error
}{
}
tests := []Tests{
{
description: "empty template",
seed: 100,
input: System{},
want: &identity.System{
CertType: ptrstring("consumer"),
ClusterID: ptrstring("i"),
CN: "wu7Re",
CertType: "consumer",
ClusterId: "i",
CommonName: "wu7Re",
},
},
{
description: "partial template",
seed: 100,
input: System{
CertType: ptrstring("asdf"),
CertType: pointy.String("asdf"),
},
want: &identity.System{
CertType: ptrstring("asdf"),
ClusterID: ptrstring("gimwu7Re"),
CN: "hCRM50",
CertType: "asdf",
ClusterId: "gimwu7Re",
CommonName: "hCRM50",
},
},
{
description: "full template",
seed: 100,
input: System{
CertType: ptrstring("consumer"),
ClusterID: ptrstring("1234"),
CN: ptrstring("xyz"),
CertType: pointy.String("consumer"),
ClusterID: pointy.String("1234"),
CN: pointy.String("xyz"),
},
want: &identity.System{
CertType: ptrstring("consumer"),
ClusterID: ptrstring("1234"),
CN: "xyz",
CertType: "consumer",
ClusterId: "1234",
CommonName: "xyz",
},
},
}
Expand Down
Loading

0 comments on commit b003581

Please sign in to comment.