Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com>
  • Loading branch information
sthwang-metal committed Aug 7, 2024
1 parent ece7e60 commit 3977a62
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 6 deletions.
11 changes: 11 additions & 0 deletions internal/graphapi/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func TestCreate_loadBalancer(t *testing.T) {
Input: graphclient.CreateLoadBalancerInput{Name: name, ProviderID: prov.ID, OwnerID: ownerID, LocationID: ""},
errorMsg: "must not be empty",
},
{
TestName: "fails to create loadbalancer with long name",
Input: graphclient.CreateLoadBalancerInput{Name: longName, ProviderID: prov.ID, OwnerID: ownerID, LocationID: locationID},
errorMsg: "must not be longer than",
},
}

for _, tt := range testCases {
Expand Down Expand Up @@ -288,6 +293,12 @@ func TestUpdate_loadBalancer(t *testing.T) {
Input: graphclient.UpdateLoadBalancerInput{Name: newString("loadbal-dne")},
errorMsg: "invalid id",
},
{
TestName: "fails to update loadbalancer with long name",
ID: lb.ID,
Input: graphclient.UpdateLoadBalancerInput{Name: &longName},
errorMsg: "must not be longer than",
},
}

for _, tt := range testCases {
Expand Down
29 changes: 27 additions & 2 deletions internal/graphapi/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestMutate_PoolCreate(t *testing.T) {
errorMsg: "validator failed",
},
{
TestName: "port with conflicting OwnerID",
TestName: "pool with conflicting OwnerID",
Input: graphclient.CreateLoadBalancerPoolInput{
Name: "",
Protocol: graphclient.LoadBalancerPoolProtocolUDP,
Expand All @@ -150,6 +150,15 @@ func TestMutate_PoolCreate(t *testing.T) {
},
errorMsg: "one or more ports not found",
},
{
TestName: "fails to create pool with long name",
Input: graphclient.CreateLoadBalancerPoolInput{
Name: longName,
Protocol: graphclient.LoadBalancerPoolProtocolTCP,
OwnerID: ownerID,
},
errorMsg: "must not be longer than",
},
}

for _, tt := range testCases {
Expand Down Expand Up @@ -255,6 +264,12 @@ func TestMutate_PoolUpdate(t *testing.T) {
},
errorMsg: "one or more ports not found",
},
{
TestName: "fails to update pool with long name",
ID: pool1.ID,
Input: graphclient.UpdateLoadBalancerPoolInput{Name: &longName},
errorMsg: "must not be longer than",
},
}

for _, tt := range testCases {
Expand Down Expand Up @@ -320,12 +335,22 @@ func TestMutate_PoolDelete(t *testing.T) {
{
TestName: "fails to delete empty pool id",
DeleteID: gidx.PrefixedID(""),
errorMsg: "not found",
errorMsg: "must not be empty",
},
{
TestName: "deletes pool with associated origins",
DeleteID: pool2.ID,
},
{
TestName: "fails with invalid gidx",
DeleteID: "test-invalid-id",
errorMsg: "invalid id",
},
{
TestName: "fails with invalid characters",
DeleteID: gidx.PrefixedID("loadpol-!@#$%^&*()"),
errorMsg: "valid characters are A-Z a-z 0-9 _ -",
},
}

for _, tt := range testCases {
Expand Down
27 changes: 26 additions & 1 deletion internal/graphapi/port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ func TestCreate_LoadbalancerPort(t *testing.T) {
},
errorMsg: "one or more pools not found",
},
{
TestName: "fails to create port with long name",
Input: graphclient.CreateLoadBalancerPortInput{
Name: &longName,
LoadBalancerID: lb.ID,
Number: 22,
},
errorMsg: "must not be longer than",
},
}

for _, tt := range testCases {
Expand Down Expand Up @@ -283,6 +292,12 @@ func TestUpdate_LoadbalancerPort(t *testing.T) {
},
errorMsg: "one or more pools not found",
},
{
TestName: "fails to update port with long name",
ID: port.ID,
Input: graphclient.UpdateLoadBalancerPortInput{Name: &longName},
errorMsg: "must not be longer than",
},
}

