Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(list): fixed unit tests for listing non-exists file #452

Merged
merged 35 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e767ff9
fix(list): fixed unit tests for listing non-exists file
cnlangzi Oct 14, 2022
2e574d5
Merge branch 'master' into fix/throws_error_on_list
cnlangzi Oct 16, 2022
b477b92
fix(list): fixed unit tests for listing non-exists file
cnlangzi Oct 17, 2022
67fe04c
fix(list): fixed unit tests for listing non-exists file
cnlangzi Oct 17, 2022
a1bb4c2
fix(list): improved startUploadFeed
cnlangzi Oct 17, 2022
b973c2d
fix(list): removed deprecated ioutil.ReadDir
cnlangzi Oct 17, 2022
b2e45b3
fix(list): fixed unit tests for listing non-exists file
cnlangzi Oct 17, 2022
6035ee9
Merge branch 'master' into fix/throws_error_on_list
cnlangzi Oct 18, 2022
39d2452
fix(list): fixed unit tests for listing non-exists file
cnlangzi Oct 18, 2022
f1c40bf
fix(upload): disabled parallel feature on ffmpeg tests
cnlangzi Oct 18, 2022
aba085f
fix(upload): reverted parallel feature on ffmpeg tests
cnlangzi Oct 19, 2022
6673aad
fix(upload): fixed startUploadFeed
cnlangzi Oct 19, 2022
763c174
Merge branch 'master' into fix/throws_error_on_list
cnlangzi Oct 19, 2022
d20ebf1
fix(feed):improved logging for cmd
cnlangzi Oct 19, 2022
0ff4c4a
Merge branch 'master' into fix/throws_error_on_list
cnlangzi Oct 19, 2022
5f94188
fix(upload): added StartCommandWithStderr
cnlangzi Oct 19, 2022
d8611f3
fix(upload): added StartCommandWithStderr
cnlangzi Oct 20, 2022
929764a
fix(upload): added StartCommandWithStderr
cnlangzi Oct 20, 2022
ce1511b
fix(upload): added StartCommandWithStderr
cnlangzi Oct 20, 2022
dcf5aea
fix(upload): added StartCommandWithStderr
cnlangzi Oct 20, 2022
6e747cf
fix(upload): added StartCommandWithStderr
cnlangzi Oct 20, 2022
aec90af
fix(feed): enabled logging of ffmpeg
cnlangzi Oct 20, 2022
b665c25
fix(feed): enabled logging of youtube-dl
cnlangzi Oct 20, 2022
f2e1f83
fix(feed): improved getFeed
cnlangzi Oct 21, 2022
7f7e644
fix(feed): improved getFeed
cnlangzi Oct 21, 2022
284b6a9
fix(feed): improved getFeed
cnlangzi Oct 21, 2022
f83c1b6
fix(feed): improved getFeed
cnlangzi Oct 21, 2022
f7a9ea8
fix(feed): improved getFeed
cnlangzi Oct 21, 2022
4e2517f
fix(feed): improved getFeed
cnlangzi Oct 21, 2022
5d639eb
fix(feed): improved getFeed
cnlangzi Oct 21, 2022
e8af22c
fix(feed): reverted stream tests
cnlangzi Oct 21, 2022
0f6420d
fix(feed): disabled stream tests
cnlangzi Oct 21, 2022
a54d293
fix(alloction): fixed listAllWithWallet assertion
cnlangzi Oct 21, 2022
653f7d1
fix(feed): reverted --silent on feed tests
cnlangzi Oct 21, 2022
371368f
Merge branch 'master' into fix/throws_error_on_list
cnlangzi Oct 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions tests/cli_tests/zboxcli_file_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ func TestFileDelete(t *testing.T) {
"json": "",
}), true)

require.Nil(t, err, "List files returned nil", err, strings.Join(output, "\n"))
require.Len(t, output, 1, "Len of output is not enough")
require.Equal(t, "null", output[0], "Output is not 'null'", strings.Join(output, "\n"))
require.NotNil(t, err, strings.Join(output, "\n"))
require.Contains(t, strings.Join(output, "\n"), "Invalid path record not found")
}
})

