Skip to content

Commit

Permalink
Function integration test refactor
Browse files Browse the repository at this point in the history
Authored-by: Kevin Yeap <kyeap@vmware.com>
  • Loading branch information
kyeap-vmware authored and AJR-VMware committed Nov 22, 2022
1 parent e28433d commit 303871a
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions integration/predata_functions_queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ var _ = Describe("backup integration tests", func() {
Describe("GetFunctions", func() {
var prokindValue string
var plannerSupportValue string
var proparallelValue string
BeforeEach(func() {
testutils.SkipIfBefore5(connectionPool)
if connectionPool.Version.AtLeast("7") {
prokindValue = "f"
plannerSupportValue = "-"
proparallelValue = "u"
} else {
prokindValue = ""
plannerSupportValue = ""
proparallelValue = ""
}
})
It("returns a slice of functions", func() {
Expand Down Expand Up @@ -56,15 +59,14 @@ MODIFIES SQL DATA
IdentArgs: sql.NullString{String: "integer, integer", Valid: true},
ResultType: sql.NullString{String: "integer", Valid: true},
Volatility: "v", IsStrict: false, IsSecurityDefiner: false, PlannerSupport: plannerSupportValue, Config: "", Cost: 100, NumRows: 0,
DataAccess: "c",
Language: "sql", ExecLocation: "a"}
DataAccess: "c", Language: "sql", ExecLocation: "a", Parallel: proparallelValue}
appendFunction := backup.Function{
Schema: "public", Name: "append", Kind: prokindValue, ReturnsSet: true, FunctionBody: "SELECT ($1, $2)",
BinaryPath: "", Arguments: sql.NullString{String: "integer, integer", Valid: true},
IdentArgs: sql.NullString{String: "integer, integer", Valid: true},
ResultType: sql.NullString{String: "SETOF record", Valid: true},
Volatility: "s", IsStrict: true, IsSecurityDefiner: true, PlannerSupport: plannerSupportValue, Config: `SET search_path TO 'pg_temp'`, Cost: 200,
NumRows: 200, DataAccess: "m", Language: "sql", ExecLocation: "a"}
NumRows: 200, DataAccess: "m", Language: "sql", ExecLocation: "a", Parallel: proparallelValue}

Expect(results).To(HaveLen(2))
structmatcher.ExpectStructsToMatchExcluding(&results[0], &addFunction, "Oid")
Expand All @@ -88,7 +90,7 @@ LANGUAGE SQL`)
IdentArgs: sql.NullString{String: "integer, integer", Valid: true},
ResultType: sql.NullString{String: "integer", Valid: true},
Volatility: "v", IsStrict: false, IsSecurityDefiner: false, PlannerSupport: plannerSupportValue, Config: "", Cost: 100, NumRows: 0, DataAccess: "c",
Language: "sql", ExecLocation: "a"}
Language: "sql", ExecLocation: "a", Parallel: proparallelValue}
_ = backupCmdFlags.Set(options.INCLUDE_SCHEMA, "testschema")
results := backup.GetFunctions(connectionPool)

Expand All @@ -112,7 +114,7 @@ LANGUAGE SQL WINDOW`)
IdentArgs: sql.NullString{String: "integer, integer", Valid: true},
ResultType: sql.NullString{String: "integer", Valid: true},
Volatility: "v", IsStrict: false, IsSecurityDefiner: false, PlannerSupport: plannerSupportValue, Config: "", Cost: 100, NumRows: 0, DataAccess: "c",
Language: "sql", Kind: "w", ExecLocation: "a"}
Language: "sql", Kind: "w", ExecLocation: "a", Parallel: proparallelValue}
} else {
windowFunction = backup.Function{
Schema: "public", Name: "add", ReturnsSet: false, FunctionBody: "SELECT $1 + $2",
Expand All @@ -121,7 +123,7 @@ LANGUAGE SQL WINDOW`)
ResultType: sql.NullString{String: "integer", Valid: true},
Volatility: "v", IsStrict: false, IsSecurityDefiner: false,
PlannerSupport: plannerSupportValue, Config: "", Cost: 100, NumRows: 0, DataAccess: "c",
Language: "sql", IsWindow: true, ExecLocation: "a"}
Language: "sql", IsWindow: true, ExecLocation: "a", Parallel: proparallelValue}
}
Expect(results).To(HaveLen(1))
structmatcher.ExpectStructsToMatchExcluding(&results[0], &windowFunction, "Oid")
Expand Down Expand Up @@ -157,15 +159,15 @@ EXECUTE ON ALL SEGMENTS;`)
ResultType: sql.NullString{String: "integer", Valid: true},
Volatility: "v", IsStrict: false, IsSecurityDefiner: false,
PlannerSupport: plannerSupportValue, Config: "", Cost: 100, NumRows: 0, DataAccess: "c",
Language: "sql", IsWindow: isWindowValue, ExecLocation: "m"}
Language: "sql", IsWindow: isWindowValue, ExecLocation: "m", Parallel: proparallelValue}
srfOnAllSegmentsFunction := backup.Function{
Schema: "public", Name: "srf_on_all_segments", Kind: prokindValue, ReturnsSet: false, FunctionBody: "SELECT $1 + $2",
BinaryPath: "", Arguments: sql.NullString{String: "integer, integer", Valid: true},
IdentArgs: sql.NullString{String: "integer, integer", Valid: true},
ResultType: sql.NullString{String: "integer", Valid: true},
Volatility: "v", IsStrict: false, IsSecurityDefiner: false,
PlannerSupport: plannerSupportValue, Config: "", Cost: 100, NumRows: 0, DataAccess: "c",
Language: "sql", IsWindow: isWindowValue, ExecLocation: "s"}
Language: "sql", IsWindow: isWindowValue, ExecLocation: "s", Parallel: proparallelValue}

