Exemplo n.º 1
0
// NewDPNSync creates a new DPNSync object.
func NewDPNSync(_context *context.Context) (*DPNSync, error) {
	if _context == nil {
		return nil, fmt.Errorf("Param _context cannot be nil.")
	}
	localClient, err := network.NewDPNRestClient(
		_context.Config.DPN.RestClient.LocalServiceURL,
		_context.Config.DPN.DPNAPIVersion,
		_context.Config.DPN.RestClient.LocalAuthToken,
		_context.Config.DPN.LocalNode,
		_context.Config.DPN)
	if err != nil {
		return nil, fmt.Errorf("Error creating local DPN REST client: %v", err)
	}
	remoteClients, err := localClient.GetRemoteClients()
	if err != nil {
		return nil, fmt.Errorf("Error creating remote DPN REST client: %v", err)
	}
	results := make(map[string]*models.SyncResult)
	for nodeName := range remoteClients {
		results[nodeName] = models.NewSyncResult(nodeName)
	}
	sync := DPNSync{
		LocalClient:   localClient,
		RemoteNodes:   make(map[string]*models.Node),
		RemoteClients: remoteClients,
		Context:       _context,
		Results:       results,
	}
	return &sync, nil
}
Exemplo n.º 2
0
func TestAddToSyncCount(t *testing.T) {
	result := models.NewSyncResult("aptrust")
	require.NotNil(t, result)
	result.AddToSyncCount(dpn.DPNTypeBag, 1)
	assert.Equal(t, 1, result.SyncCounts[dpn.DPNTypeBag])
	result.AddToSyncCount(dpn.DPNTypeBag, 4)
	assert.Equal(t, 5, result.SyncCounts[dpn.DPNTypeBag])
}
Exemplo n.º 3
0
func TestNewSyncResult(t *testing.T) {
	result := models.NewSyncResult("aptrust")
	require.NotNil(t, result)
	assert.Equal(t, "aptrust", result.NodeName)
	assert.NotNil(t, result.FetchCounts)
	assert.NotNil(t, result.SyncCounts)
	assert.NotNil(t, result.Errors)
}
Exemplo n.º 4
0
func TestAddError(t *testing.T) {
	result := models.NewSyncResult("aptrust")
	require.NotNil(t, result)
	result.AddError(dpn.DPNTypeBag, fmt.Errorf("Error 1"))
	assert.Equal(t, 1, len(result.Errors[dpn.DPNTypeBag]))
	assert.Equal(t, "Error 1", result.Errors[dpn.DPNTypeBag][0].Error())
	result.AddError(dpn.DPNTypeBag, fmt.Errorf("Error 2"))
	assert.Equal(t, 2, len(result.Errors[dpn.DPNTypeBag]))
	assert.Equal(t, "Error 2", result.Errors[dpn.DPNTypeBag][1].Error())
}
Exemplo n.º 5
0
func TestHasErrors(t *testing.T) {
	result := models.NewSyncResult("aptrust")
	require.NotNil(t, result)
	assert.False(t, result.HasErrors(dpn.DPNTypeBag))
	assert.False(t, result.HasErrors(""))

	result.AddError(dpn.DPNTypeBag, fmt.Errorf("Error 1"))
	assert.Equal(t, 1, len(result.Errors[dpn.DPNTypeBag]))
	assert.True(t, result.HasErrors(dpn.DPNTypeBag))
	assert.True(t, result.HasErrors(""))
}