Perform client version validation before executing pg_dump command (#614)
* Add func to parse out pg_dump version * Perform client vs server version checking before dump exports * Fix dump tests * Add extra test to validate against empty server version * Fix attachment filenames cleanup function * Add extra test * Fix small typos in comments * Drop third-party package to deal with versions * Tweak the pg dump incompatibility error message * Run CI on pull requests
This commit is contained in:
@@ -48,3 +48,69 @@ func TestDetectServerType(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectDumpVersion(t *testing.T) {
|
||||
examples := []struct {
|
||||
input string
|
||||
match bool
|
||||
version string
|
||||
}{
|
||||
{"", false, ""},
|
||||
{"pg_dump (PostgreSQL) 9.6", true, "9.6"},
|
||||
{"pg_dump 10", true, "10"},
|
||||
{"pg_dump (PostgreSQL) 14.5 (Homebrew)", true, "14.5"},
|
||||
}
|
||||
|
||||
for _, ex := range examples {
|
||||
t.Run("input:"+ex.input, func(t *testing.T) {
|
||||
match, version := detectDumpVersion(ex.input)
|
||||
|
||||
assert.Equal(t, ex.match, match)
|
||||
assert.Equal(t, ex.version, version)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMajorMinorVersion(t *testing.T) {
|
||||
examples := []struct {
|
||||
input string
|
||||
major int
|
||||
minor int
|
||||
}{
|
||||
{"", 0, 0},
|
||||
{" ", 0, 0},
|
||||
{"0", 0, 0},
|
||||
{"9.6", 9, 6},
|
||||
{"9.6.1.1", 9, 6},
|
||||
{"10", 10, 0},
|
||||
{"10.1 ", 10, 1},
|
||||
}
|
||||
|
||||
for _, ex := range examples {
|
||||
t.Run(ex.input, func(t *testing.T) {
|
||||
major, minor := getMajorMinorVersion(ex.input)
|
||||
assert.Equal(t, ex.major, major)
|
||||
assert.Equal(t, ex.minor, minor)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckVersionRequirement(t *testing.T) {
|
||||
examples := []struct {
|
||||
client string
|
||||
server string
|
||||
result bool
|
||||
}{
|
||||
{"", "", true},
|
||||
{"0", "0", true},
|
||||
{"9.6", "9.7", false},
|
||||
{"9.6.10", "9.6.25", true},
|
||||
{"10.0", "10.1", true},
|
||||
{"10.5", "10.1", true},
|
||||
{"14.5", "15.1", false},
|
||||
}
|
||||
|
||||
for _, ex := range examples {
|
||||
assert.Equal(t, ex.result, checkVersionRequirement(ex.client, ex.server))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user