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

Refactor Existing Tests #253

Merged
merged 5 commits into from
Oct 18, 2023
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
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E=
github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
Expand Down Expand Up @@ -474,6 +475,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sebdah/goldie/v2 v2.5.3 h1:9ES/mNN+HNUbNWpVAlrzuZ7jE+Nrczbj8uFRjM7624Y=
Expand Down Expand Up @@ -542,6 +545,9 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/urfave/cli v1.22.12 h1:igJgVw1JdKH+trcLWLeLwZjU9fEfPesQ+9/e4MQ44S8=
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
Expand All @@ -557,6 +563,8 @@ github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vb
github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/wundergraph/graphql-go-tools v1.66.4 h1:yRvXYi0jjTghi5zimTluqHXAmyS7JVlGzTlxY6aL0sI=
github.com/wundergraph/graphql-go-tools v1.66.4/go.mod h1:obaEJWub7088qodhKbSGHyhRVnHlBP5M9HigN/oalLE=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
6 changes: 4 additions & 2 deletions internal/graphapi/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"go.infratographer.com/permissions-api/pkg/permissions/mockpermissions"
"go.infratographer.com/x/echojwtx"
"go.infratographer.com/x/testing/auth"

"go.infratographer.com/load-balancer-api/internal/testutils"
)

