Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
porjo committed Oct 12, 2023
1 parent 9be4941 commit f4020ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
3 changes: 1 addition & 2 deletions cmd/youtubeuploader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ func main() {
ShowAppVersion: *showAppVersion,
Chunksize: *chunksize,
NotifySubscribers: *notifySubscribers,
Debug: *debug,
SendFileName: *sendFileName,
}

config.Logger = utils.NewLogger(config.Debug)
config.Logger = utils.NewLogger(*debug)

config.Logger.Debugf("Youtubeuploader version: %s\n", appVersion)

Expand Down
1 change: 0 additions & 1 deletion files.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type Config struct {
ShowAppVersion bool
Chunksize int
NotifySubscribers bool
Debug bool
SendFileName bool

Logger utils.Logger
Expand Down
40 changes: 17 additions & 23 deletions test/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"os"
"testing"
"time"

yt "github.com/porjo/youtubeuploader"
"github.com/porjo/youtubeuploader/internal/limiter"
Expand Down Expand Up @@ -106,38 +107,20 @@ func TestMain(m *testing.M) {
transport = &mockTransport{url: url}

config = yt.Config{}
config.Logger = utils.NewLogger(true)
//config.Logger = utils.NewLogger(true)
config.Logger = utils.NewLogger(false)
config.Filename = "test.mp4"
config.Debug = true

ret := m.Run()

os.Exit(ret)
}

/*
func TestBasic(t *testing.T) {
t.Logf("File size %d", fileSize)
transport, err := limiter.NewLimitTransport(config.Logger, transport, limiter.LimitRange{}, fileSize, 0)
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
videoReader := &mockReader{fileSize: fileSize}
defer videoReader.Close()
err = yt.Run(ctx, transport, config, videoReader)
if err != nil {
log.Fatal(err)
}
}
*/

func TestRateLimit(t *testing.T) {

rateLimit := int(fileSize / 125 / 4)
runTimeWant := 2

rateLimit := int(fileSize / 125 / runTimeWant)

t.Logf("File size %d bytes", fileSize)
t.Logf("Ratelimit %d Kbps", rateLimit)
Expand All @@ -150,8 +133,19 @@ func TestRateLimit(t *testing.T) {
videoReader := &mockReader{fileSize: fileSize}
defer videoReader.Close()

start := time.Now()
err = yt.Run(ctx, transport, config, videoReader)
if err != nil {
log.Fatal(err)
}

runTimeGot := time.Since(start)
t.Logf("run time: %s\n", runTimeGot)

// Allow runtime 100ms either side
startLimit := time.Duration(runTimeWant*1000-100) * time.Millisecond
endLimit := time.Duration(runTimeWant*1000+100) * time.Millisecond
if runTimeGot < startLimit || runTimeGot > endLimit {
t.Fatalf("run time took longer/shorter than expected: %s", runTimeGot)
}
}

0 comments on commit f4020ba

Please sign in to comment.