コード例 #1
0
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)
}
コード例 #2
0
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)
}
コード例 #3
0
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)
}
コード例 #4
0
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))
}
コード例 #5
0
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)
}
コード例 #6
0
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)
}
コード例 #7
0
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))
}
コード例 #8
0
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)
}
コード例 #9
0
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)
}
コード例 #10
0
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())
}
コード例 #11
0
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)
}
コード例 #12
0
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())
}
コード例 #13
0
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())
}
コード例 #14
0
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())
}
コード例 #15
0
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())
}
コード例 #16
0
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())
}
コード例 #17
0
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())
}
コード例 #18
0
ファイル: context.go プロジェクト: APTrust/exchange
// 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
}
コード例 #19
0
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)
}
コード例 #20
0
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)
	}
}
コード例 #21
0
func TestDPNWorkItemList(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(dpnWorkItemListHandler))
	defer testServer.Close()

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

	response := client.DPNWorkItemList(nil)

	// Check the request URL and method
	assert.Equal(t, "GET", 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)
	assert.EqualValues(t, "DPNWorkItem", response.ObjectType())

	list := response.DPNWorkItems()
	if list == nil {
		t.Errorf("DPNWorkItem list should not be nil")
		return
	}
	if len(list) != 4 {
		t.Errorf("DPNWorkItems list should have four items. Found %d.", len(list))
		return
	}
	for _, obj := range list {
		assert.NotEqual(t, "", obj.Task)
		assert.NotEqual(t, "", obj.Identifier)
	}

	// Make sure params are added to URL
	params := sampleParams()
	response = client.DPNWorkItemList(params)
	expectedUrl := fmt.Sprintf("/api/v2/dpn_item/?%s", params.Encode())
	assert.Equal(t, expectedUrl, response.Request.URL.Opaque)
}
コード例 #22
0
func TestGenericFileSaveBatch(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(genericFileSaveBatchHandler))
	defer testServer.Close()

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

	// ---------------------------------------------
	// Make an IntellectualObject with 5 GenericFiles,
	// each with 2 checksums and 2 events.
	// ---------------------------------------------
	obj := testutil.MakeIntellectualObject(5, 2, 2, 0)
	for _, gf := range obj.GenericFiles {
		gf.Id = 0
	}
	response := client.GenericFileSaveBatch(obj.GenericFiles)

	// Check the request URL and method
	expectedUrl := fmt.Sprintf("/api/v2/files/%d/create_batch", obj.GenericFiles[0].IntellectualObjectId)
	assert.Equal(t, "POST", response.Request.Method)
	assert.Equal(t, expectedUrl, response.Request.URL.Opaque)

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

	savedFiles := response.GenericFiles()
	assert.EqualValues(t, "GenericFile", response.ObjectType())
	assert.Equal(t, 5, len(savedFiles))

	// Make sure the client returns the SAVED object,
	// not the unsaved one we sent.
	for _, gf := range savedFiles {
		assert.NotEqual(t, 0, gf.Id)
		assert.Equal(t, 2, len(gf.Checksums))
		assert.Equal(t, 2, len(gf.PremisEvents))
	}
}
コード例 #23
0
func TestInstitutionGet(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(institutionGetHandler))
	defer testServer.Close()

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

	response := client.InstitutionGet("college.edu")

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

	// Basic sanity check on response values
	assert.Nil(t, response.Error)
	assert.EqualValues(t, "Institution", response.ObjectType())
	if response.Institution() == nil {
		t.Errorf("Institution should not be nil")
	}
	assert.NotEqual(t, "", response.Institution().Identifier)
}
コード例 #24
0
func TestWorkItemStateSave(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(workItemStateSaveHandler))
	defer testServer.Close()

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

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

	// Check the request URL and method
	assert.Equal(t, "POST", response.Request.Method)
	assert.Equal(t, "/api/v2/item_state/", 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, 0, obj.Id)
	assert.NotEqual(t, 0, obj.WorkItemId)
	assert.Equal(t, "Ingest", obj.Action)
	assert.Equal(t, `{"key1":"value1","key2":"value2"}`, obj.State)
	assert.False(t, obj.CreatedAt.IsZero())
	assert.False(t, obj.UpdatedAt.IsZero())

	// 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.MakeWorkItemState()
	origModTime := obj.UpdatedAt
	origId := obj.Id
	origWorkItemId := obj.WorkItemId

	// Change this
	obj.State = `{"key3":"value3"}`
	response = client.WorkItemStateSave(obj)

	// Check the request URL and method
	expectedUrl := fmt.Sprintf("/api/v2/item_state/%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.WorkItemState()
	assert.EqualValues(t, "WorkItemState", response.ObjectType())
	if obj == nil {
		t.Errorf("WorkItemState should not be nil")
	}
	assert.Equal(t, origId, obj.Id)
	assert.Equal(t, origWorkItemId, obj.WorkItemId)
	assert.Equal(t, `{"key3":"value3"}`, obj.State)
	assert.NotEqual(t, origModTime, obj.UpdatedAt)
}
コード例 #25
0
func TestNewPharosClient(t *testing.T) {
	_, err := network.NewPharosClient("http://example.com", "v2", "user", "key")
	if err != nil {
		t.Error(err)
	}
}