Skip to content
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
28 changes: 13 additions & 15 deletions integration_tests/create_postgres_access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ mainTeam:addMember(staleUser)

Helper.readK8sResources("k8s_resources/create_postgres_access")

Test.gql("Postgres branches use local names and stay scoped to their Postgres", function(t)
Test.gql("Postgres access targets the logical database", function(t)
t.addHeader("x-user-email", user:email())
t.query [[{ team(slug: "someteamname") { environment(name: "dev") {
postgres(name: "foobar") { activeBranch { name } branches { nodes { name postgres { name } } } branch(name: "main") { name postgres { name } } }
postgres(name: "foobar") { name state }
} } }]]
t.check { data = { team = { environment = { postgres = {
activeBranch = { name = "main" },
branches = { nodes = { { name = "main", postgres = { name = "foobar" } } } },
branch = { name = "main", postgres = { name = "foobar" } },
name = "foobar", state = "AVAILABLE",
} } } } }
end)

Expand All @@ -29,7 +27,7 @@ Test.gql("Create personal postgres access without authorization", function(t)
t.query [[
mutation CreatePostgresAccess {
createPostgresAccess(input: {
postgres: "foobar", branch: "main"
postgres: "foobar"
environmentName: "dev"
teamSlug: "someteamname"
accessLevel: READ
Expand Down Expand Up @@ -58,7 +56,7 @@ Test.gql("Create personal postgres access requires an audit reason", function(t)
t.query [[
mutation CreatePostgresAccess {
createPostgresAccess(input: {
postgres: "foobar", branch: "main"
postgres: "foobar"
environmentName: "dev"
teamSlug: "someteamname"
accessLevel: READ
Expand Down Expand Up @@ -86,7 +84,7 @@ Test.gql("Create personal postgres access rejects an unknown instance", function
t.query [[
mutation CreatePostgresAccess {
createPostgresAccess(input: {
postgres: "foobar", branch: "unknown"
postgres: "unknown"
environmentName: "dev"
teamSlug: "someteamname"
accessLevel: READ
Expand Down Expand Up @@ -114,7 +112,7 @@ Test.gql("Create personal postgres access rejects a logical Postgres without a p
t.addHeader("x-user-email", user:email())
t.query [[
mutation { createPostgresAccess(input: {
postgres: "legacy-only", branch: "main", environmentName: "dev",
postgres: "legacy-only", environmentName: "dev",
teamSlug: "someteamname", accessLevel: READ,
reason: "Testing missing physical database instance"
}) { name } }
Expand All @@ -130,7 +128,7 @@ Test.gql("Create personal postgres access rejects an unavailable instance", func
t.query [[
mutation CreatePostgresAccess {
createPostgresAccess(input: {
postgres: "progressing", branch: "main"
postgres: "progressing"
environmentName: "dev"
teamSlug: "someteamname"
accessLevel: READ
Expand Down Expand Up @@ -159,7 +157,7 @@ Test.gql("Create personal postgres access", function(t)
t.query [[
mutation CreatePostgresAccess {
createPostgresAccess(input: {
postgres: "foobar", branch: "main"
postgres: "foobar"
environmentName: "dev"
teamSlug: "someteamname"
accessLevel: READWRITE
Expand Down Expand Up @@ -229,7 +227,7 @@ Test.gql("Requesting access again returns the live access instead of creating an
t.addHeader("x-user-email", creatorUser:email())
local request = [[
mutation { createPostgresAccess(input: {
postgres: "foobar", branch: "main", environmentName: "dev", teamSlug: "someteamname",
postgres: "foobar", environmentName: "dev", teamSlug: "someteamname",
accessLevel: READWRITE, reason: "Testing personal database access"
}) { name expiresAt } }
]]
Expand All @@ -249,7 +247,7 @@ Test.gql("Changing access level revokes and recreates live access", function(t)
for _, level in ipairs({ "READ", "READWRITE" }) do
t.query(string.format([[
mutation { createPostgresAccess(input: {
postgres: "foobar", branch: "main", environmentName: "dev", teamSlug: "someteamname",
postgres: "foobar", environmentName: "dev", teamSlug: "someteamname",
accessLevel: %s, reason: "Testing personal database access"
}) { name expiresAt } }
]], level))
Expand Down Expand Up @@ -279,7 +277,7 @@ Test.gql("Personal access rejects retired non-main selection", function(t)
reason: "Testing access to a recovered instance"
}) { name } }
]]
t.check { data = Null, errors = { { extensions = { field = "branch" }, message = Contains("Could not find PostgresBranch"), path = { "createPostgresAccess" } } } }
t.check { data = Null, errors = { { extensions = { code = "GRAPHQL_VALIDATION_FAILED" }, locations = NotNull(), message = Contains('Field "branch" is not defined') } } }
end)

Test.gql("PostgresAccess status is visible to authorized team members", function(t)
Expand Down Expand Up @@ -432,7 +430,7 @@ Test.gql("An expired access is replaced in the same request", function(t)
t.addHeader("x-user-email", staleUser:email())
local request = [[
mutation { createPostgresAccess(input: {
postgres: "foobar", branch: "main", environmentName: "dev", teamSlug: "someteamname",
postgres: "foobar", environmentName: "dev", teamSlug: "someteamname",
accessLevel: READ, reason: "Testing personal database access"
}) { name } }
]]
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/create_postgres_admin_access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Helper.readK8sResources("k8s_resources/create_postgres_access")

local request = [[
mutation { createPostgresAccess(input: {
postgres: "foobar", branch: "main", environmentName: "dev", teamSlug: "someteamname",
postgres: "foobar", environmentName: "dev", teamSlug: "someteamname",
accessLevel: ADMIN, reason: "Creating an application schema", ttl: "30m"
}) { name expiresAt } }
]]
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/create_postgres_maintain_access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Helper.readK8sResources("k8s_resources/create_postgres_access")

local request = [[
mutation { createPostgresAccess(input: {
postgres: "foobar", branch: "main", environmentName: "dev", teamSlug: "someteamname",
postgres: "foobar", environmentName: "dev", teamSlug: "someteamname",
accessLevel: MAINTAIN, reason: "Investigating database maintenance", ttl: "30m"
}) { name expiresAt } }
]]
Expand Down
26 changes: 8 additions & 18 deletions integration_tests/label_selectors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Test.gql("Check all Postgres instances (no filter)", function(t)
}
nodes {
name
branches { nodes { name labels { key value } } }
labels { key value }
}
}
}
Expand All @@ -159,34 +159,24 @@ Test.gql("Check all Postgres instances (no filter)", function(t)
postgreses = {
pageInfo = { totalCount = 3 },
nodes = {
{ name = "postgres-one", branches = { nodes = { { name = "main", labels = { { key = "priority", value = "high" }, { key = "tag", value = "target" } } } } } },
{ name = "postgres-three", branches = { nodes = { { name = "main", labels = { { key = "tag", value = "other" } } } } } },
{ name = "postgres-two", branches = { nodes = { { name = "main", labels = { { key = "tag", value = "target" } } } } } },
{ name = "postgres-one", labels = { { key = "priority", value = "high" }, { key = "tag", value = "target" } } },
{ name = "postgres-three", labels = { { key = "tag", value = "other" } } },
{ name = "postgres-two", labels = { { key = "tag", value = "target" } } },
},
},
},
},
}
end)

Test.gql("A branch's labels are available through its Postgres", function(t)
Test.gql("Postgres labels are available on the database", function(t)
t.addHeader("x-user-email", user:email())
t.query [[{ team(slug: "labelteam") { environment(name: "dev") {
postgres(name: "postgres-one") { branch(name: "main") { labels { key value } } }
postgres(name: "postgres-one") { labels { key value } }
} } }]]
t.check { data = { team = { environment = { postgres = { branch = { labels = {
t.check { data = { team = { environment = { postgres = { labels = {
{ key = "priority", value = "high" }, { key = "tag", value = "target" },
} } } } } } }
end)

Test.gql("The main facade inherits Postgres labels", function(t)
t.addHeader("x-user-email", user:email())
t.query [[{ team(slug: "labelteam") { environment(name: "dev") {
postgres(name: "postgres-one") { labels { key value } branch(name: "main") { labels { key value } } }
} } }]]
t.check { data = { team = { environment = { postgres = {
labels = { { key = "priority", value = "high" }, { key = "tag", value = "target" } }, branch = { labels = { { key = "priority", value = "high" }, { key = "tag", value = "target" } } },
} } } } }
} } } } } }
end)

Test.gql("Check all applications (no filter)", function(t)
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/postgres_audit_log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ team:addMember(user)
Test.gql("Logical Postgres settings are not fabricated on physical instances", function(t)
t.addHeader("x-user-email", user:email())
t.query [[{ team(slug:"audit-postgres-team") { environment(name:"dev-gcp") {
postgres(name:"audit-enabled") { branch(name:"main") { name state postgres { name majorVersion } } }
postgres(name:"audit-enabled") { name state majorVersion }
} } }]]
t.check { data = { team = { environment = { postgres = { branch = {
name = "main", state = "AVAILABLE", postgres = { name = "audit-enabled", majorVersion = "16" },
} } } } } }
t.check { data = { team = { environment = { postgres = {
name = "audit-enabled", state = "AVAILABLE", majorVersion = "16",
} } } } }
end)
37 changes: 14 additions & 23 deletions integration_tests/postgres_branch_selection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,27 @@ Helper.readK8sResources("k8s_resources/postgres_branch_selection")
Test.gql("The main facade includes omitted and explicit main consumers", function(t)
t.addHeader("x-user-email", user:email())
t.query [[{ team(slug: "pg-selection-team") { environment(name: "dev") {
postgres(name: "orders") { branch(name: "main") { workloads { nodes { __typename name } } } }
postgres(name: "orders") { workloads { nodes { workload { __typename ... on Application { name } ... on Job { name } } } } }
} } }]]
t.check { data = { team = { environment = { postgres = { branch = { workloads = { nodes = {
{ __typename = "Application", name = "following-app" },
{ __typename = "Application", name = "pinned-app" },
{ __typename = "Job", name = "pinned-job" },
} } } } } } } }
t.check { data = { team = { environment = { postgres = { workloads = { nodes = {
{ workload = { __typename = "Application", name = "following-app" } },
{ workload = { __typename = "Application", name = "pinned-app" } },
{ workload = { __typename = "Job", name = "pinned-job" } },
} } } } } } }
end)

Test.gql("Stale active branch metadata never selects a physical target", function(t)
t.addHeader("x-user-email", user:email())
t.query [[{ team(slug: "pg-selection-team") { environment(name: "dev") {
postgres(name: "orders") { activeBranch { name } branches { nodes { name } } }
application(name: "following-app") { postgreses { nodes { branch { name } postgres { name } } } }
postgres(name: "orders") { name state }
application(name: "following-app") { postgreses { nodes { postgres { name } } } }
} } }]]
t.check { data = { team = { environment = {
postgres = { activeBranch = { name = "main" }, branches = { nodes = { { name = "main" } } } },
application = { postgreses = { nodes = { { branch = { name = "main" }, postgres = { name = "orders" } } } } },
postgres = { name = "orders", state = "PROGRESSING" },
application = { postgreses = { nodes = { { postgres = { name = "orders" } } } } },
} } } }
end)

Test.gql("Retired non-main lookups do not fall back to main", function(t)
t.addHeader("x-user-email", user:email())
t.query [[{ team(slug: "pg-selection-team") { environment(name: "dev") {
postgres(name: "orders") { branch(name: "green") { name } }
} } }]]
t.check { data = Null, errors = { { locations = NotNull(), message = Contains("orders/green"), path = { "team", "environment", "postgres", "branch" } } } }
end)

Test.gql("Postgres pagination is validated when a workload has no uses", function(t)
t.addHeader("x-user-email", user:email())
t.query [[{ team(slug: "pg-selection-team") { environment(name: "dev") {
Expand All @@ -47,13 +39,12 @@ Test.gql("A provisioning database retains workload relations without branch obje
t.addHeader("x-user-email", user:email())
t.query [[{ team(slug: "pg-selection-team") { environment(name: "dev") {
postgres(name: "missing-branch") {
state activeBranch { name state } branch(name: "main") { name state }
workloads { pageInfo { totalCount } nodes { branch { name } workload { ... on Application { name } } } }
state
workloads { pageInfo { totalCount } nodes { workload { ... on Application { name } } } }
}
} } }]]
t.check { data = { team = { environment = { postgres = {
state = "PROGRESSING", branch = { name = "main", state = "PROGRESSING" },
activeBranch = { name = "main", state = "PROGRESSING" },
workloads = { pageInfo = { totalCount = 1 }, nodes = { { branch = { name = "main" }, workload = { name = "missing-branch-app" } } } },
state = "PROGRESSING",
workloads = { pageInfo = { totalCount = 1 }, nodes = { { workload = { name = "missing-branch-app" } } } },
} } } } }
end)
Loading
Loading