• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang network.NewPharosClient函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/APTrust/exchange/network.NewPharosClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPharosClient函数的具体用法?Golang NewPharosClient怎么用?Golang NewPharosClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewPharosClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestCheckumSave

func TestCheckumSave(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(checksumSaveHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	checksum := testutil.MakeChecksum()
	response := client.ChecksumSave(checksum, "test.edu/obj1/file.txt")

	// Check the request URL and method
	assert.Equal(t, "POST", response.Request.Method)
	assert.Equal(t, "/api/v2/checksums/test.edu%2Fobj1%2Ffile.txt", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	assert.EqualValues(t, "Checksum", response.ObjectType())
	obj := response.Checksum()
	if obj == nil {
		t.Errorf("Checksum should not be nil")
	}
	assert.NotEqual(t, checksum.CreatedAt, obj.CreatedAt)
	assert.Equal(t, checksum.Digest, obj.Digest)
}
开发者ID:APTrust,项目名称:exchange,代码行数:28,代码来源:pharos_client_test.go


示例2: TestPremisEventGet

func TestPremisEventGet(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(premisEventGetHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	response := client.PremisEventGet("000000000000-0000-0000-0000-00000000")

	// Check the request URL and method
	assert.Equal(t, "GET", response.Request.Method)
	assert.Equal(t, "/api/v2/events/000000000000-0000-0000-0000-00000000/", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj := response.PremisEvent()
	assert.EqualValues(t, "PremisEvent", response.ObjectType())
	if obj == nil {
		t.Errorf("PremisEvent should not be nil")
	}
	assert.Equal(t, "000000000000-0000-0000-0000-00000000", obj.Identifier)
	assert.NotEqual(t, "", obj.EventType)
}
开发者ID:APTrust,项目名称:exchange,代码行数:27,代码来源:pharos_client_test.go


示例3: TestCheckumGet

func TestCheckumGet(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(checksumGetHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	response := client.ChecksumGet(123)

	// Check the request URL and method
	assert.Equal(t, "GET", response.Request.Method)
	assert.Equal(t, "/api/v2/checksums/123/", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	assert.EqualValues(t, "Checksum", response.ObjectType())
	obj := response.Checksum()
	if obj == nil {
		t.Errorf("Checksum should not be nil")
	}
	assert.NotEqual(t, "", obj.Digest)
}
开发者ID:APTrust,项目名称:exchange,代码行数:26,代码来源:pharos_client_test.go


示例4: TestCheckumList

func TestCheckumList(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(checksumListHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	params := url.Values{}
	params.Add("generic_file_identifier", "test.edu/obj1/file.txt")
	response := client.ChecksumList(params)

	// Check the request URL and method
	assert.Equal(t, "GET", response.Request.Method)
	assert.Equal(t, "/api/v2/checksums/?generic_file_identifier=test.edu%2Fobj1%2Ffile.txt",
		response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	assert.EqualValues(t, "Checksum", response.ObjectType())
	list := response.Checksums()
	if list == nil {
		t.Errorf("Checksums should not be nil")
	}
	assert.Equal(t, 4, len(list))
}
开发者ID:APTrust,项目名称:exchange,代码行数:29,代码来源:pharos_client_test.go


示例5: TestGenericFileSave

func TestGenericFileSave(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(genericFileSaveHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	// ---------------------------------------------
	// First, test create...
	// ---------------------------------------------
	obj := testutil.MakeGenericFile(0, 0, "kollege.kom/objekt/file.xml")
	obj.Id = 0
	response := client.GenericFileSave(obj)

	// Check the request URL and method
	assert.Equal(t, "POST", response.Request.Method)
	assert.Equal(t, "/api/v2/files/", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj = response.GenericFile()
	assert.EqualValues(t, "GenericFile", response.ObjectType())
	if obj == nil {
		t.Errorf("GenericFile should not be nil")
	}
	assert.NotEqual(t, "", obj.Identifier)

	// Make sure the client returns the SAVED object,
	// not the unsaved one we sent.
	assert.NotEqual(t, 0, obj.Id)

	// ---------------------------------------------
	// Now test with an update...
	// ---------------------------------------------
	obj = testutil.MakeGenericFile(0, 0, "kollege.kom/objekt/file.xml")
	origModTime := obj.UpdatedAt
	response = client.GenericFileSave(obj)

	// Check the request URL and method
	objIdEncoded := strings.Replace(obj.Identifier, " ", "%20", -1)
	expectedUrl := fmt.Sprintf("/api/v2/files/%s", strings.Replace(objIdEncoded, "/", "%2F", -1))
	assert.Equal(t, "PUT", response.Request.Method)
	assert.Equal(t, expectedUrl, response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj = response.GenericFile()
	assert.EqualValues(t, "GenericFile", response.ObjectType())
	if obj == nil {
		t.Errorf("GenericFile should not be nil")
	}
	assert.NotEqual(t, "", obj.Identifier)
	assert.Equal(t, 1000, obj.Id)
	assert.NotEqual(t, origModTime, obj.UpdatedAt)
}
开发者ID:APTrust,项目名称:exchange,代码行数:60,代码来源:pharos_client_test.go


示例6: TestDPNWorkItemGet

func TestDPNWorkItemGet(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(dpnWorkItemGetHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	response := client.DPNWorkItemGet(999)

	// Check the request URL and method
	assert.Equal(t, "GET", response.Request.Method)
	assert.Equal(t, "/api/v2/dpn_item/999/", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj := response.DPNWorkItem()
	assert.EqualValues(t, "DPNWorkItem", response.ObjectType())
	if obj == nil {
		t.Errorf("DPNWorkItem should not be nil")
	}
	assert.NotEqual(t, "", obj.Task)
	assert.NotEqual(t, "", obj.Identifier)
}
开发者ID:APTrust,项目名称:exchange,代码行数:27,代码来源:pharos_client_test.go


示例7: TestGenericFileGet

func TestGenericFileGet(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(genericFileGetHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	response := client.GenericFileGet("college.edu/object/file.xml")

	// Check the request URL and method
	assert.Equal(t, "GET", response.Request.Method)
	assert.Equal(t, "/api/v2/files/college.edu%2Fobject%2Ffile.xml", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj := response.GenericFile()
	assert.EqualValues(t, "GenericFile", response.ObjectType())
	if obj == nil {
		t.Errorf("GenericFile should not be nil")
	}
	assert.True(t, strings.HasPrefix(obj.Identifier, "kollege.kom/objekt"))

	// Check that child objects were parsed correctly
	assert.Equal(t, 2, len(obj.PremisEvents))
	assert.Equal(t, 3, len(obj.Checksums))
}
开发者ID:APTrust,项目名称:exchange,代码行数:30,代码来源:pharos_client_test.go


示例8: TestIntellectualObjectPushToDPN

func TestIntellectualObjectPushToDPN(t *testing.T) {
	// Note the handler. That's not an error, because this call returns
	// a WorkItem object.
	testServer := httptest.NewServer(http.HandlerFunc(workItemGetHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	// This method is used only in integration tests.
	response := client.IntellectualObjectPushToDPN("college.edu/object")

	// Check the request URL and method
	assert.Equal(t, "PUT", response.Request.Method)
	assert.Equal(t, "/api/v2/objects/college.edu%2Fobject/dpn", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	assert.EqualValues(t, "WorkItem", response.ObjectType())
	item := response.WorkItem()
	require.NotNil(t, item)
	assert.NotEqual(t, 0, item.Id)
	assert.NotEqual(t, "", item.ObjectIdentifier)
}
开发者ID:APTrust,项目名称:exchange,代码行数:28,代码来源:pharos_client_test.go


示例9: TestPremisEventSave

func TestPremisEventSave(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(premisEventSaveHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	// ---------------------------------------------
	// Test create only. PremisEvents cannot be updaed
	// ---------------------------------------------
	obj := testutil.MakePremisEvent()
	obj.Id = 0
	response := client.PremisEventSave(obj)

	// Check the request URL and method
	assert.Equal(t, "POST", response.Request.Method)
	assert.Equal(t, "/api/v2/events/", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj = response.PremisEvent()
	assert.EqualValues(t, "PremisEvent", response.ObjectType())
	if obj == nil {
		t.Errorf("PremisEvent should not be nil")
	}
	assert.NotEqual(t, "", obj.Identifier)

	// Make sure the client returns the SAVED object,
	// not the unsaved one we sent.
	assert.NotEqual(t, 0, obj.Id)
}
开发者ID:APTrust,项目名称:exchange,代码行数:35,代码来源:pharos_client_test.go


示例10: TestWorkStateItemGet

func TestWorkStateItemGet(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(workItemStateGetHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	response := client.WorkItemStateGet(999)

	// Check the request URL and method
	assert.Equal(t, "GET", response.Request.Method)
	assert.Equal(t, "/api/v2/item_state/999/", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj := response.WorkItemState()
	assert.EqualValues(t, "WorkItemState", response.ObjectType())
	if obj == nil {
		t.Errorf("WorkItemState should not be nil")
	}
	assert.NotEqual(t, "", obj.Action)
	assert.NotEqual(t, "", obj.State)
	assert.False(t, obj.CreatedAt.IsZero())
	assert.False(t, obj.UpdatedAt.IsZero())
}
开发者ID:APTrust,项目名称:exchange,代码行数:29,代码来源:pharos_client_test.go


示例11: TestDPNWorkItemSave

func TestDPNWorkItemSave(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(dpnWorkItemSaveHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	// ---------------------------------------------
	// First, test create...
	// ---------------------------------------------
	obj := testutil.MakeDPNWorkItem()
	obj.Id = 0
	response := client.DPNWorkItemSave(obj)

	// Check the request URL and method
	assert.Equal(t, "POST", response.Request.Method)
	assert.Equal(t, "/api/v2/dpn_item/", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj = response.DPNWorkItem()
	assert.EqualValues(t, "DPNWorkItem", response.ObjectType())
	if obj == nil {
		t.Errorf("DPNWorkItem should not be nil")
	}
	assert.NotEqual(t, "", obj.Task)
	assert.NotEqual(t, "", obj.Identifier)

	// Make sure the client returns the SAVED object,
	// not the unsaved one we sent.
	assert.NotEqual(t, 0, obj.Id)

	// ---------------------------------------------
	// Now test with an update...
	// ---------------------------------------------
	obj = testutil.MakeDPNWorkItem()
	origModTime := obj.UpdatedAt
	response = client.DPNWorkItemSave(obj)

	// Check the request URL and method
	expectedUrl := fmt.Sprintf("/api/v2/dpn_item/%d/", obj.Id)
	assert.Equal(t, "PUT", response.Request.Method)
	assert.Equal(t, expectedUrl, response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj = response.DPNWorkItem()
	assert.EqualValues(t, "DPNWorkItem", response.ObjectType())
	if obj == nil {
		t.Errorf("DPNWorkItem should not be nil")
	}
	assert.Equal(t, 1000, obj.Id)
	assert.NotEqual(t, origModTime, obj.UpdatedAt)
}
开发者ID:APTrust,项目名称:exchange,代码行数:59,代码来源:pharos_client_test.go


示例12: TestInstitution

func TestInstitution(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(institutionGetHandler))
	defer testServer.Close()
	client, err := network.NewPharosClient(testServer.URL, "v1", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}
	resp := client.InstitutionGet("college.edu")
	assert.NotNil(t, resp.Institution())
}
开发者ID:APTrust,项目名称:exchange,代码行数:11,代码来源:pharos_response_test.go


示例13: TestPremisEvents

func TestPremisEvents(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(premisEventListHandler))
	defer testServer.Close()
	client, err := network.NewPharosClient(testServer.URL, "v1", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}
	resp := client.PremisEventList(nil)
	assert.NotEmpty(t, resp.PremisEvents())
}
开发者ID:APTrust,项目名称:exchange,代码行数:11,代码来源:pharos_response_test.go


示例14: TestWorkItemState

func TestWorkItemState(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(workItemStateGetHandler))
	defer testServer.Close()
	client, err := network.NewPharosClient(testServer.URL, "v1", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}
	resp := client.WorkItemStateGet(1000)
	assert.NotNil(t, resp.WorkItemState())
}
开发者ID:APTrust,项目名称:exchange,代码行数:11,代码来源:pharos_response_test.go


示例15: TestGenericFile

func TestGenericFile(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(genericFileGetHandler))
	defer testServer.Close()
	client, err := network.NewPharosClient(testServer.URL, "v1", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}
	resp := client.GenericFileGet("college.edu/object/file.xml")
	assert.NotNil(t, resp.GenericFile())
}
开发者ID:APTrust,项目名称:exchange,代码行数:11,代码来源:pharos_response_test.go


示例16: TestIntellectualObject

func TestIntellectualObject(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(intellectualObjectGetHandler))
	defer testServer.Close()
	client, err := network.NewPharosClient(testServer.URL, "v1", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}
	resp := client.IntellectualObjectGet("college.edu/object", true, false)
	assert.NotNil(t, resp.IntellectualObject())
}
开发者ID:APTrust,项目名称:exchange,代码行数:11,代码来源:pharos_response_test.go


示例17: TestDPNWorkItem

func TestDPNWorkItem(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(dpnWorkItemGetHandler))
	defer testServer.Close()
	client, err := network.NewPharosClient(testServer.URL, "v1", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}
	resp := client.DPNWorkItemGet(999)
	assert.Nil(t, resp.Error)
	assert.NotNil(t, resp.DPNWorkItem())
}
开发者ID:APTrust,项目名称:exchange,代码行数:12,代码来源:pharos_response_test.go


示例18: initPharosClient

// Initializes a reusable Pharos client.
func (context *Context) initPharosClient() {
	pharosClient, err := network.NewPharosClient(
		context.Config.PharosURL,
		context.Config.PharosAPIVersion,
		os.Getenv("PHAROS_API_USER"),
		os.Getenv("PHAROS_API_KEY"))
	if err != nil {
		message := fmt.Sprintf("Exiting. Cannot initialize Pharos Client: %v", err)
		fmt.Fprintln(os.Stderr, message)
		context.MessageLog.Fatal(message)
	}
	context.PharosClient = pharosClient
}
开发者ID:APTrust,项目名称:exchange,代码行数:14,代码来源:context.go


示例19: TestIntellectualObjectGet

func TestIntellectualObjectGet(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(intellectualObjectGetHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	response := client.IntellectualObjectGet("college.edu/object", false, false)

	// Check the request URL and method
	assert.Equal(t, "GET", response.Request.Method)
	assert.Equal(t, "/api/v2/objects/college.edu%2Fobject", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj := response.IntellectualObject()
	assert.EqualValues(t, "IntellectualObject", response.ObjectType())
	if obj == nil {
		t.Errorf("IntellectualObject should not be nil")
	}
	assert.NotEqual(t, "", obj.Identifier)

	// Check that child objects were parsed correctly
	assert.Equal(t, 2, len(obj.GenericFiles))
	assert.Equal(t, 3, len(obj.PremisEvents))
	assert.Equal(t, 4, len(obj.GenericFiles[0].Checksums))
	assert.Equal(t, 5, len(obj.IngestTags))

	// Check with includeFiles option
	response = client.IntellectualObjectGet("college.edu/object", true, false)
	assert.Equal(t,
		"/api/v2/objects/college.edu%2Fobject?include_files=true",
		response.Request.URL.Opaque)
	// Check with includeEvents option
	response = client.IntellectualObjectGet("college.edu/object", false, true)
	assert.Equal(t,
		"/api/v2/objects/college.edu%2Fobject?include_events=true",
		response.Request.URL.Opaque)
	// Check with includeFiles and includeEvents options
	response = client.IntellectualObjectGet("college.edu/object", true, true)
	assert.Equal(t,
		"/api/v2/objects/college.edu%2Fobject?include_all_relations=true",
		response.Request.URL.Opaque)
}
开发者ID:APTrust,项目名称:exchange,代码行数:48,代码来源:pharos_client_test.go


示例20: TestRawResponseData

func TestRawResponseData(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(institutionGetHandler))
	defer testServer.Close()
	client, err := network.NewPharosClient(testServer.URL, "v1", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}
	resp := client.InstitutionGet("college.edu")

	// Should be able to call repeatedly without error.
	// Incorrect implementation would try to read from
	// closed network socket.
	for i := 0; i < 3; i++ {
		bytes, err := resp.RawResponseData()
		assert.NotNil(t, bytes)
		assert.NotEmpty(t, bytes)
		assert.Nil(t, err)
	}
}
开发者ID:APTrust,项目名称:exchange,代码行数:20,代码来源:pharos_response_test.go



注:本文中的github.com/APTrust/exchange/network.NewPharosClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang stats.APTBucketReaderStats类代码示例发布时间:2022-05-24
下一篇:
Golang models.GenericFile类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap