@@ -1526,320 +1526,3 @@ func testBinary(t testing.TB, name string) string {
15261526 }
15271527 return binaryPath
15281528}
1529-
1530- func TestCheckForSameServiceComponents (t * testing.T ) {
1531- tests := map [string ]struct {
1532- lastCompModel []component.Component
1533- currCompModel []component.Component
1534- expectedCompModel []component.Component
1535- }{
1536- "no components in either model" : {
1537- lastCompModel : []component.Component {},
1538- currCompModel : []component.Component {},
1539- expectedCompModel : []component.Component {},
1540- },
1541- "no service components in either model" : {
1542- lastCompModel : []component.Component {
1543- {
1544- ID : "command-comp-1" ,
1545- InputType : "filestream" ,
1546- InputSpec : & component.InputRuntimeSpec {
1547- Spec : component.InputSpec {
1548- Command : & component.CommandSpec {},
1549- },
1550- },
1551- },
1552- },
1553- currCompModel : []component.Component {
1554- {
1555- ID : "command-comp-2" ,
1556- InputType : "filestream" ,
1557- InputSpec : & component.InputRuntimeSpec {
1558- Spec : component.InputSpec {
1559- Command : & component.CommandSpec {},
1560- },
1561- },
1562- },
1563- },
1564- expectedCompModel : []component.Component {
1565- {
1566- ID : "command-comp-2" ,
1567- InputType : "filestream" ,
1568- InputSpec : & component.InputRuntimeSpec {
1569- Spec : component.InputSpec {
1570- Command : & component.CommandSpec {},
1571- },
1572- },
1573- },
1574- },
1575- },
1576- "service components in old model but not new" : {
1577- lastCompModel : []component.Component {
1578- {
1579- ID : "service-comp-old" ,
1580- InputType : "endpoint-security" ,
1581- InputSpec : & component.InputRuntimeSpec {
1582- Spec : component.InputSpec {
1583- Service : & component.ServiceSpec {},
1584- },
1585- },
1586- },
1587- },
1588- currCompModel : []component.Component {
1589- {
1590- ID : "command-comp-1" ,
1591- InputType : "filestream" ,
1592- InputSpec : & component.InputRuntimeSpec {
1593- Spec : component.InputSpec {
1594- Command : & component.CommandSpec {},
1595- },
1596- },
1597- },
1598- },
1599- expectedCompModel : []component.Component {
1600- {
1601- ID : "command-comp-1" ,
1602- InputType : "filestream" ,
1603- InputSpec : & component.InputRuntimeSpec {
1604- Spec : component.InputSpec {
1605- Command : & component.CommandSpec {},
1606- },
1607- },
1608- },
1609- },
1610- },
1611- "service components in new model but not old" : {
1612- lastCompModel : []component.Component {},
1613- currCompModel : []component.Component {
1614- {
1615- ID : "service-comp-new" ,
1616- InputType : "endpoint" ,
1617- InputSpec : & component.InputRuntimeSpec {
1618- Spec : component.InputSpec {
1619- Service : & component.ServiceSpec {},
1620- },
1621- },
1622- },
1623- },
1624- expectedCompModel : []component.Component {
1625- {
1626- ID : "service-comp-new" ,
1627- InputType : "endpoint" ,
1628- InputSpec : & component.InputRuntimeSpec {
1629- Spec : component.InputSpec {
1630- Service : & component.ServiceSpec {},
1631- },
1632- },
1633- },
1634- },
1635- },
1636- "same service component in both models - should preserve ID" : {
1637- lastCompModel : []component.Component {
1638- {
1639- ID : "endpoint" ,
1640- InputType : "endpoint" ,
1641- OutputType : "elasticsearch" ,
1642- InputSpec : & component.InputRuntimeSpec {
1643- Spec : component.InputSpec {
1644- Service : & component.ServiceSpec {},
1645- },
1646- },
1647- },
1648- },
1649- currCompModel : []component.Component {
1650- {
1651- ID : "endpoint" ,
1652- InputType : "endpoint" ,
1653- OutputType : "logstash" ,
1654- InputSpec : & component.InputRuntimeSpec {
1655- Spec : component.InputSpec {
1656- Service : & component.ServiceSpec {},
1657- },
1658- },
1659- },
1660- },
1661- expectedCompModel : []component.Component {
1662- {
1663- ID : "endpoint" , // Should preserve original ID
1664- InputType : "endpoint" ,
1665- OutputType : "logstash" , // Should use the output type from the new model
1666- InputSpec : & component.InputRuntimeSpec {
1667- Spec : component.InputSpec {
1668- Service : & component.ServiceSpec {},
1669- },
1670- },
1671- },
1672- },
1673- },
1674- "different service components in both models - should not preserve IDs" : {
1675- lastCompModel : []component.Component {
1676- {
1677- ID : "endpoint" ,
1678- InputType : "endpoint" ,
1679- InputSpec : & component.InputRuntimeSpec {
1680- Spec : component.InputSpec {
1681- Service : & component.ServiceSpec {},
1682- },
1683- },
1684- },
1685- },
1686- currCompModel : []component.Component {
1687- {
1688- ID : "another-edr" ,
1689- InputType : "another-edr" ,
1690- InputSpec : & component.InputRuntimeSpec {
1691- Spec : component.InputSpec {
1692- Service : & component.ServiceSpec {},
1693- },
1694- },
1695- },
1696- },
1697- expectedCompModel : []component.Component {
1698- {
1699- ID : "another-edr" ,
1700- InputType : "another-edr" ,
1701- InputSpec : & component.InputRuntimeSpec {
1702- Spec : component.InputSpec {
1703- Service : & component.ServiceSpec {},
1704- },
1705- },
1706- },
1707- },
1708- },
1709- "multiple service components with some matching" : {
1710- lastCompModel : []component.Component {
1711- {
1712- ID : "endpoint" ,
1713- InputType : "endpoint" ,
1714- OutputType : "elasticsearch" ,
1715- InputSpec : & component.InputRuntimeSpec {
1716- Spec : component.InputSpec {
1717- Service : & component.ServiceSpec {},
1718- },
1719- },
1720- },
1721- },
1722- currCompModel : []component.Component {
1723- {
1724- ID : "endpoint" ,
1725- InputType : "endpoint" ,
1726- OutputType : "logstash" ,
1727- InputSpec : & component.InputRuntimeSpec {
1728- Spec : component.InputSpec {
1729- Service : & component.ServiceSpec {},
1730- },
1731- },
1732- },
1733- {
1734- ID : "another-edr" ,
1735- InputType : "another-edr" ,
1736- InputSpec : & component.InputRuntimeSpec {
1737- Spec : component.InputSpec {
1738- Service : & component.ServiceSpec {},
1739- },
1740- },
1741- },
1742- },
1743- expectedCompModel : []component.Component {
1744- {
1745- ID : "endpoint" , // Should preserve original ID
1746- InputType : "endpoint" ,
1747- OutputType : "logstash" ,
1748- InputSpec : & component.InputRuntimeSpec {
1749- Spec : component.InputSpec {
1750- Service : & component.ServiceSpec {},
1751- },
1752- },
1753- },
1754- {
1755- ID : "another-edr" ,
1756- InputType : "another-edr" ,
1757- InputSpec : & component.InputRuntimeSpec {
1758- Spec : component.InputSpec {
1759- Service : & component.ServiceSpec {},
1760- },
1761- },
1762- },
1763- },
1764- },
1765- "mixed service and command components - only service components affected" : {
1766- lastCompModel : []component.Component {
1767- {
1768- ID : "endpoint" ,
1769- InputType : "endpoint" ,
1770- InputSpec : & component.InputRuntimeSpec {
1771- Spec : component.InputSpec {
1772- Service : & component.ServiceSpec {},
1773- },
1774- },
1775- },
1776- {
1777- ID : "filestream-default" ,
1778- InputType : "filestream" ,
1779- InputSpec : & component.InputRuntimeSpec {
1780- Spec : component.InputSpec {
1781- Command : & component.CommandSpec {},
1782- },
1783- },
1784- },
1785- },
1786- currCompModel : []component.Component {
1787- {
1788- ID : "endpoint" ,
1789- InputType : "endpoint" , // Service component - should preserve ID
1790- InputSpec : & component.InputRuntimeSpec {
1791- Spec : component.InputSpec {
1792- Service : & component.ServiceSpec {},
1793- },
1794- },
1795- },
1796- {
1797- ID : "filestream-new" ,
1798- InputType : "filestream" ,
1799- InputSpec : & component.InputRuntimeSpec {
1800- Spec : component.InputSpec {
1801- Command : & component.CommandSpec {},
1802- },
1803- },
1804- },
1805- },
1806- expectedCompModel : []component.Component {
1807- {
1808- ID : "endpoint" , // Service: should preserve original ID
1809- InputType : "endpoint" ,
1810- InputSpec : & component.InputRuntimeSpec {
1811- Spec : component.InputSpec {
1812- Service : & component.ServiceSpec {},
1813- },
1814- },
1815- },
1816- {
1817- ID : "filestream-new" , // Command: should keep new ID
1818- InputType : "filestream" ,
1819- InputSpec : & component.InputRuntimeSpec {
1820- Spec : component.InputSpec {
1821- Command : & component.CommandSpec {},
1822- },
1823- },
1824- },
1825- },
1826- },
1827- }
1828-
1829- for testName , tt := range tests {
1830- t .Run (testName , func (t * testing.T ) {
1831- // Create a coordinator with existing component model
1832- coord := & Coordinator {
1833- componentModel : tt .lastCompModel ,
1834- }
1835-
1836- // Make a copy of the current component model from the test case
1837- // so we don't modify it.
1838- currentCompModel := make ([]component.Component , len (tt .currCompModel ))
1839- copy (currentCompModel , tt .currCompModel )
1840-
1841- coord .checkForSameServiceComponents (currentCompModel )
1842- require .Equal (t , tt .expectedCompModel , currentCompModel )
1843- })
1844- }
1845- }
0 commit comments