81ba6ab6f0
* feat: lp mig - first few steps * lp mig: default tasks * code comments * docs * lp-mig-progress * shared * comments and todos * fix: curio: rename lotus-provider to curio (#11645) * rename provider to curio * install gotext * fix lint errors, mod tidy * fix typo * fix API_INFO and add gotext to circleCI * add back gotext * add gotext after remerge * lp: channels doc * finish easy-migration TODOs * out generate * merging and more renames * avoid make-all * minor doc stuff * cu: make gen * make gen fix * make gen * tryfix * go mod tidy * minor ez migration fixes * ez setup - ui cleanups * better error message * guided setup colors * better path to saveconfigtolayer * loadconfigwithupgrades fix * readMiner oops * guided - homedir * err if miner is running * prompt error should exit * process already running, miner_id sectors in migration * dont prompt for language a second time * check miner stopped * unlock repo * render and sql oops * curio easyMig - some fixes * easyMigration runs successfully * lint * review fixes * fix backup path * fixes1 * fixes2 * fixes 3 --------- Co-authored-by: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Co-authored-by: LexLuthr <lexluthr@protocol.ai>
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package seal
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestUrlPieceReader_Read tests various scenarios of reading data from UrlPieceReader
|
|
func TestUrlPieceReader_Read(t *testing.T) {
|
|
// Create a test server
|
|
testData := "This is a test string."
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
_, err := io.WriteString(w, testData)
|
|
require.NoError(t, err)
|
|
}))
|
|
defer ts.Close()
|
|
|
|
tests := []struct {
|
|
name string
|
|
rawSize int64
|
|
expected string
|
|
expectError bool
|
|
expectEOF bool
|
|
}{
|
|
{"ReadExact", int64(len(testData)), testData, false, true},
|
|
{"ReadLess", 10, testData[:10], false, false},
|
|
{"ReadMore", int64(len(testData)) + 10, "", true, false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
reader := UrlPieceReader{
|
|
Url: ts.URL,
|
|
RawSize: tt.rawSize,
|
|
}
|
|
buffer, err := io.ReadAll(&reader)
|
|
if err != nil {
|
|
if (err != io.EOF && !tt.expectError) || (err == io.EOF && !tt.expectEOF) {
|
|
t.Errorf("Read() error = %v, expectError %v, expectEOF %v", err, tt.expectError, tt.expectEOF)
|
|
}
|
|
} else {
|
|
if got := string(buffer); got != tt.expected {
|
|
t.Errorf("Read() got = %v, expected %v", got, tt.expected)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestUrlPieceReader_Read_Error tests the error handling of UrlPieceReader
|
|
func TestUrlPieceReader_Read_Error(t *testing.T) {
|
|
// Simulate a server that returns an error
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
http.Error(w, "error", http.StatusInternalServerError)
|
|
}))
|
|
defer ts.Close()
|
|
|
|
reader := UrlPieceReader{
|
|
Url: ts.URL,
|
|
RawSize: 100,
|
|
}
|
|
buffer := make([]byte, 200)
|
|
|
|
_, err := reader.Read(buffer)
|
|
if err == nil {
|
|
t.Errorf("Expected an error, but got nil")
|
|
}
|
|
}
|