Skip to content

Commit

Permalink
provider error logs, do no expose internals
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>
  • Loading branch information
rizzza committed Sep 27, 2023
1 parent 33aca57 commit dacc5b5
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
68 changes: 63 additions & 5 deletions internal/graphapi/provider.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 33 additions & 4 deletions internal/graphapi/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func TestQuery_loadBalancerProvider(t *testing.T) {
QueryID: gidx.MustNewID("testing"),
errorMsg: "provider not found",
},
{
TestName: "Invalid load balancer provider ID",
QueryID: gidx.PrefixedID("invalid"),
errorMsg: "invalid id",
},
}

for _, tt := range testCases {
Expand Down Expand Up @@ -102,6 +107,11 @@ func TestCreate_Provider(t *testing.T) {
Input: graphclient.CreateLoadBalancerProviderInput{Name: name, OwnerID: ""},
errorMsg: "value is less than the required length",
},
{
TestName: "fails to create provider with invalid ownerID",
Input: graphclient.CreateLoadBalancerProviderInput{Name: name, OwnerID: gidx.PrefixedID("invalid")},
errorMsg: "invalid id",
},
}

for _, tt := range testCases {
Expand Down Expand Up @@ -139,16 +149,17 @@ func TestUpdate_Provider(t *testing.T) {

prov := ProviderBuilder{}.MustNew(ctx)
updateName := gofakeit.DomainName()
emptyName := ""

testCases := []struct {
TestName string
ID gidx.PrefixedID
Input graphclient.UpdateLoadBalancerProviderInput
ExpectedProvider *ent.LoadBalancerProvider
errorMsg string
}{
{
TestName: "updates provider",
ID: prov.ID,
Input: graphclient.UpdateLoadBalancerProviderInput{Name: &updateName},
ExpectedProvider: &ent.LoadBalancerProvider{
Name: updateName,
Expand All @@ -158,14 +169,27 @@ func TestUpdate_Provider(t *testing.T) {
},
{
TestName: "fails to update name to empty",
Input: graphclient.UpdateLoadBalancerProviderInput{Name: &emptyName},
ID: prov.ID,
Input: graphclient.UpdateLoadBalancerProviderInput{Name: newString("")},
errorMsg: "value is less than the required length",
},
{
TestName: "fails to update provider that does not exist",
ID: gidx.PrefixedID("loadpvd-dne"),
Input: graphclient.UpdateLoadBalancerProviderInput{},
errorMsg: "provider not found",
},
{
TestName: "fails to update provider with invalid id",
ID: gidx.PrefixedID("invalid"),
Input: graphclient.UpdateLoadBalancerProviderInput{},
errorMsg: "invalid id",
},
}

for _, tt := range testCases {
t.Run(tt.TestName, func(t *testing.T) {
resp, err := graphTestClient().LoadBalancerProviderUpdate(ctx, prov.ID, tt.Input)
resp, err := graphTestClient().LoadBalancerProviderUpdate(ctx, tt.ID, tt.Input)

if tt.errorMsg != "" {
require.Error(t, err)
Expand Down Expand Up @@ -215,11 +239,16 @@ func TestDelete_Provider(t *testing.T) {
Input: gidx.PrefixedID(""),
errorMsg: "provider not found",
},
{
TestName: "fails to delete invalid gidx id",
Input: gidx.PrefixedID("not-a-valid-gidx-id"),
errorMsg: "invalid id",
},
}

for _, tt := range testCases {
t.Run(tt.TestName, func(t *testing.T) {
resp, err := graphTestClient().LoadBalancerProviderDelete(ctx, prov.ID)
resp, err := graphTestClient().LoadBalancerProviderDelete(ctx, tt.Input)

if tt.errorMsg != "" {
require.Error(t, err)
Expand Down

0 comments on commit dacc5b5

Please sign in to comment.