github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/geo/geos/geos_test.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package geos 12 13 import ( 14 "testing" 15 16 "github.com/cockroachdb/errors" 17 "github.com/stretchr/testify/require" 18 ) 19 20 func TestInitGEOS(t *testing.T) { 21 t.Run("test no initGEOS paths", func(t *testing.T) { 22 _, _, err := initGEOS([]string{}) 23 require.Error(t, err) 24 }) 25 26 t.Run("test invalid initGEOS paths", func(t *testing.T) { 27 _, _, err := initGEOS([]string{"/invalid/path"}) 28 require.Error(t, err) 29 }) 30 31 t.Run("test valid initGEOS paths", func(t *testing.T) { 32 ret, loc, err := initGEOS(findGEOSLocations("")) 33 require.NoError(t, err) 34 require.NotEmpty(t, loc) 35 require.NotNil(t, ret) 36 }) 37 } 38 39 func TestEnsureInit(t *testing.T) { 40 // Fetch at least once. 41 _, err := ensureInit(EnsureInitErrorDisplayPublic, "") 42 require.NoError(t, err) 43 44 fakeErr := errors.Newf("contain path info do not display me") 45 defer func() { geosOnce.err = nil }() 46 47 geosOnce.err = fakeErr 48 _, err = ensureInit(EnsureInitErrorDisplayPrivate, "") 49 require.Contains(t, err.Error(), fakeErr.Error()) 50 51 _, err = ensureInit(EnsureInitErrorDisplayPublic, "") 52 require.Equal(t, errors.Newf("geos: this operation is not available").Error(), err.Error()) 53 }