github.com/k0marov/go-socnet@v0.0.0-20220715154813-90d07867c782/features/profiles/store/file_storage/file_storage_test.go (about)

     1  package file_storage_test
     2  
     3  import (
     4  	"github.com/k0marov/go-socnet/core/general/core_values/ref"
     5  	. "github.com/k0marov/go-socnet/core/helpers/test_helpers"
     6  	"testing"
     7  
     8  	"github.com/k0marov/go-socnet/features/profiles/store/file_storage"
     9  )
    10  
    11  func TestAvatarFileCreator(t *testing.T) {
    12  	t.Run("should forward the call to static file creator with proper args", func(t *testing.T) {
    13  		tUserId := RandomString()
    14  		tData := []byte(RandomString())
    15  		tDataRef, _ := ref.NewRef(&tData)
    16  
    17  		expectedDir := file_storage.ProfilePrefix + tUserId
    18  		expectedName := file_storage.AvatarFileName
    19  
    20  		wantPath := RandomString()
    21  		wantErr := RandomError()
    22  
    23  		staticFileCreator := func(data ref.Ref[[]byte], dir, name string) (string, error) {
    24  			if data == tDataRef && dir == expectedDir && name == expectedName {
    25  				return wantPath, wantErr
    26  			}
    27  			panic("called with unexpected args")
    28  		}
    29  		sut := file_storage.NewAvatarFileCreator(staticFileCreator)
    30  		path, err := sut(tDataRef, tUserId)
    31  		AssertError(t, err, wantErr)
    32  		Assert(t, path, wantPath, "returned path")
    33  	})
    34  }