remove invalid tests

move functions out of utils
address review comments
revert lockfile changes
This commit is contained in:
Niko Storni 2018-07-17 14:58:47 -04:00
parent dfa3bb1b19
commit f800e77e4c
No known key found for this signature in database
GPG key ID: F37FE63398800368
10 changed files with 41 additions and 148 deletions

30
Gopkg.lock generated
View file

@ -49,8 +49,8 @@
"service/s3/s3manager",
"service/sts"
]
revision = "fefacb6d45b233a9e20097a176c1c46e85a782d3"
version = "v1.14.25"
revision = "d2d4fca90395039f60821c231da759cab8f318c7"
version = "v1.14.4"
[[projects]]
branch = "master"
@ -63,7 +63,7 @@
"rpcclient",
"wire"
]
revision = "fdfc19097e7ac6b57035062056f5b7b4638b8898"
revision = "86fed781132ac890ee03e906e4ecd5d6fa180c64"
[[projects]]
branch = "master"
@ -79,7 +79,7 @@
"base58",
"bech32"
]
revision = "ab6388e0c60ae4834a1f57511e20c17b5f78be4b"
revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4"
[[projects]]
branch = "master"
@ -117,8 +117,8 @@
[[projects]]
name = "github.com/go-ini/ini"
packages = ["."]
revision = "af26abd521cd7697481572fdbc4a53cbea3dde1b"
version = "v1.38.0"
revision = "06f5f3d67269ccec1fe5fe4134ba6e982984f7f5"
version = "v1.37.0"
[[projects]]
name = "github.com/golang/protobuf"
@ -180,16 +180,16 @@
version = "v0.2.0"
[[projects]]
branch = "master"
name = "github.com/shopspring/decimal"
packages = ["."]
revision = "cd690d0c9e2447b1ef2a129a6b7b49077da89b8e"
version = "1.1.0"
revision = "19e3cb6c29303990525b56f51acf77c5630dd88a"
[[projects]]
branch = "master"
name = "github.com/sirupsen/logrus"
packages = ["."]
revision = "e54a77765aca7bbdd8e56c1c54f60579968b2dc9"
revision = "ea8897e79973357ba785ac2533559a6297e83c44"
[[projects]]
name = "github.com/spf13/cast"
@ -201,7 +201,7 @@
branch = "master"
name = "github.com/spf13/cobra"
packages = ["."]
revision = "a114f312e075f65bf30d6d9a1430113f857e543b"
revision = "1e58aa3361fd650121dceeedc399e7189c05674a"
[[projects]]
name = "github.com/spf13/pflag"
@ -229,7 +229,7 @@
"sha3",
"ssh/terminal"
]
revision = "a49355c7e3f8fe157a85be2f77e6e269a0f89602"
revision = "8ac0e0d97ce45cd83d1d7243c060cb8461dda5e9"
[[projects]]
branch = "master"
@ -240,7 +240,7 @@
"html",
"html/atom"
]
revision = "cffdcf672aee934982473246bc7e9a8ba446aa9b"
revision = "db08ff08e8622530d9ed3a0e8ac279f6d4c02196"
[[projects]]
branch = "master"
@ -249,7 +249,7 @@
"unix",
"windows"
]
revision = "1b2967e3c290b7c545b3db0deeda16e9be4f98a2"
revision = "bff228c7b664c5fce602223a05fb708fd8654986"
[[projects]]
branch = "master"
@ -261,7 +261,7 @@
"googleapi/transport",
"youtube/v3"
]
revision = "1d2d9cc0ae74226e8076e2a87e211c8fea38a160"
revision = "ef86ce4234efee96020bde00391d6a9cfae66561"
[[projects]]
name = "gopkg.in/nullbio/null.v6"
@ -272,6 +272,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "16b411a37ad7df581529665691944d63a8ff23573acfdd37c3a3391ea4bde746"
inputs-digest = "adebfeec40e94ad17cba1f18d8f47da60af4106a50386ebce51650d036e3d4ac"
solver-name = "gps-cdcl"
solver-version = 1

