mirror of
https://github.com/jlelse/GoBlog
synced 2024-06-18 04:05:00 +00:00
31 lines
619 B
Go
31 lines
619 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func Test_localMediaStorage(t *testing.T) {
|
||
|
testDir := t.TempDir()
|
||
|
|
||
|
l := &localMediaStorage{
|
||
|
mediaURL: "https://example.com",
|
||
|
path: testDir,
|
||
|
}
|
||
|
|
||
|
testFileContent := "This is a test"
|
||
|
|
||
|
loc, err := l.save("test.txt", strings.NewReader(testFileContent))
|
||
|
require.Nil(t, err)
|
||
|
assert.Equal(t, "https://example.com/test.txt", loc)
|
||
|
|
||
|
file, err := os.ReadFile(filepath.Join(testDir, "test.txt"))
|
||
|
require.Nil(t, err)
|
||
|
assert.Equal(t, testFileContent, string(file))
|
||
|
}
|