Example #1
0
func TestChainsNewDirGenCustomFile(t *testing.T) {
	defer tests.RemoveAllContainers()

	const (
		chain    = "test-dir-gen"
		file     = "file.file"
		contents = "test contents"
	)

	dir := filepath.Join(common.DataContainersPath, chain)
	if err := os.MkdirAll(dir, 0700); err != nil {
		t.Fatalf("could not create a directory %q: %v", dir, err)
	}
	if err := tests.FakeDefinitionFile(filepath.Join(common.DataContainersPath, chain), file, contents); err != nil {
		t.Fatalf("could not create a test file %q: %v", file, err)
	}

	do := def.NowDo()
	do.GenesisFile = filepath.Join(common.ChainsPath, "default", "genesis.json")
	do.Name = chain
	do.Path = dir
	do.Operations.ContainerNumber = 1
	do.Operations.PublishAllPorts = true
	if err := NewChain(do); err != nil {
		t.Fatalf("expected a new chain to be created, got %v", err)
	}

	args := []string{"cat", filepath.Join(common.ErisContainerRoot, file+".toml")}
	if out := exec(t, chain, args); out != contents {
		t.Fatalf("expected file contents, got %q", out)
	}
}
Example #2
0
func TestPutFiles(t *testing.T) {
	var (
		content  = "test contents"
		filename = filepath.Join(erisDir, "test-file.toml")
	)
	tests.FakeDefinitionFile(erisDir, "test-file", content)

	do := definitions.NowDo()
	do.Name = filename
	log.WithField("=>", do.Name).Info("Putting file (from tests)")

	hash := "QmcJdniiSKMp5az3fJvkbJTANd7bFtDoUkov3a8pkByWkv"

	// Fake IPFS server.
	os.Setenv("ERIS_IPFS_HOST", "http://127.0.0.1")
	ipfs := tests.NewServer("127.0.0.1:8080")
	ipfs.SetResponse(tests.ServerResponse{
		Code: http.StatusOK,
		Header: map[string][]string{
			"Ipfs-Hash": {hash},
		},
	})
	defer ipfs.Close()

	if err := PutFiles(do); err != nil {
		fatal(t, err)
	}

	if expected := "/ipfs/"; ipfs.Path() != expected {
		fatal(t, fmt.Errorf("Called the wrong endpoint; expected %v, got %v\n", expected, ipfs.Path()))
	}

	if expected := "POST"; ipfs.Method() != expected {
		fatal(t, fmt.Errorf("Used the wrong HTTP method; expected %v, got %v\n", expected, ipfs.Method()))
	}

	if ipfs.Body() != content {
		fatal(t, fmt.Errorf("Put the bad file; expected %q, got %q\n", content, ipfs.Body()))
	}

	if hash != do.Result {
		fatal(t, fmt.Errorf("Hash mismatch; expected %q, got %q\n", hash, do.Result))
	}

	log.WithField("result", do.Result).Debug("Finished putting a file")
}