func TestJWTEnabledLoadbalancerGETWithAuthClient(t *testing.T) {
Expand Down Expand Up @@ -44,7 +46,7 @@ func TestJWTEnabledLoadbalancerGETWithAuthClient(t *testing.T) {

defer srv.Close()

lb1 := (&LoadBalancerBuilder{}).MustNew(ctx)
lb1 := (&testutils.LoadBalancerBuilder{}).MustNew(ctx)

resp, err := graphTestClient(
withGraphClientHTTPClient(oauthCLI),
Expand Down Expand Up @@ -85,7 +87,7 @@ func TestJWTENabledLoadbalancerGETWithDefaultClient(t *testing.T) {

defer srv.Close()

lb1 := (&LoadBalancerBuilder{}).MustNew(ctx)
lb1 := (&testutils.LoadBalancerBuilder{}).MustNew(ctx)

resp, err := graphTestClient(
withGraphClientHTTPClient(http.DefaultClient),
Expand Down
13 changes: 7 additions & 6 deletions internal/graphapi/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

ent "go.infratographer.com/load-balancer-api/internal/ent/generated"
"go.infratographer.com/load-balancer-api/internal/graphclient"
"go.infratographer.com/load-balancer-api/internal/testutils"
)

func TestQuery_loadBalancer(t *testing.T) {
Expand All @@ -26,8 +27,8 @@ func TestQuery_loadBalancer(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

lb1 := (&LoadBalancerBuilder{}).MustNew(ctx)
lb2 := (&LoadBalancerBuilder{}).MustNew(ctx)
lb1 := (&testutils.LoadBalancerBuilder{}).MustNew(ctx)
lb2 := (&testutils.LoadBalancerBuilder{}).MustNew(ctx)

testCases := []struct {
TestName string
Expand Down Expand Up @@ -90,7 +91,7 @@ func TestCreate_loadBalancer(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

prov := (&ProviderBuilder{}).MustNew(ctx)
prov := (&testutils.ProviderBuilder{}).MustNew(ctx)
ownerID := gidx.MustNewID(ownerPrefix)
locationID := gidx.MustNewID(locationPrefix)
name := gofakeit.DomainName()
Expand Down Expand Up @@ -167,7 +168,7 @@ func TestUpdate_loadBalancer(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

lb := (&LoadBalancerBuilder{}).MustNew(ctx)
lb := (&testutils.LoadBalancerBuilder{}).MustNew(ctx)
updateName := gofakeit.DomainName()

testCases := []struct {
Expand Down Expand Up @@ -242,7 +243,7 @@ func TestDelete_loadBalancer(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

lb := (&LoadBalancerBuilder{}).MustNew(ctx)
lb := (&testutils.LoadBalancerBuilder{}).MustNew(ctx)

testCases := []struct {
TestName string
Expand Down Expand Up @@ -305,7 +306,7 @@ func TestFullLoadBalancerLifecycle(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

prov := (&ProviderBuilder{}).MustNew(ctx)
prov := (&testutils.ProviderBuilder{}).MustNew(ctx)
ownerID := gidx.MustNewID(ownerPrefix)
locationID := gidx.MustNewID(locationPrefix)
name := gofakeit.DomainName()
Expand Down
129 changes: 0 additions & 129 deletions internal/graphapi/models_test.go

This file was deleted.

17 changes: 9 additions & 8 deletions internal/graphapi/origin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

ent "go.infratographer.com/load-balancer-api/internal/ent/generated"
"go.infratographer.com/load-balancer-api/internal/graphclient"
"go.infratographer.com/load-balancer-api/internal/testutils"
)

func TestQueryPoolOrigin(t *testing.T) {
Expand All @@ -26,9 +27,9 @@ func TestQueryPoolOrigin(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

pool1 := (&PoolBuilder{}).MustNew(ctx)
origin1 := (&OriginBuilder{PoolID: pool1.ID}).MustNew(ctx)
origin2 := (&OriginBuilder{PoolID: pool1.ID}).MustNew(ctx)
pool1 := (&testutils.PoolBuilder{}).MustNew(ctx)
origin1 := (&testutils.OriginBuilder{PoolID: pool1.ID}).MustNew(ctx)
origin2 := (&testutils.OriginBuilder{PoolID: pool1.ID}).MustNew(ctx)

testCases := []struct {
TestName string
Expand Down Expand Up @@ -90,7 +91,7 @@ func TestMutate_OriginCreate(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

pool1 := (&PoolBuilder{}).MustNew(ctx)
pool1 := (&testutils.PoolBuilder{}).MustNew(ctx)

testCases := []struct {
TestName string
Expand Down Expand Up @@ -241,8 +242,8 @@ func TestMutate_OriginUpdate(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

pool1 := (&PoolBuilder{}).MustNew(ctx)
origin1 := (&OriginBuilder{PoolID: pool1.ID}).MustNew(ctx)
pool1 := (&testutils.PoolBuilder{}).MustNew(ctx)
origin1 := (&testutils.OriginBuilder{PoolID: pool1.ID}).MustNew(ctx)

testCases := []struct {
TestName string
Expand Down Expand Up @@ -332,8 +333,8 @@ func TestMutate_OriginDelete(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

pool1 := (&PoolBuilder{}).MustNew(ctx)
origin1 := (&OriginBuilder{PoolID: pool1.ID}).MustNew(ctx)
pool1 := (&testutils.PoolBuilder{}).MustNew(ctx)
origin1 := (&testutils.OriginBuilder{PoolID: pool1.ID}).MustNew(ctx)

testCases := []struct {
TestName string
Expand Down
9 changes: 5 additions & 4 deletions internal/graphapi/owner_resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

ent "go.infratographer.com/load-balancer-api/internal/ent/generated"
"go.infratographer.com/load-balancer-api/internal/graphclient"
"go.infratographer.com/load-balancer-api/internal/testutils"
)

func TestOwnerLoadBalancersResolver(t *testing.T) {
Expand All @@ -26,10 +27,10 @@ func TestOwnerLoadBalancersResolver(t *testing.T) {
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

ownerID := gidx.MustNewID("testtnt")
lb1 := (&LoadBalancerBuilder{OwnerID: ownerID, LocationID: "testloc-CCCafdsaf", Name: "lb-a"}).MustNew(ctx)
lb2 := (&LoadBalancerBuilder{OwnerID: ownerID, LocationID: "testloc-AAAfasdf", Name: "lb-c"}).MustNew(ctx)
lb3 := (&LoadBalancerBuilder{OwnerID: ownerID, LocationID: "testloc-BBBasdfa", Name: "lb-1"}).MustNew(ctx)
(&LoadBalancerBuilder{}).MustNew(ctx)
lb1 := (&testutils.LoadBalancerBuilder{OwnerID: ownerID, LocationID: "testloc-CCCafdsaf", Name: "lb-a"}).MustNew(ctx)
lb2 := (&testutils.LoadBalancerBuilder{OwnerID: ownerID, LocationID: "testloc-AAAfasdf", Name: "lb-c"}).MustNew(ctx)
lb3 := (&testutils.LoadBalancerBuilder{OwnerID: ownerID, LocationID: "testloc-BBBasdfa", Name: "lb-1"}).MustNew(ctx)
(&testutils.LoadBalancerBuilder{}).MustNew(ctx)
// Update LB1 so it's updated at is most recent
lb1.Update().SaveX(ctx)

Expand Down
21 changes: 11 additions & 10 deletions internal/graphapi/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
ent "go.infratographer.com/load-balancer-api/internal/ent/generated"
pool "go.infratographer.com/load-balancer-api/internal/ent/generated/pool"
"go.infratographer.com/load-balancer-api/internal/graphclient"
"go.infratographer.com/load-balancer-api/internal/testutils"
)

func TestQueryPool(t *testing.T) {
Expand All @@ -26,8 +27,8 @@ func TestQueryPool(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

pool1 := (&PoolBuilder{}).MustNew(ctx)
pool2 := (&PoolBuilder{}).MustNew(ctx)
pool1 := (&testutils.PoolBuilder{}).MustNew(ctx)
pool2 := (&testutils.PoolBuilder{}).MustNew(ctx)

testCases := []struct {
TestName string
Expand Down Expand Up @@ -89,8 +90,8 @@ func TestMutate_PoolCreate(t *testing.T) {

ownerID := gidx.MustNewID(ownerPrefix)

lb := (&LoadBalancerBuilder{}).MustNew(ctx)
port := (&PortBuilder{Name: "port80", LoadBalancerID: lb.ID, Number: 80}).MustNew(ctx)
lb := (&testutils.LoadBalancerBuilder{}).MustNew(ctx)
port := (&testutils.PortBuilder{Name: "port80", LoadBalancerID: lb.ID, Number: 80}).MustNew(ctx)

testCases := []struct {
TestName string
Expand Down Expand Up @@ -186,9 +187,9 @@ func TestMutate_PoolUpdate(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

pool1 := (&PoolBuilder{Protocol: "tcp"}).MustNew(ctx)
lb := (&LoadBalancerBuilder{}).MustNew(ctx)
port := (&PortBuilder{LoadBalancerID: lb.ID}).MustNew(ctx)
pool1 := (&testutils.PoolBuilder{Protocol: "tcp"}).MustNew(ctx)
lb := (&testutils.LoadBalancerBuilder{}).MustNew(ctx)
port := (&testutils.PortBuilder{LoadBalancerID: lb.ID}).MustNew(ctx)
updateProtocolUDP := graphclient.LoadBalancerPoolProtocolUDP

testCases := []struct {
Expand Down Expand Up @@ -290,9 +291,9 @@ func TestMutate_PoolDelete(t *testing.T) {
// Permit request
ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker)

pool1 := (&PoolBuilder{Protocol: "tcp"}).MustNew(ctx)
pool2 := (&PoolBuilder{Protocol: "tcp"}).MustNew(ctx)
_ = (&OriginBuilder{PoolID: pool2.ID}).MustNew(ctx)
pool1 := (&testutils.PoolBuilder{Protocol: "tcp"}).MustNew(ctx)
pool2 := (&testutils.PoolBuilder{Protocol: "tcp"}).MustNew(ctx)
_ = (&testutils.OriginBuilder{PoolID: pool2.ID}).MustNew(ctx)

testCases := []struct {
TestName string
Expand Down
Loading