|
| 1 | +package collect |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | + "go.undefinedlabs.com/scopeagent" |
| 9 | +) |
| 10 | + |
| 11 | +func Test_parsePostgresVersion(t *testing.T) { |
| 12 | + tests := []struct { |
| 13 | + postgresVersion string |
| 14 | + expect string |
| 15 | + }{ |
| 16 | + { |
| 17 | + // docker run -d --name pgnine -e POSTGRES_PASSWORD=password postgres:9 |
| 18 | + postgresVersion: "PostgreSQL 9.6.17 on x86_64-pc-linux-gnu (Debian 9.6.17-2.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit", |
| 19 | + expect: "9.6.17", |
| 20 | + }, |
| 21 | + { |
| 22 | + // docker run -d --name pgten -e POSTGRES_PASSWORD=password postgres:10 |
| 23 | + postgresVersion: "PostgreSQL 10.12 (Debian 10.12-2.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit", |
| 24 | + expect: "10.12", |
| 25 | + }, |
| 26 | + { |
| 27 | + // docker run -d --name pgeleven -e POSTGRES_PASSWORD=password postgres:11 |
| 28 | + postgresVersion: "PostgreSQL 11.7 (Debian 11.7-2.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit", |
| 29 | + expect: "11.7", |
| 30 | + }, |
| 31 | + { |
| 32 | + // docker run -d --name pgtwelve -e POSTGRES_PASSWORD=password postgres:12 |
| 33 | + postgresVersion: "PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit", |
| 34 | + expect: "12.2", |
| 35 | + }, |
| 36 | + } |
| 37 | + for _, test := range tests { |
| 38 | + t.Run(test.postgresVersion, func(t *testing.T) { |
| 39 | + scopetest := scopeagent.StartTest(t) |
| 40 | + defer scopetest.End() |
| 41 | + |
| 42 | + req := require.New(t) |
| 43 | + actual, err := parsePostgresVersion(test.postgresVersion) |
| 44 | + req.NoError(err) |
| 45 | + |
| 46 | + assert.Equal(t, test.expect, actual) |
| 47 | + |
| 48 | + }) |
| 49 | + } |
| 50 | +} |
0 commit comments