@@ -1551,3 +1551,233 @@ func TestTraceRepoImpl_getSpanInsertTable(t *testing.T) {
15511551 })
15521552 }
15531553}
1554+
1555+ func TestTraceRepoImpl_ListWorkspaceAnnotations (t * testing.T ) {
1556+ type fields struct {
1557+ annoDao dao.IAnnotationDao
1558+ traceConfig config.ITraceConfig
1559+ spanRedisDao * redis_dao_mock.MockISpansRedisDao
1560+ spanProducer mq.ISpanProducer
1561+ }
1562+ type args struct {
1563+ ctx context.Context
1564+ param * repo.ListWorkspaceAnnotationsParam
1565+ }
1566+ tests := []struct {
1567+ name string
1568+ fieldsGetter func (ctrl * gomock.Controller ) fields
1569+ args args
1570+ want loop_span.AnnotationList
1571+ wantErr bool
1572+ }{
1573+ {
1574+ name : "annoDao is nil returns error" ,
1575+ fieldsGetter : func (ctrl * gomock.Controller ) fields {
1576+ traceConfigMock := confmocks .NewMockITraceConfig (ctrl )
1577+ return fields {
1578+ annoDao : nil ,
1579+ traceConfig : traceConfigMock ,
1580+ }
1581+ },
1582+ args : args {
1583+ ctx : context .Background (),
1584+ param : & repo.ListWorkspaceAnnotationsParam {
1585+ WorkSpaceID : "ws1" ,
1586+ Tenants : []string {"test" },
1587+ },
1588+ },
1589+ wantErr : true ,
1590+ },
1591+ {
1592+ name : "getQueryTenantTables error" ,
1593+ fieldsGetter : func (ctrl * gomock.Controller ) fields {
1594+ annoDaoMock := daomock .NewMockIAnnotationDao (ctrl )
1595+ traceConfigMock := confmocks .NewMockITraceConfig (ctrl )
1596+ traceConfigMock .EXPECT ().GetTenantConfig (gomock .Any ()).Return (nil , assert .AnError )
1597+ return fields {
1598+ annoDao : annoDaoMock ,
1599+ traceConfig : traceConfigMock ,
1600+ }
1601+ },
1602+ args : args {
1603+ ctx : context .Background (),
1604+ param : & repo.ListWorkspaceAnnotationsParam {
1605+ WorkSpaceID : "ws1" ,
1606+ Tenants : []string {"test" },
1607+ },
1608+ },
1609+ wantErr : true ,
1610+ },
1611+ {
1612+ name : "empty anno tables returns empty list" ,
1613+ fieldsGetter : func (ctrl * gomock.Controller ) fields {
1614+ annoDaoMock := daomock .NewMockIAnnotationDao (ctrl )
1615+ traceConfigMock := confmocks .NewMockITraceConfig (ctrl )
1616+ traceConfigMock .EXPECT ().GetTenantConfig (gomock .Any ()).Return (& config.TenantCfg {
1617+ TenantTables : map [string ]map [loop_span.TTL ]config.TableCfg {
1618+ "test" : {
1619+ loop_span .TTL3d : {
1620+ AnnoTable : "" ,
1621+ },
1622+ },
1623+ },
1624+ }, nil )
1625+ return fields {
1626+ annoDao : annoDaoMock ,
1627+ traceConfig : traceConfigMock ,
1628+ }
1629+ },
1630+ args : args {
1631+ ctx : context .Background (),
1632+ param : & repo.ListWorkspaceAnnotationsParam {
1633+ WorkSpaceID : "ws1" ,
1634+ Tenants : []string {"test" },
1635+ },
1636+ },
1637+ want : loop_span.AnnotationList {},
1638+ },
1639+ {
1640+ name : "annoDao.List error" ,
1641+ fieldsGetter : func (ctrl * gomock.Controller ) fields {
1642+ annoDaoMock := daomock .NewMockIAnnotationDao (ctrl )
1643+ annoDaoMock .EXPECT ().List (gomock .Any (), gomock .Any ()).Return (nil , assert .AnError )
1644+ traceConfigMock := confmocks .NewMockITraceConfig (ctrl )
1645+ traceConfigMock .EXPECT ().GetTenantConfig (gomock .Any ()).Return (& config.TenantCfg {
1646+ TenantTables : map [string ]map [loop_span.TTL ]config.TableCfg {
1647+ "test" : {
1648+ loop_span .TTL3d : {
1649+ AnnoTable : "annotations" ,
1650+ },
1651+ },
1652+ },
1653+ }, nil )
1654+ return fields {
1655+ annoDao : annoDaoMock ,
1656+ traceConfig : traceConfigMock ,
1657+ }
1658+ },
1659+ args : args {
1660+ ctx : context .Background (),
1661+ param : & repo.ListWorkspaceAnnotationsParam {
1662+ WorkSpaceID : "ws1" ,
1663+ Tenants : []string {"test" },
1664+ },
1665+ },
1666+ wantErr : true ,
1667+ },
1668+ {
1669+ name : "success with default limit" ,
1670+ fieldsGetter : func (ctrl * gomock.Controller ) fields {
1671+ annoDaoMock := daomock .NewMockIAnnotationDao (ctrl )
1672+ annoDaoMock .EXPECT ().List (gomock .Any (), gomock .Any ()).Return ([]* dao.Annotation {
1673+ {
1674+ ID : "anno1" ,
1675+ TraceID : "trace1" ,
1676+ SpaceID : "ws1" ,
1677+ },
1678+ }, nil )
1679+ traceConfigMock := confmocks .NewMockITraceConfig (ctrl )
1680+ traceConfigMock .EXPECT ().GetTenantConfig (gomock .Any ()).Return (& config.TenantCfg {
1681+ TenantTables : map [string ]map [loop_span.TTL ]config.TableCfg {
1682+ "test" : {
1683+ loop_span .TTL3d : {
1684+ AnnoTable : "annotations" ,
1685+ },
1686+ },
1687+ },
1688+ }, nil )
1689+ return fields {
1690+ annoDao : annoDaoMock ,
1691+ traceConfig : traceConfigMock ,
1692+ }
1693+ },
1694+ args : args {
1695+ ctx : context .Background (),
1696+ param : & repo.ListWorkspaceAnnotationsParam {
1697+ WorkSpaceID : "ws1" ,
1698+ Tenants : []string {"test" },
1699+ AnnotationType : "manual" ,
1700+ DescByUpdatedAt : true ,
1701+ StartAt : 1000 ,
1702+ EndAt : 2000 ,
1703+ Limit : 0 ,
1704+ },
1705+ },
1706+ want : loop_span.AnnotationList {
1707+ {
1708+ ID : "anno1" ,
1709+ TraceID : "trace1" ,
1710+ WorkspaceID : "ws1" ,
1711+ StartTime : time .UnixMicro (0 ),
1712+ UpdatedAt : time .UnixMicro (0 ),
1713+ CreatedAt : time .UnixMicro (0 ),
1714+ },
1715+ },
1716+ },
1717+ {
1718+ name : "success with explicit limit" ,
1719+ fieldsGetter : func (ctrl * gomock.Controller ) fields {
1720+ annoDaoMock := daomock .NewMockIAnnotationDao (ctrl )
1721+ annoDaoMock .EXPECT ().List (gomock .Any (), gomock .Any ()).Return ([]* dao.Annotation {
1722+ {
1723+ ID : "anno2" ,
1724+ TraceID : "trace2" ,
1725+ SpaceID : "ws2" ,
1726+ },
1727+ }, nil )
1728+ traceConfigMock := confmocks .NewMockITraceConfig (ctrl )
1729+ traceConfigMock .EXPECT ().GetTenantConfig (gomock .Any ()).Return (& config.TenantCfg {
1730+ TenantTables : map [string ]map [loop_span.TTL ]config.TableCfg {
1731+ "test" : {
1732+ loop_span .TTL3d : {
1733+ AnnoTable : "annotations" ,
1734+ },
1735+ },
1736+ },
1737+ }, nil )
1738+ return fields {
1739+ annoDao : annoDaoMock ,
1740+ traceConfig : traceConfigMock ,
1741+ }
1742+ },
1743+ args : args {
1744+ ctx : context .Background (),
1745+ param : & repo.ListWorkspaceAnnotationsParam {
1746+ WorkSpaceID : "ws2" ,
1747+ Tenants : []string {"test" },
1748+ Limit : 50 ,
1749+ },
1750+ },
1751+ want : loop_span.AnnotationList {
1752+ {
1753+ ID : "anno2" ,
1754+ TraceID : "trace2" ,
1755+ WorkspaceID : "ws2" ,
1756+ StartTime : time .UnixMicro (0 ),
1757+ UpdatedAt : time .UnixMicro (0 ),
1758+ CreatedAt : time .UnixMicro (0 ),
1759+ },
1760+ },
1761+ },
1762+ }
1763+ for _ , tt := range tests {
1764+ t .Run (tt .name , func (t * testing.T ) {
1765+ ctrl := gomock .NewController (t )
1766+ defer ctrl .Finish ()
1767+ fields := tt .fieldsGetter (ctrl )
1768+ r , err := NewTraceRepoImpl (
1769+ fields .traceConfig ,
1770+ & mockStorageProvider {},
1771+ fields .spanRedisDao ,
1772+ fields .spanProducer ,
1773+ nil ,
1774+ nil ,
1775+ WithTraceStorageAnnotationDao ("ck" , fields .annoDao ),
1776+ )
1777+ assert .NoError (t , err )
1778+ got , err := r .ListWorkspaceAnnotations (tt .args .ctx , tt .args .param )
1779+ assert .Equal (t , tt .wantErr , err != nil )
1780+ assert .Equal (t , tt .want , got )
1781+ })
1782+ }
1783+ }
0 commit comments