View file

@ -1,37 +0,0 @@
package cmd
import (
"fmt"
"testing"
)
/*
func TestMain(m *testing.M) {
APIURL = os.Getenv("LBRY_API")
APIToken = os.Getenv("LBRY_API_TOKEN")
}
*/
func TestFetchChannels(t *testing.T) {
res, err := fetchChannels(StatusQueued)
if err != nil {
t.Error(err)
}
if res == nil {
t.Error("empty response")
}
fmt.Println(res)
}
// warning this test will actually set sync_server on the db entry for this test channel (mine)
// such field should be reset to null if the test must be run on a different machine (different hostname)
// and obviously the auth token must be appropriate
func TestSetChannelSyncStatus(t *testing.T) {
err := setChannelSyncStatus("UCNQfQvFMPnInwsU_iGYArJQ", StatusSyncing)
if err != nil {
t.Error(err)
}
err = setChannelSyncStatus("UCNQfQvFMPnInwsU_iGYArJQ", StatusQueued)
if err != nil {
t.Error(err)
}
}

View file

@ -1,18 +0,0 @@
package util
import "syscall"
// GetUsedSpace returns a value between 0 and 1, with 0 being completely empty and 1 being full, for the disk that holds the provided path
func GetUsedSpace(path string) (float32, error) {
var stat syscall.Statfs_t
err := syscall.Statfs(path, &stat)
if err != nil {
return 0, err
}
// Available blocks * size per block = available space in bytes
all := stat.Blocks * uint64(stat.Bsize)
free := stat.Bfree * uint64(stat.Bsize)
used := all - free
return float32(used) / float32(all), nil
}

View file

@ -1,21 +0,0 @@
package util
import (
"os/user"
"testing"
)
func TestGetUsedSpace(t *testing.T) {
usr, err := user.Current()
if err != nil {
t.Error(err)
}
usedPctile, err := GetUsedSpace(usr.HomeDir + "/.lbrynet/blobfiles/")
if err != nil {
t.Error(err)
}
if usedPctile > 1 {
t.Errorf("over 1: %.2f", usedPctile)
}
t.Logf("used space: %.2f", usedPctile)
}

View file

@ -1,20 +0,0 @@
package util
import (
"os"
"testing"
)
func TestSendToSlack(t *testing.T) {
slackToken := os.Getenv("SLACK_TOKEN")
if slackToken == "" {
t.Error("A slack token was not provided")
}
host, err := os.Hostname()
if err != nil {
host = "ytsync-unknown"
}
InitSlack(os.Getenv("SLACK_TOKEN"), os.Getenv("SLACK_CHANNEL"), host)
SendInfoToSlack("This is a test :) Working %.2f%%", 1.01*100)
SendErrorToSlack("This is a test :) Working %.2f%%", 0.01*100)
}

View file