Expect(results).To(HaveLen(2))
structmatcher.ExpectStructsToMatchExcluding(&results[0], &srfOnAllSegmentsFunction, "Oid")
Expand Down Expand Up @@ -221,7 +223,7 @@ MODIFIES SQL DATA
ResultType: sql.NullString{String: "SETOF record", Valid: true},
Volatility: "s", IsStrict: true, IsLeakProof: true, IsSecurityDefiner: true,
PlannerSupport: plannerSupportValue, Config: `SET search_path TO 'pg_temp'`, Cost: 200,
NumRows: 200, DataAccess: "m", Language: "sql", ExecLocation: "a"}
NumRows: 200, DataAccess: "m", Language: "sql", ExecLocation: "a", Parallel: proparallelValue}

Expect(results).To(HaveLen(1))
structmatcher.ExpectStructsToMatchExcluding(&results[0], &appendFunction, "Oid")
Expand Down Expand Up @@ -262,7 +264,7 @@ MODIFIES SQL DATA
ResultType: sql.NullString{String: "text", Valid: true},
Volatility: "v", IsStrict: false, IsLeakProof: false, IsSecurityDefiner: false,
PlannerSupport: plannerSupportValue, Config: "SET work_mem TO '1MB'", Cost: 100,
NumRows: 0, DataAccess: "n", Language: "plpgsql", ExecLocation: "a"}
NumRows: 0, DataAccess: "n", Language: "plpgsql", ExecLocation: "a", Parallel: proparallelValue}
Expect(results).To(HaveLen(1))
structmatcher.ExpectStructsToMatchExcluding(&results[0], &appendFunction, "Oid")
})
Expand Down Expand Up @@ -297,7 +299,7 @@ MODIFIES SQL DATA
ResultType: sql.NullString{String: "text", Valid: true},
Volatility: "v", IsStrict: false, IsLeakProof: false, IsSecurityDefiner: false,
PlannerSupport: plannerSupportValue, Config: `SET search_path TO '$user', 'public', 'abc"def'`, Cost: 100,
NumRows: 0, DataAccess: "n", Language: "plpgsql", ExecLocation: "a"}
NumRows: 0, DataAccess: "n", Language: "plpgsql", ExecLocation: "a", Parallel: proparallelValue}

Expect(results).To(HaveLen(1))
structmatcher.ExpectStructsToMatchExcluding(&results[0], &appendFunction, "Oid")
Expand Down Expand Up @@ -336,7 +338,7 @@ INSERT INTO public.tbl VALUES (b);
ResultType: sql.NullString{String: "", Valid: false},
Volatility: "v", IsSecurityDefiner: false, PlannerSupport: plannerSupportValue,
Config: "", Cost: 100, NumRows: 0, DataAccess: "c",
Language: "sql", ExecLocation: "a"}
Language: "sql", ExecLocation: "a", Parallel: proparallelValue}
secondProcedure := backup.Function{
Schema: "public", Name: "insert_more_data", Kind: "p", ReturnsSet: false, FunctionBody: `
INSERT INTO public.tbl VALUES (a);
Expand All @@ -347,7 +349,7 @@ INSERT INTO public.tbl VALUES (b);
ResultType: sql.NullString{String: "", Valid: false},
Volatility: "v", IsSecurityDefiner: false, PlannerSupport: plannerSupportValue,
Config: "", Cost: 100, NumRows: 0, DataAccess: "c",
Language: "sql", ExecLocation: "a"}
Language: "sql", ExecLocation: "a", Parallel: proparallelValue}

Expect(results).To(HaveLen(2))
structmatcher.ExpectStructsToMatchExcluding(&results[0], &firstProcedure, "Oid")
Expand Down

0 comments on commit 303871a

Please sign in to comment.