forked from fergusstrange/embedded-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_strategy_test.go
149 lines (132 loc) · 4.18 KB
/
version_strategy_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package embeddedpostgres
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_DefaultVersionStrategy_AllGolangDistributions(t *testing.T) {
allGolangDistributions := map[string][]string{
"aix/ppc64": {"aix", "ppc64"},
"android/386": {"android", "386"},
"android/amd64": {"android", "amd64"},
"android/arm": {"android", "arm"},
"android/arm64": {"android", "arm64"},
"darwin/amd64": {"darwin", "amd64"},
"darwin/arm64": {"darwin", "amd64"},
"dragonfly/amd64": {"dragonfly", "amd64"},
"freebsd/386": {"freebsd", "386"},
"freebsd/amd64": {"freebsd", "amd64"},
"freebsd/arm": {"freebsd", "arm"},
"freebsd/arm64": {"freebsd", "arm64"},
"illumos/amd64": {"illumos", "amd64"},
"js/wasm": {"js", "wasm"},
"linux/386": {"linux", "386"},
"linux/amd64": {"linux", "amd64"},
"linux/arm": {"linux", "arm"},
"linux/arm64": {"linux", "arm64v8"},
"linux/mips": {"linux", "mips"},
"linux/mips64": {"linux", "mips64"},
"linux/mips64le": {"linux", "mips64le"},
"linux/mipsle": {"linux", "mipsle"},
"linux/ppc64": {"linux", "ppc64"},
"linux/ppc64le": {"linux", "ppc64le"},
"linux/riscv64": {"linux", "riscv64"},
"linux/s390x": {"linux", "s390x"},
"netbsd/386": {"netbsd", "386"},
"netbsd/amd64": {"netbsd", "amd64"},
"netbsd/arm": {"netbsd", "arm"},
"netbsd/arm64": {"netbsd", "arm64"},
"openbsd/386": {"openbsd", "386"},
"openbsd/amd64": {"openbsd", "amd64"},
"openbsd/arm": {"openbsd", "arm"},
"openbsd/arm64": {"openbsd", "arm64"},
"plan9/386": {"plan9", "386"},
"plan9/amd64": {"plan9", "amd64"},
"plan9/arm": {"plan9", "arm"},
"solaris/amd64": {"solaris", "amd64"},
"windows/386": {"windows", "386"},
"windows/amd64": {"windows", "amd64"},
"windows/arm": {"windows", "arm"},
}
versionDifferences := map[PostgresVersion]map[string][]string{
PostgresVersion("14.0.0"): {},
PostgresVersion("14.1.0"): {},
PostgresVersion("14.2.0"): {"darwin/arm64": {"darwin", "arm64v8"}},
V14: {"darwin/arm64": {"darwin", "arm64v8"}},
}
defaultConfig := DefaultConfig()
for version, differences := range versionDifferences {
defaultConfig.version = version
for dist, expected := range allGolangDistributions {
dist := dist
expected := expected
if override, ok := differences[dist]; ok {
expected = override
}
t.Run(fmt.Sprintf("DefaultVersionStrategy_%s", dist), func(t *testing.T) {
osArch := strings.Split(dist, "/")
operatingSystem, architecture, postgresVersion := defaultVersionStrategy(
defaultConfig,
osArch[0],
osArch[1],
linuxMachineName,
func() bool {
return false
})()
assert.Equal(t, expected[0], operatingSystem)
assert.Equal(t, expected[1], architecture)
assert.Equal(t, version, postgresVersion)
})
}
}
}
func Test_DefaultVersionStrategy_Linux_ARM32V6(t *testing.T) {
operatingSystem, architecture, postgresVersion := defaultVersionStrategy(
DefaultConfig(),
"linux",
"arm",
func() string {
return "armv6l"
}, func() bool {
return false
})()
assert.Equal(t, "linux", operatingSystem)
assert.Equal(t, "arm32v6", architecture)
assert.Equal(t, V14, postgresVersion)
}
func Test_DefaultVersionStrategy_Linux_ARM32V7(t *testing.T) {
operatingSystem, architecture, postgresVersion := defaultVersionStrategy(
DefaultConfig(),
"linux",
"arm",
func() string {
return "armv7l"
}, func() bool {
return false
})()
assert.Equal(t, "linux", operatingSystem)
assert.Equal(t, "arm32v7", architecture)
assert.Equal(t, V14, postgresVersion)
}
func Test_DefaultVersionStrategy_Linux_Alpine(t *testing.T) {
operatingSystem, architecture, postgresVersion := defaultVersionStrategy(
DefaultConfig(),
"linux",
"amd64",
func() string {
return ""
},
func() bool {
return true
},
)()
assert.Equal(t, "linux", operatingSystem)
assert.Equal(t, "amd64-alpine", architecture)
assert.Equal(t, V14, postgresVersion)
}
func Test_DefaultVersionStrategy_shouldUseAlpineLinuxBuild(t *testing.T) {
assert.NotPanics(t, func() {
shouldUseAlpineLinuxBuild()
})
}