41 lines
734 B
Go
41 lines
734 B
Go
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||
|
|
||
|
package transport
|
||
|
|
||
|
import (
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"net/url"
|
||
|
"testing"
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
var TempDir string
|
||
|
|
||
|
func TestMain(m *testing.M) {
|
||
|
var err error
|
||
|
TempDir, err = os.MkdirTemp("", "testtransportfile")
|
||
|
if err != nil || TempDir == "" {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
rc := m.Run()
|
||
|
|
||
|
os.RemoveAll(TempDir)
|
||
|
os.Exit(rc)
|
||
|
}
|
||
|
|
||
|
func TestNewTransportReader(t *testing.T) {
|
||
|
path := fmt.Sprintf("%s/foo", TempDir)
|
||
|
u, e := url.Parse(fmt.Sprintf("file://%s", path))
|
||
|
assert.Nil(t, e)
|
||
|
|
||
|
writeErr := os.WriteFile(path, []byte("test"), 0644)
|
||
|
assert.Nil(t, writeErr)
|
||
|
|
||
|
reader, err := NewReader(u)
|
||
|
assert.Nil(t, err)
|
||
|
assert.NotNil(t, reader)
|
||
|
}
|