@ -11,7 +11,8 @@ func InSlice(str string, values []string) bool {
return false
}
func InSliceContains(fullString string, candidates []string) bool {
// ContainedInSlice returns true if fullstring is contained within any element of the candidates slice. False otherwise
func ContainedInSlice(fullString string, candidates []string) bool {
for _, v := range candidates {
if strings.Contains(fullString, v) {
return true

View file

@ -12,6 +12,8 @@ import (
"time"
"syscall"
"github.com/lbryio/lbry.go/errors"
"github.com/lbryio/lbry.go/null"
"github.com/lbryio/lbry.go/util"
@ -214,7 +216,7 @@ func (s SyncManager) Start() error {
"NotEnoughFunds",
"no space left on device",
}
if util.InSliceContains(err.Error(), fatalErrors) {
if util.ContainedInSlice(err.Error(), fatalErrors) {
return errors.Prefix("@Nikooo777 this requires manual intervention! Exiting...", err)
}
util.SendInfoToSlack("A non fatal error was reported by the sync process. %s\nContinuing...", err.Error())
@ -243,7 +245,7 @@ func (s SyncManager) checkUsedSpace() error {
if err != nil {
return err
}
usedPctile, err := util.GetUsedSpace(usr.HomeDir + "/.lbrynet/blobfiles/")
usedPctile, err := GetUsedSpace(usr.HomeDir + "/.lbrynet/blobfiles/")
if err != nil {
return err
}
@ -253,3 +255,18 @@ func (s SyncManager) checkUsedSpace() error {
util.SendInfoToSlack("disk usage: %.1f%%", usedPctile*100)
return nil
}
// GetUsedSpace returns a value between 0 and 1, with 0 being completely empty and 1 being full, for the disk that holds the provided path
func GetUsedSpace(path string) (float32, error) {
var stat syscall.Statfs_t
err := syscall.Statfs(path, &stat)
if err != nil {
return 0, err
}
// Available blocks * size per block = available space in bytes
all := stat.Blocks * uint64(stat.Bsize)
free := stat.Bfree * uint64(stat.Bsize)
used := all - free
return float32(used) / float32(all), nil
}

View file

@ -131,7 +131,7 @@ func (v YoutubeVideo) delete() error {
videoPath := v.getFilename()
err := os.Remove(videoPath)
if err != nil {
log.Debugln(errors.Prefix("delete error", err))
log.Errorln(errors.Prefix("delete error", err))
return err
}
log.Debugln(v.id + " deleted from disk (" + videoPath + ")")

View file

@ -100,7 +100,7 @@ func (s *Sync) FullCycle() (e error) {
noFailConditions := []string{
"this youtube channel is being managed by another server",
}
if util.InSliceContains(e.Error(), noFailConditions) {
if util.ContainedInSlice(e.Error(), noFailConditions) {
return
}
err := s.Manager.setChannelSyncStatus(s.YoutubeChannelID, StatusFailed)
@ -219,7 +219,7 @@ func (s *Sync) doSync() error {
err = s.walletSetup()
if err != nil {
return errors.Err("Initial wallet setup failed! Manual Intervention is required. Reason: %v", err)
return errors.Prefix("Initial wallet setup failed! Manual Intervention is required.", err)
}
if s.StopOnError {
@ -281,7 +281,7 @@ func (s *Sync) startWorker(workerNum int) {
"NotEnoughFunds",
"Cannot publish using channel",
}
if util.InSliceContains(err.Error(), fatalErrors) || s.StopOnError {
if util.ContainedInSlice(err.Error(), fatalErrors) || s.StopOnError {
s.grp.Stop()
} else if s.MaxTries > 1 {
errorsNoRetry := []string{
@ -296,7 +296,7 @@ func (s *Sync) startWorker(workerNum int) {
"Client.Timeout exceeded while awaiting headers)",
"video is bigger than 2GB, skipping for now",
}
if util.InSliceContains(err.Error(), errorsNoRetry) {
if util.ContainedInSlice(err.Error(), errorsNoRetry) {
log.Println("This error should not be retried at all")
} else if tryCount < s.MaxTries {
if strings.Contains(err.Error(), "txn-mempool-conflict") ||
@ -369,9 +369,6 @@ func (s *Sync) enqueueYoutubeVideos() error {
}
for _, item := range playlistResponse.Items {
// todo: there's thumbnail info here. why did we need lambda???
// because when videos are taken down from youtube, the thumb is gone too
// normally we'd send the video into the channel here, but youtube api doesn't have sorting
// so we have to get ALL the videos, then sort them, then send them in
videos = append(videos, sources.NewYoutubeVideo(s.videoDirectory, item.Snippet))

View file

@ -1,26 +0,0 @@
package ytsync
import (
"testing"
)
func TestWaitForDaemonProcess(t *testing.T) {
/*
err := startDaemonViaSystemd()
if err != nil {
t.Fail()
}
log.Infoln("Waiting 5 seconds for the daemon to start...")
time.Sleep(5 * time.Second)
err = stopDaemonViaSystemd()
if err != nil {
t.Fail()
}
*/
//start lbrynet before running this test
// stop lbrynet while running this test
err := waitForDaemonProcess(100)
if err != nil {
t.Fail()
}
}