Expand Down Expand Up @@ -220,9 +219,9 @@ func TestFileDelete(t *testing.T) {
"remotepath": remotepath,
"json": "",
}), true)
require.Nil(t, err, "List files failed", err, strings.Join(output, "\n"))
require.Len(t, output, 1)
require.Equal(t, "null", output[0], strings.Join(output, "\n"))
require.NotNil(t, err, strings.Join(output, "\n"))
require.Contains(t, strings.Join(output, "\n"), "Invalid path record not found")

})

t.Run("delete existing non-root directory should work", func(t *testing.T) {
Expand All @@ -248,9 +247,8 @@ func TestFileDelete(t *testing.T) {
"remotepath": remotepath,
"json": "",
}), true)
require.Nil(t, err, "List files failed", err, strings.Join(output, "\n"))
require.Len(t, output, 1)
require.Equal(t, "null", output[0], strings.Join(output, "\n"))
require.NotNil(t, err, strings.Join(output, "\n"))
require.Contains(t, strings.Join(output, "\n"), "Invalid path record not found")
})

t.Run("delete existing file with thumbnail should work", func(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions tests/cli_tests/zboxcli_file_rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ func TestFileRename(t *testing.T) { // nolint:gocyclo // team preference is to h
"remotepath": path.Join(remotePathPrefix, deleteFileNames[i]),
"json": "",
}), true)
require.Nil(t, err, "List files failed", err, strings.Join(output, "\n"))

require.NotNil(t, err)
require.Len(t, output, 1)
require.Equal(t, "null", output[0], strings.Join(output, "\n"))
require.Contains(t, strings.Join(output, "\n"), "error from server list response:", strings.Join(output, "\n"))
}
})

Expand Down
9 changes: 5 additions & 4 deletions tests/cli_tests/zboxcli_list_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,7 @@ func TestListFileSystem(t *testing.T) {
strings.Join(output, "\n"))
})

//FIXME: Listing a file in another allocation does not fail but returns no output see https://github.com/0chain/zboxcli/issues/246
t.Run("BROKEN List Files in Other's Wallet Should Fail but does not see zboxcli/issues/246", func(t *testing.T) {
t.Run("List Files in Other's Wallet Should Fail", func(t *testing.T) {
t.Parallel()

var otherAllocationID string
Expand Down Expand Up @@ -588,9 +587,11 @@ func TestListFileSystem(t *testing.T) {
"json": "",
"remotepath": remotepath,
}), false)
require.Nil(t, err, err)

require.NotNil(t, err)
require.Len(t, output, 1)
require.Equal(t, "null", output[0], strings.Join(output, "\n"))
require.Contains(t, strings.Join(output, "\n"), "error from server list response:", strings.Join(output, "\n"))

})

