"Fossies" - the Fresh Open Source Software Archive

Member "geoipupdate-4.3.0/pkg/geoipupdate/database/writer_test.go" (16 Apr 2020, 1141 Bytes) of package /linux/misc/geoipupdate-4.3.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "writer_test.go": 4.1.5_vs_4.2.0.

    1 package database
    2 
    3 import (
    4     "github.com/stretchr/testify/assert"
    5     "github.com/stretchr/testify/require"
    6     "io/ioutil"
    7     "os"
    8     "path/filepath"
    9     "testing"
   10 )
   11 
   12 func TestCreateLockFile(t *testing.T) {
   13     tests := []struct {
   14         Description   string
   15         LockFilename  string
   16         ExpectedError string
   17     }{
   18         {
   19             Description:   "Database shouldn't have errors with good file paths",
   20             LockFilename:  ".geoipupdate.lock",
   21             ExpectedError: "",
   22         },
   23         {
   24             Description:   "Database should fail to build with bad file path",
   25             LockFilename:  "bad/file/path.geoipupdate.lock",
   26             ExpectedError: `database directory is not available`,
   27         },
   28     }
   29 
   30     for _, test := range tests {
   31         t.Run(test.Description, func(t *testing.T) {
   32             tempDir, err := ioutil.TempDir("", "gutest-")
   33             require.NoError(t, err)
   34             err = os.RemoveAll(tempDir)
   35             require.NoError(t, err)
   36             _, err = CreateLockFile(filepath.Join(tempDir, test.LockFilename), false)
   37             if err != nil {
   38                 // regex because some errors have filenames.
   39                 assert.Regexp(t, test.ExpectedError, err.Error(), test.Description)
   40             } else {
   41                 require.Equal(t, test.ExpectedError, "", test.Description)
   42             }
   43         })
   44     }
   45 }