Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update tests to depends on platform go middleware #11

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion associate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xrhidgen

import (
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

// Associate holds values to be used as input when generating an associate
Expand Down
19 changes: 10 additions & 9 deletions associate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"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("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",
Expand All @@ -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",
Expand Down
16 changes: 9 additions & 7 deletions cmd/xrhidgen/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,27 @@ func (f *BoolFlag) Set(v string) error {

func (f BoolFlag) IsBoolFlag() bool { return true }

type Float64Flag struct {
Value *float64
type Float32Flag struct {
Value *float32
}

func (f Float64Flag) String() string {
func (f Float32Flag) String() string {
if f.Value != nil {
return strconv.FormatFloat(*f.Value, 'G', -1, 64)
return strconv.FormatFloat(float64(*f.Value), 'G', -1, 32)
}
return ""
}

func (f *Float64Flag) Set(v string) error {
func (f *Float32Flag) Set(v string) error {
if f.Value == nil {
f.Value = new(float64)
f.Value = new(float32)
}
var err error
*f.Value, err = strconv.ParseFloat(v, 64)
var value float64
value, err = strconv.ParseFloat(v, 32)
if err != nil {
return err
}
*f.Value = float32(value)
return nil
}
2 changes: 1 addition & 1 deletion cmd/xrhidgen/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var internalFlags struct {
authType Float64Flag
authType Float32Flag
crossAccess BoolFlag
orgID StringFlag
}
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":"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() {
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":"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() {
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"}}
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ require (
github.com/google/go-cmp v0.6.0
github.com/peterbourgon/ff/v3 v3.4.0
github.com/pioz/faker v1.7.3
github.com/redhatinsights/module-update-router v0.0.0-20220708181923-3d8d459361dd
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
Loading