当前位置: 首页>>代码示例>>Golang>>正文


Golang network.NewPharosClient函数代码示例

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


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


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