t.Run("List All Files Should Work On An Empty Allocation", func(t *testing.T) {
Expand Down
52 changes: 43 additions & 9 deletions tests/cli_tests/zboxcli_livestream_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli_tests

import (
"context"
"encoding/json"
"fmt"
"io/fs"
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestStreamUploadDownload(t *testing.T) {
require.Nil(t, err, "Error in creating the folders", localpath)
defer os.RemoveAll(localfolder)

err = startUploadFeed(t, "feed", configPath, createParams(map[string]interface{}{
err = startUploadFeed(t, configPath, "feed", localfolder, createParams(map[string]interface{}{
"allocation": allocationID,
"remotepath": remotepath,
"localpath": localpath,
Expand Down Expand Up @@ -124,7 +125,7 @@ func TestStreamUploadDownload(t *testing.T) {
require.Nil(t, err, "Error in creating the folders", localpath)
defer os.RemoveAll(localfolder)

err = startUploadFeed(t, configPath, "feed", createParams(map[string]interface{}{
err = startUploadFeed(t, configPath, "feed", localfolder, createParams(map[string]interface{}{
"allocation": allocationID,
"remotepath": remotepath,
"localpath": localpath,
Expand Down Expand Up @@ -193,7 +194,7 @@ func TestStreamUploadDownload(t *testing.T) {
require.Nil(t, err, "Error in creating the folders", localpath)
defer os.RemoveAll(localfolder)

err = startUploadFeed(t, configPath, "feed", createParams(map[string]interface{}{
err = startUploadFeed(t, configPath, "feed", localfolder, createParams(map[string]interface{}{
"allocation": allocationID,
"remotepath": remotepath,
"localpath": localpath,
Expand Down Expand Up @@ -264,7 +265,7 @@ func TestStreamUploadDownload(t *testing.T) {
require.Nil(t, err, "Error in creating the folders", localpath)
defer os.RemoveAll(localfolder)

err = startUploadFeed(t, configPath, "stream", createParams(map[string]interface{}{
err = startUploadFeed(t, configPath, "stream", localfolder, createParams(map[string]interface{}{
"allocation": allocationID,
"remotepath": remotepath,
"localpath": localpath,
Expand Down Expand Up @@ -331,7 +332,7 @@ func TestStreamUploadDownload(t *testing.T) {
require.Nil(t, err, "Error in creating the folders", localpath)
defer os.RemoveAll(localfolder)

err = startUploadFeed(t, configPath, "stream", createParams(map[string]interface{}{
err = startUploadFeed(t, configPath, "stream", localfolder, createParams(map[string]interface{}{
"allocation": allocationID,
"remotepath": remotepath,
"localpath": localpath,
Expand Down Expand Up @@ -399,7 +400,7 @@ func TestStreamUploadDownload(t *testing.T) {
require.Nil(t, err, "Error in creating the folders", localpath)
defer os.RemoveAll(localfolder)

err = startUploadFeed(t, configPath, "stream", createParams(map[string]interface{}{
err = startUploadFeed(t, configPath, "stream", localfolder, createParams(map[string]interface{}{
"allocation": allocationID,
"remotepath": remotepath,
"localpath": localpath,
Expand Down Expand Up @@ -450,14 +451,43 @@ func TestStreamUploadDownload(t *testing.T) {
// FIXME: Disabled for now due to process hanging
}

func startUploadFeed(t *testing.T, cmdName, cliConfigFilename, params string) error {
func startUploadFeed(t *testing.T, cliConfigFilename, cmdName, localFolder, params string) error {
t.Logf("Starting upload of live stream to zbox...")
commandString := fmt.Sprintf("./zbox %s %s --silent --wallet "+escapedTestName(t)+"_wallet.json"+" --configDir ./config --config "+cliConfigFilename, cmdName, params)
cmd, err := cliutils.StartCommand(t, commandString, 3, 15*time.Second)
require.Nil(t, err, "error in uploading a live feed")

// Need atleast 3-4 .ts files uploaded
cliutils.Wait(t, 30*time.Second)
ctx, cf := context.WithTimeout(context.TODO(), 1*time.Minute)
defer cf()

var done bool
for {

select {
case <-ctx.Done():
done = true
break
cnlangzi marked this conversation as resolved.
Show resolved Hide resolved
case <-time.After(5 * time.Second):
files, _ := os.ReadDir(localFolder)
c := 0
for _, file := range files {
if strings.HasSuffix(file.Name(), ".ts") {
c++
}
}

if c > 2 {
done = true
break
cnlangzi marked this conversation as resolved.
Show resolved Hide resolved
}
}

if done {
break
cnlangzi marked this conversation as resolved.
Show resolved Hide resolved
}

}

// Kills upload process as well as it's child processes
err = cmd.Process.Kill()
Expand All @@ -467,7 +497,8 @@ func startUploadFeed(t *testing.T, cmdName, cliConfigFilename, params string) er
func checkYoutubeFeedAvailabiity() (feed string, isStreamAvailable bool) {
feed = ""
const feed1 = `https://www.youtube.com/watch?v=Dx5qFachd3A`
const feed2 = `https://www.youtube.com/watch?v=21qNxnCS8WU`
const feed2 = `https://www.youtube.com/watch?v=fuXfT4Rv_WM`
const feed3 = `https://www.youtube.com/watch?v=oaSLqdnKniA`

for i := 1; i < 3; i++ {
var resp *http.Response
Expand All @@ -479,6 +510,9 @@ func checkYoutubeFeedAvailabiity() (feed string, isStreamAvailable bool) {
case 2:
resp, err = http.Get(feed2)
feed = feed2
case 3:
resp, err = http.Get(feed3)
feed = feed3
}
if err == nil && resp.StatusCode == 200 {
return feed, true
Expand Down
17 changes: 7 additions & 10 deletions tests/cli_tests/zboxcli_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,20 +719,17 @@ func TestSyncWithBlobbers(t *testing.T) {
"allocation": allocationID,
"localpath": localpath,
}, true)
require.Nil(t, err, "Error in syncing the folder: ", strings.Join(output, "\n"))

require.True(t,
strings.Contains(strings.Join(output, ""), "consensus_not_met"), strings.Join(output, "\n"))
require.NotNil(t, err)
require.Len(t, output, 2)
require.Contains(t, strings.Join(output, "\n"), "error from server list response:", strings.Join(output, "\n"))

// no file must be uploaded to allocation
output, err = listAll(t, configPath, allocationID, true)
require.Nil(t, err, "Error in listing the allocation files: ", strings.Join(output, "\n"))
require.Len(t, output, 1)

var files []climodel.AllocationFile
err = json.Unmarshal([]byte(output[0]), &files)
require.Nil(t, err, "Error deserializing JSON string `%s`: %v", strings.Join(output, "\n"), err)

require.Len(t, files, 0, "no file must be uploaded to allocation", files)
require.NotNil(t, err)
require.Len(t, output, 1)
require.Contains(t, strings.Join(output, "\n"), "error from server list response:", strings.Join(output, "\n"))
})

t.Run("Attempt to Sync to non-existing allocation must fail", func(t *testing.T) {
Expand Down
90 changes: 3 additions & 87 deletions tests/cli_tests/zboxcli_transfer_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,88 +370,6 @@ func TestTransferAllocation(t *testing.T) { // nolint:gocyclo // team preference
"download file - Unexpected output", strings.Join(output, "\n"))
})

// FIXME: New owner cannot download encrypted file after allocation ownership is transferred https://github.com/0chain/blobber/issues/711
t.Run("BROKEN transfer allocation and download encrypted file should work but does not see 0chain/blobber/issues/711", func(t *testing.T) {
t.Parallel()

allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": int64(204800),
})

ownerWallet, err := getWallet(t, configPath)
require.Nil(t, err, "Error occurred when retrieving owner wallet")

output, err := addCurator(t, createParams(map[string]interface{}{
"allocation": allocationID,
"curator": ownerWallet.ClientID,
}), true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 1, "add curator - Unexpected output", strings.Join(output, "\n"))
require.Equal(t, fmt.Sprintf("%s added %s as a curator to allocation %s", ownerWallet.ClientID, ownerWallet.ClientID, allocationID), output[0],
"add curator - Unexpected output", strings.Join(output, "\n"))

file := generateRandomTestFileName(t)
err = createFileWithSize(file, 25600) // cannot be a small file when uploading with encrypt
require.Nil(t, err)

filename := filepath.Base(file)
remotePath := "/child/" + filename

output, err = uploadFile(t, configPath, map[string]interface{}{
"allocation": allocationID,
"remotepath": remotePath,
"localpath": file,
"encrypt": "",
}, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 2, "upload file - Unexpected output", strings.Join(output, "\n"))
require.Equal(t, "Status completed callback. Type = application/octet-stream. Name = "+filepath.Base(file), output[1],
"upload file - Unexpected output", strings.Join(output, "\n"))

newOwner := escapedTestName(t) + "_NEW_OWNER"

output, err = registerWalletForName(t, configPath, newOwner)
require.Nil(t, err, "registering wallet failed", strings.Join(output, "\n"))

output, err = executeFaucetWithTokensForWallet(t, newOwner, configPath, 1)
require.Nil(t, err, "faucet execution failed for non-owner wallet", strings.Join(output, "\n"))

newOwnerWallet, err := getWalletForName(t, configPath, newOwner)
require.Nil(t, err, "Error occurred when retrieving new owner wallet")

output, err = transferAllocationOwnership(t, map[string]interface{}{
"allocation": allocationID,
"new_owner_key": newOwnerWallet.ClientPublicKey,
"new_owner": newOwnerWallet.ClientID,
}, true)
require.Nil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 1, "transfer allocation - Unexpected output", strings.Join(output, "\n"))
require.Equal(t, fmt.Sprintf("transferred ownership of allocation %s to %s", allocationID, newOwnerWallet.ClientID), output[0],
"transfer allocation - Unexpected output", strings.Join(output, "\n"))

transferred := pollForAllocationTransferToEffect(t, newOwner, allocationID)
require.True(t, transferred, "allocation was not transferred to new owner within time allotted")

output, err = readPoolLockWithWallet(t, newOwner, configPath, createParams(map[string]interface{}{
"tokens": 0.5,
}), true)
require.Nil(t, err, "Tokens could not be locked", strings.Join(output, "\n"))
require.Len(t, output, 1, "read pool lock - Unexpected output", strings.Join(output, "\n"))
require.Equal(t, "locked", output[0], "read pool lock - Unexpected output", strings.Join(output, "\n"))

downloadFilePath := strings.TrimSuffix(os.TempDir(), "/") + "/"
os.Remove(downloadFilePath + "/" + filename)

output, err = downloadFileForWallet(t, newOwner, configPath, createParams(map[string]interface{}{
"allocation": allocationID,
"localpath": downloadFilePath,
"remotepath": remotePath,
}), false)
require.NotNil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 2, "download file - Unexpected output", strings.Join(output, "\n"))
require.Equal(t, "Error in file operation: File content didn't match with uploaded file", output[1], "download file - Unexpected output", strings.Join(output, "\n"))
})

t.Run("transfer allocation and download with auth ticket should fail", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -549,7 +467,7 @@ func TestTransferAllocation(t *testing.T) { // nolint:gocyclo // team preference
require.NotNil(t, err, strings.Join(output, "\n"))
require.Len(t, output, 3, "download file - Unexpected output", strings.Join(output, "\n"))
aggregatedOutput := strings.ToLower(strings.Join(output, " "))
require.Contains(t, aggregatedOutput, "download failed")
require.Contains(t, aggregatedOutput, "failed")

/* Authticket is redundant for owner and collaborator
output, err = downloadFileForWallet(t, newOwner, configPath, createParams(map[string]interface{}{
Expand Down Expand Up @@ -912,13 +830,11 @@ func pollForAllocationTransferToEffect(t *testing.T, newOwner, allocationID stri
// this requires the allocation has file uploaded to work properly.
for {
// using `list all` to verify transfer as this check blobber content as opposed to `get allocation` which is based on sharder
output, err := listAllWithWallet(t, newOwner, configPath, allocationID, true)
require.Nil(t, err, "Unexpected list all failure %s", strings.Join(output, "\n"))
require.Len(t, output, 1)
output, _ := listAllWithWallet(t, newOwner, configPath, allocationID, true)

// if not empty, the transfer of allocation contents has occurred on blobbers.
// there is only one content expected so once it is no longer empty, transfer is deemed complete.
if output[0] != "[]" {
if len(output) == 1 && output[0] != "[]" {
return true
}

Expand Down