Skip to content

Instantly share code, notes, and snippets.

@MSevey
Created December 3, 2019 22:38
Show Gist options
  • Save MSevey/ca3d08b9cba30f55fba30ea68de2e159 to your computer and use it in GitHub Desktop.
Save MSevey/ca3d08b9cba30f55fba30ea68de2e159 to your computer and use it in GitHub Desktop.
This is an example of a simple upload and download test using the siatest package
// TestSiaTest is an example of how to structure a test using the siatest
// package
//
// The testnodes created with the TestGroup can access all the client
// package methods as well as a number of helper siatest methods for common
// tasks.
func TestSiaTest(t *testing.T) {
// These integration tests can take some time and so should be run with a
// longer timeout
if testing.Short() {
t.SkipNow()
}
// Running these tests in parallel can help speed up the pipeline
t.Parallel()
// Define your group parameters. Below are default values that should work
// for most cases
groupParams := siatest.GroupParams{
Hosts: 5,
Renters: 1,
Miners: 1,
}
// Define the directory to store the test data
testDir := renterTestDir(t.Name()) // NOTE: this should be updated to fit your projects needs
// Create Test Group
tg, err := siatest.NewGroupFromTemplate(testDir, groupParams)
if err != nil {
t.Fatal(err)
}
// Close the testgroup at the end of the test
defer func() {
if err := tg.Close(); err != nil {
t.Fatal(err)
}
}()
// Below is an example of a simple upload and download test
//
// Grab the first of the group's renters
renter := tg.Renters()[0]
// Upload file, creating a piece for each host in the group
dataPieces := uint64(1)
parityPieces := uint64(len(tg.Hosts())) - dataPieces
fileSize := siatest.Fuzz()
localFile, remoteFile, err := renter.UploadNewFileBlocking(fileSize, dataPieces, parityPieces, false)
if err != nil {
t.Fatal("Failed to upload a file for testing: ", err)
}
// Download the file synchronously to a file on disk
uid, lf, err = renter.DownloadToDisk(remoteFile, false)
if err != nil {
t.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment