...

Source file src/github.com/fergusstrange/embedded-postgres/version_strategy_test.go

Documentation: github.com/fergusstrange/embedded-postgres

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

View as plain text