Exemple #1
0
func TestGetFiles(t *testing.T) {
	var (
		filename = filepath.Join(erisDir, "tset file.toml")
		content  = "test contents"
		hash     = "QmcJdniiSKMp5az3fJvkbJTANd7bFtDoUkov3a8pkByWkv"
	)
	do := definitions.NowDo()
	do.Name = hash
	do.Path = filename

	// 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,
		Body: content,
	})
	defer ipfs.Close()

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

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

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

	if returned := tests.FileContents(filename); content != returned {
		fatal(t, fmt.Errorf("Returned unexpected content; expected %q, got %q", content, returned))
	}
}
func TestCatService(t *testing.T) {
	do := def.NowDo()
	do.Name = servName
	if err := CatService(do); err != nil {
		t.Fatalf("expected cat to succeed, got %v", err)
	}

	if out := tests.FileContents(filepath.Join(config.GlobalConfig.ErisDir, "services", "ipfs.toml")); out != do.Result {
		t.Fatalf("expected local config to be returned %v, got %v", out, do.Result)
	}
}
Exemple #3
0
func TestCatChainLocalConfig(t *testing.T) {
	buf := new(bytes.Buffer)
	config.GlobalConfig.Writer = buf

	do := def.NowDo()
	do.Name = chainName
	do.Type = "toml"
	if err := CatChain(do); err != nil {
		t.Fatalf("expected getting a local config to succeed, got %v", err)
	}

	if buf.String() != tests.FileContents(filepath.Join(erisDir, "chains", chainName+".toml")) {
		t.Fatalf("expected the local config file to match, got %v", buf.String())
	}
}
func TestExportService(t *testing.T) {
	do := def.NowDo()
	do.Name = "ipfs"

	const hash = "QmQ1LZYPNG4wSb9dojRicWCmM4gFLTPKFUhFnMTR3GKuA2"

	// 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 := ExportService(do); err != nil {
		t.Fatalf("expected service to be exported, got %v", err)
	}

	if expected := "/ipfs/"; ipfs.Path() != expected {
		t.Fatalf("called the wrong endpoint; expected %v, got %v", expected, ipfs.Path())
	}

	if expected := "POST"; ipfs.Method() != expected {
		t.Fatalf("used the wrong HTTP method; expected %v, got %v", expected, ipfs.Method())
	}

	if content := tests.FileContents(FindServiceDefinitionFile(do.Name)); content != ipfs.Body() {
		t.Fatalf("sent the bad file; expected %v, got %v", content, ipfs.Body())
	}

	if hash != do.Result {
		t.Fatalf("hash mismatch; expected %v, got %v", hash, do.Result)
	}
}
func TestImportService(t *testing.T) {
	do := def.NowDo()
	do.Name = "eth"
	do.Hash = "QmQ1LZYPNG4wSb9dojRicWCmM4gFLTPKFUhFnMTR3GKuA2"

	content := `name = "ipfs"

[service]
name = "ipfs"
image = "` + path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_IPFS) + `"`

	// 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,
		Body: content,
	})
	defer ipfs.Close()

	if err := ImportService(do); err != nil {
		t.Fatalf("expected service to be imported, got %v", err)
	}

	if expected := "/ipfs/" + do.Hash; ipfs.Path() != expected {
		t.Fatalf("called the wrong endpoint; expected %v, got %v", expected, ipfs.Path())
	}

	if expected := "GET"; ipfs.Method() != expected {
		t.Fatalf("used the wrong HTTP method; expected %v, got %v\n", expected, ipfs.Method())
	}

	if imported := tests.FileContents(FindServiceDefinitionFile(do.Name)); imported != content {
		t.Fatalf("returned unexpected content; expected: %v, got %v", content, imported)
	}
}