for _, tt := range testCases {
Expand Down Expand Up @@ -341,7 +356,7 @@ func TestDelete_LoadbalancerPort(t *testing.T) {
{
TestName: "fails to delete empty loadbalancer port ID",
Input: gidx.PrefixedID(""),
errorMsg: "port not found",
errorMsg: "must not be empty",
},
{
TestName: "fails to delete with invalid gidx port ID",
Expand Down Expand Up @@ -411,6 +426,16 @@ func TestGet_LoadbalancerPort(t *testing.T) {
QueryID: "an invalid port id",
errorMsg: "invalid id",
},
{
TestName: "fails with invalid gidx",
QueryID: "test-invalid-id",
errorMsg: "invalid id",
},
{
TestName: "fails with invalid characters",
QueryID: gidx.PrefixedID("loadprt-!@#$%^&*()"),
errorMsg: "valid characters are A-Z a-z 0-9 _ -",
},
}

for _, tt := range testCases {
Expand Down
33 changes: 30 additions & 3 deletions internal/graphapi/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ func TestCreate_Provider(t *testing.T) {
{
TestName: "fails to create provider with empty name",
Input: graphclient.CreateLoadBalancerProviderInput{Name: "", OwnerID: ownerID},
errorMsg: "value is less than the required length",
errorMsg: "must not be empty",
},
{
TestName: "fails to create provider with long name",
Input: graphclient.CreateLoadBalancerProviderInput{Name: longName, OwnerID: ownerID},
errorMsg: "must not be longer than",
},
{
TestName: "fails to create provider with empty ownerID",
Expand Down Expand Up @@ -174,7 +179,13 @@ func TestUpdate_Provider(t *testing.T) {
TestName: "fails to update name to empty",
ID: prov.ID,
Input: graphclient.UpdateLoadBalancerProviderInput{Name: newString("")},
errorMsg: "value is less than the required length",
errorMsg: "must not be empty",
},
{
TestName: "fails to update provider with long name",
ID: prov.ID,
Input: graphclient.UpdateLoadBalancerProviderInput{Name: &longName},
errorMsg: "must not be longer than",
},
{
TestName: "fails to update provider that does not exist",
Expand All @@ -188,6 +199,12 @@ func TestUpdate_Provider(t *testing.T) {
Input: graphclient.UpdateLoadBalancerProviderInput{},
errorMsg: "invalid id",
},
{
TestName: "fails with invalid characters",
Input: graphclient.UpdateLoadBalancerProviderInput{},
ID: gidx.PrefixedID("loadpvd-!@#$%^&*()"),
errorMsg: "valid characters are A-Z a-z 0-9 _ -",
},
}

for _, tt := range testCases {
Expand Down Expand Up @@ -240,13 +257,23 @@ func TestDelete_Provider(t *testing.T) {
{
TestName: "fails to delete empty provider ID",
Input: gidx.PrefixedID(""),
errorMsg: "provider not found",
errorMsg: "must not be empty",
},
{
TestName: "fails to delete invalid gidx id",
Input: gidx.PrefixedID("not-a-valid-gidx-id"),
errorMsg: "invalid id",
},
{
TestName: "fails with invalid gidx",
Input: "test-invalid-id",
errorMsg: "invalid id",
},
{
TestName: "fails with invalid characters",
Input: gidx.PrefixedID("loadpvd-!@#$%^&*()"),
errorMsg: "valid characters are A-Z a-z 0-9 _ -",
},
}

for _, tt := range testCases {
Expand Down
3 changes: 3 additions & 0 deletions internal/graphapi/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"

"github.com/99designs/gqlgen/graphql/handler"
Expand Down Expand Up @@ -33,6 +34,8 @@ const (
lbPrefix = "loadbal"
)

var longName = strings.Repeat("a", 65)

var EntClient *ent.Client

func TestMain(m *testing.M) {
Expand Down

0 comments on commit 3977a62

Please sign in to comment.