From b003581a0cecd6c2d699847c1002ce8051207a06 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Wed, 29 Nov 2023 10:29:20 +0100 Subject: [PATCH] test: update to fit the updated code 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 --- associate_test.go | 17 +++---- example_test.go | 10 ++-- go.mod | 1 + go.sum | 6 ++- identity_test.go | 113 +++++++++++++++++----------------------------- internal_test.go | 26 ++++++----- system_test.go | 32 +++++++------ user_test.go | 84 +++++++++++++++++----------------- x509_test.go | 12 +++-- 9 files changed, 141 insertions(+), 160 deletions(-) diff --git a/associate_test.go b/associate_test.go index 95594a2..b845628 100644 --- a/associate_test.go +++ b/associate_test.go @@ -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) { @@ -33,9 +34,9 @@ func TestNewAssociate(t *testing.T) { description: "partial template", seed: 100, input: Associate{ - Email: ptrstring("jsmith@redhat.com"), - GivenName: ptrstring("John"), - Surname: ptrstring("Smith"), + Email: pointy.String("jsmith@redhat.com"), + GivenName: pointy.String("John"), + Surname: pointy.String("Smith"), }, want: &identity.Associate{ Email: "jsmith@redhat.com", @@ -49,11 +50,11 @@ func TestNewAssociate(t *testing.T) { description: "full template", seed: 100, input: Associate{ - Email: ptrstring("jsmith@redhat.com"), - GivenName: ptrstring("John"), - RHatUUID: ptrstring("6208f878-b405-498e-979f-e85cd68d8a18"), - Role: ptrslicestring([]string{"a", "b"}), - Surname: ptrstring("Smith"), + Email: pointy.String("jsmith@redhat.com"), + GivenName: pointy.String("John"), + RHatUUID: pointy.String("6208f878-b405-498e-979f-e85cd68d8a18"), + Role: &[]string{"a", "b"}, + Surname: pointy.String("Smith"), }, want: &identity.Associate{ Email: "jsmith@redhat.com", diff --git a/example_test.go b/example_test.go index dca1972..17d7494 100644 --- a/example_test.go +++ b/example_test.go @@ -18,7 +18,7 @@ func ExampleAssociate() { panic(err) } fmt.Println(string(data)) - //Output: {"identity":{"associate":{"email":"winnifredwinning@shred.org","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":"winnifredwinning@shred.org","givenName":"Cameron","rhatUUID":"00e3c758-1d7d-4ecd-98a2-997157e2d05c","surname":"Swift"},"x509":{"subject_dn":"","issuer_dn":""},"type":"Associate","auth_type":"basic-auth"}} } func ExampleInternal() { @@ -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() { @@ -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() { @@ -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":"fransen@crump.biz","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":"fransen@crump.biz","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() { @@ -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"}} } diff --git a/go.mod b/go.mod index 809539e..83bf922 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 66800ce..ba273b1 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/identity_test.go b/identity_test.go index cdf14cf..e8df133 100644 --- a/identity_test.go +++ b/identity_test.go @@ -7,43 +7,34 @@ 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{}, }, }, }, @@ -51,31 +42,20 @@ func TestNewIdentity(t *testing.T) { 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{}, }, }, }, @@ -83,35 +63,24 @@ func TestNewIdentity(t *testing.T) { 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{}, }, }, }, diff --git a/internal_test.go b/internal_test.go index 3103dfa..a44a041 100644 --- a/internal_test.go +++ b/internal_test.go @@ -7,23 +7,25 @@ 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", }, }, @@ -31,11 +33,11 @@ func TestNewInternal(t *testing.T) { 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", }, }, @@ -43,13 +45,13 @@ func TestNewInternal(t *testing.T) { 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", }, }, diff --git a/system_test.go b/system_test.go index 71d5f7a..6913f6f 100644 --- a/system_test.go +++ b/system_test.go @@ -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", }, }, } diff --git a/user_test.go b/user_test.go index 778e8ad..cc5c02b 100644 --- a/user_test.go +++ b/user_test.go @@ -7,76 +7,78 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/pioz/faker" "github.com/redhatinsights/platform-go-middlewares/identity" + "go.openly.dev/pointy" ) func TestNewUser(t *testing.T) { - tests := []struct { + type Tests struct { description string seed int64 input User want *identity.User wantError error - }{ + } + tests := []Tests{ { description: "empty template", seed: 100, input: User{}, want: &identity.User{ - Email: "ammon@benison.biz", - FirstName: "Augustine", - IsActive: true, - IsInternal: false, - IsOrgAdmin: false, - LastName: "Stracke", - Locale: "fo", - UserID: "salify", - Username: "platas", + Email: "ammon@benison.biz", + FirstName: "Augustine", + Active: true, + Internal: false, + OrgAdmin: false, + LastName: "Stracke", + Locale: "fo", + UserID: "salify", + Username: "platas", }, }, { description: "partial template", seed: 100, input: User{ - Email: ptrstring("jsmith@redhat.com"), - FirstName: ptrstring("John"), - LastName: ptrstring("Smith"), + Email: pointy.String("jsmith@redhat.com"), + FirstName: pointy.String("John"), + LastName: pointy.String("Smith"), }, want: &identity.User{ - Email: "jsmith@redhat.com", - FirstName: "John", - IsActive: false, - IsInternal: true, - IsOrgAdmin: true, - LastName: "Smith", - Locale: "ik", - UserID: "goniometer", - Username: "waldner", + Email: "jsmith@redhat.com", + FirstName: "John", + Active: false, + Internal: true, + OrgAdmin: true, + LastName: "Smith", + Locale: "ik", + UserID: "goniometer", + Username: "waldner", }, }, { description: "full template", seed: 100, input: User{ - Email: ptrstring("jsmith@redhat.com"), - FirstName: ptrstring("John"), - IsActive: ptrbool(true), - IsInternal: ptrbool(true), - IsOrgAdmin: ptrbool(false), - LastName: ptrstring("Smith"), - Locale: ptrstring("en"), - UserID: ptrstring("jsmith1"), - Username: ptrstring("jsm"), + Email: pointy.String("jsmith@redhat.com"), + FirstName: pointy.String("John"), + IsActive: pointy.Bool(true), + IsInternal: pointy.Bool(true), + IsOrgAdmin: pointy.Bool(false), + LastName: pointy.String("Smith"), + Locale: pointy.String("en"), + UserID: pointy.String("jsmith1"), + Username: pointy.String("jsm"), }, want: &identity.User{ - Email: "jsmith@redhat.com", - FirstName: "John", - IsActive: true, - IsInternal: true, - IsOrgAdmin: false, - LastName: "Smith", - Locale: "en", - UserID: "jsmith1", - Username: "jsm", + Email: "jsmith@redhat.com", + FirstName: "John", + Active: true, + Internal: true, + OrgAdmin: false, + LastName: "Smith", + Locale: "en", + UserID: "jsmith1", + Username: "jsm", }, }, } diff --git a/x509_test.go b/x509_test.go index 8044130..a7190ea 100644 --- a/x509_test.go +++ b/x509_test.go @@ -7,16 +7,18 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/pioz/faker" "github.com/redhatinsights/platform-go-middlewares/identity" + "go.openly.dev/pointy" ) func TestNewX509(t *testing.T) { - tests := []struct { + type Test struct { description string seed int64 input X509 want *identity.X509 wantError error - }{ + } + tests := []Test{ { description: "empty template", seed: 100, @@ -30,7 +32,7 @@ func TestNewX509(t *testing.T) { description: "partial template", seed: 100, input: X509{ - SubjectDN: ptrstring("CN = d6cde789-fbad-45ea-a542-30ba779aa870"), + SubjectDN: pointy.String("CN = d6cde789-fbad-45ea-a542-30ba779aa870"), }, want: &identity.X509{ SubjectDN: "CN = d6cde789-fbad-45ea-a542-30ba779aa870", @@ -41,8 +43,8 @@ func TestNewX509(t *testing.T) { description: "full template", seed: 100, input: X509{ - SubjectDN: ptrstring("CN = d6cde789-fbad-45ea-a542-30ba779aa870"), - IssuerDN: ptrstring("O = Foo, Inc."), + SubjectDN: pointy.String("CN = d6cde789-fbad-45ea-a542-30ba779aa870"), + IssuerDN: pointy.String("O = Foo, Inc."), }, want: &identity.X509{ SubjectDN: "CN = d6cde789-fbad-45ea-a542-30ba779aa870",