func TestCompareAndAddComponent(t *testing.T) { m := newComponents() // Get nil component. component, found := m.get("test") assert.False(t, found) assert.Nil(t, component) // Create mock component newComponent := new(mocks.Component) newComponent.On("GetKey").Return("test") // Use compare and add initially. added := m.compareAndAdd(newComponent) assert.True(t, added) // Use compare and add again to show failure. added = m.compareAndAdd(newComponent) assert.False(t, added) }
func TestAddComponent(t *testing.T) { // Setup map m := newComponents() // Get nil component. component, found := m.get("test") assert.False(t, found) assert.Nil(t, component) // Create mock component newComponent := new(mocks.Component) newComponent.On("GetKey").Return("test") // Test add method m.add(newComponent) // Try to retrieve the component again. component, found = m.get("test") assert.True(t, found) assert.Equal(t, component.GetKey(), "test") }