コード例 #1
0
ファイル: checksum_test.go プロジェクト: APTrust/exchange
func TestChecksumMergeAttributes(t *testing.T) {
	cs1 := testutil.MakeChecksum()
	cs2 := testutil.MakeChecksum()

	err := cs1.MergeAttributes(cs2)
	require.Nil(t, err)
	assert.Equal(t, cs1.Id, cs2.Id)
	assert.Equal(t, cs1.CreatedAt, cs2.CreatedAt)
	assert.Equal(t, cs1.UpdatedAt, cs2.UpdatedAt)

	err = cs1.MergeAttributes(nil)
	assert.NotNil(t, err)
}
コード例 #2
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)
}
コード例 #3
0
func TestNewChecksumForPharos(t *testing.T) {
	cs := testutil.MakeChecksum()
	pharosChecksum := models.NewChecksumForPharos(cs)
	assert.Equal(t, cs.Id, pharosChecksum.Id)
	assert.Equal(t, cs.GenericFileId, pharosChecksum.GenericFileId)
	assert.Equal(t, cs.Algorithm, pharosChecksum.Algorithm)
	assert.Equal(t, cs.DateTime, pharosChecksum.DateTime)
	assert.Equal(t, cs.Digest, pharosChecksum.Digest)
}
コード例 #4
0
func checksumListHandler(w http.ResponseWriter, r *http.Request) {
	list := make([]*models.Checksum, 4)
	for i := 0; i < 4; i++ {
		list[i] = testutil.MakeChecksum()
	}
	data := listResponseData()
	data["results"] = list
	listJson, _ := json.Marshal(data)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(listJson))
}
コード例 #5
0
ファイル: testutil_test.go プロジェクト: APTrust/exchange
func TestMakeChecksum(t *testing.T) {
	cs := testutil.MakeChecksum()
	if cs == nil {
		t.Errorf("MakeChecksum() returned nil")
		return
	}
	assert.NotEqual(t, 0, cs.Id)
	assert.NotEqual(t, 0, cs.GenericFileId)
	assert.NotEqual(t, "", cs.Algorithm)
	assert.False(t, cs.DateTime.IsZero())
	assert.NotEqual(t, "", cs.Digest)
}
コード例 #6
0
func checksumGetHandler(w http.ResponseWriter, r *http.Request) {
	obj := testutil.MakeChecksum()
	objJson, _ := json.Marshal(obj)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(objJson))
}