github.com/weaviate/weaviate@v1.24.6/modules/backup-filesystem/backup_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package modstgfs
    13  
    14  import (
    15  	"context"
    16  	"os"
    17  	"path/filepath"
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  )
    22  
    23  func TestBackend_StoreBackup(t *testing.T) {
    24  	backupRelativePath := filepath.Join("./backups", "some", "nested", "dir")
    25  	backupAbsolutePath := t.TempDir()
    26  
    27  	ctx := context.Background()
    28  
    29  	t.Run("fails init fs module with empty backup path", func(t *testing.T) {
    30  		module := New()
    31  		err := module.initBackupBackend(ctx, "")
    32  
    33  		assert.NotNil(t, err)
    34  		assert.Contains(t, err.Error(), "empty backup path provided")
    35  	})
    36  
    37  	t.Run("fails init fs module with relative backup path", func(t *testing.T) {
    38  		module := New()
    39  		err := module.initBackupBackend(ctx, backupRelativePath)
    40  
    41  		assert.NotNil(t, err)
    42  		assert.Contains(t, err.Error(), "relative backup path provided")
    43  	})
    44  
    45  	t.Run("inits backup module with absolute backup path", func(t *testing.T) {
    46  		module := New()
    47  		err := module.initBackupBackend(ctx, backupAbsolutePath)
    48  
    49  		assert.Nil(t, err)
    50  
    51  		_, err = os.Stat(backupAbsolutePath)
    52  		assert.Nil(t, err)
    53  	})
    54  }