예제 #1
0
func TestImportService(t *testing.T) {
	do := def.NowDo()
	do.Name = "eth"
	do.Hash = "QmQ1LZYPNG4wSb9dojRicWCmM4gFLTPKFUhFnMTR3GKuA2"
	log.WithFields(log.Fields{
		"=>":   do.Name,
		"hash": do.Hash,
	}).Debug("Importing service (from tests)")

	content := `name = "ipfs"

[service]
name = "ipfs"
image = "quay.io/eris/ipfs"`

	// Fake IPFS server.
	os.Setenv("ERIS_IPFS_HOST", "http://localhost")
	ipfs := tests.NewServer("localhost:8080")
	ipfs.SetResponse(tests.ServerResponse{
		Code: http.StatusOK,
		Body: content,
	})
	defer ipfs.Close()

	if err := ImportService(do); err != nil {
		tests.IfExit(err)
	}

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

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

	if imported := tests.FileContents(FindServiceDefinitionFile(do.Name)); imported != content {
		tests.IfExit(fmt.Errorf("Returned unexpected content; expected: %q, got %q", content, imported))
	}
}
예제 #2
0
func TestExportService(t *testing.T) {
	do := def.NowDo()
	do.Name = "ipfs"

	hash := "QmQ1LZYPNG4wSb9dojRicWCmM4gFLTPKFUhFnMTR3GKuA2"

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

	if err := ExportService(do); err != nil {
		tests.IfExit(err)
	}

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

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

	if content := tests.FileContents(FindServiceDefinitionFile(do.Name)); content != ipfs.Body() {
		tests.IfExit(fmt.Errorf("Sent the bad file; expected %q, got %q\n", content, ipfs.Body()))
	}

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