Skip to content

Commit 356108d

Browse files
authored
Merge pull request #72 from syou6162/remove_duplicated_tests
test: テスト重複排除とカバレッジ向上(61.3%→70.3%)
2 parents f604156 + 26ec9d5 commit 356108d

File tree

8 files changed

+3056
-1416
lines changed

8 files changed

+3056
-1416
lines changed

conditions_test.go

Lines changed: 352 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,3 +1703,355 @@ func TestCheckPreCompactCondition(t *testing.T) {
17031703
})
17041704
}
17051705
}
1706+
1707+
func TestCheckNotificationCondition(t *testing.T) {
1708+
tests := []struct {
1709+
name string
1710+
condition Condition
1711+
input *NotificationInput
1712+
want bool
1713+
wantErr bool
1714+
}{
1715+
{
1716+
name: "permission_mode_is match in Notification",
1717+
condition: Condition{
1718+
Type: ConditionPermissionModeIs,
1719+
Value: "default",
1720+
},
1721+
input: &NotificationInput{
1722+
BaseInput: BaseInput{
1723+
SessionID: "test-notif",
1724+
HookEventName: Notification,
1725+
PermissionMode: "default",
1726+
},
1727+
NotificationType: "idle_prompt",
1728+
},
1729+
want: true,
1730+
wantErr: false,
1731+
},
1732+
{
1733+
name: "permission_mode_is no match in Notification",
1734+
condition: Condition{
1735+
Type: ConditionPermissionModeIs,
1736+
Value: "plan",
1737+
},
1738+
input: &NotificationInput{
1739+
BaseInput: BaseInput{
1740+
SessionID: "test-notif2",
1741+
HookEventName: Notification,
1742+
PermissionMode: "default",
1743+
},
1744+
NotificationType: "permission_prompt",
1745+
},
1746+
want: false,
1747+
wantErr: false,
1748+
},
1749+
{
1750+
name: "file_exists common condition still works",
1751+
condition: Condition{
1752+
Type: ConditionFileExists,
1753+
Value: "go.mod",
1754+
},
1755+
input: &NotificationInput{
1756+
BaseInput: BaseInput{
1757+
SessionID: "test-notif3",
1758+
HookEventName: Notification,
1759+
},
1760+
NotificationType: "idle_prompt",
1761+
},
1762+
want: true,
1763+
wantErr: false,
1764+
},
1765+
{
1766+
name: "unsupported condition type for Notification",
1767+
condition: Condition{
1768+
Type: ConditionFileExtension,
1769+
Value: ".go",
1770+
},
1771+
input: &NotificationInput{
1772+
BaseInput: BaseInput{
1773+
SessionID: "test-notif4",
1774+
HookEventName: Notification,
1775+
},
1776+
NotificationType: "idle_prompt",
1777+
},
1778+
want: false,
1779+
wantErr: true,
1780+
},
1781+
}
1782+
1783+
for _, tt := range tests {
1784+
t.Run(tt.name, func(t *testing.T) {
1785+
got, err := checkNotificationCondition(tt.condition, tt.input)
1786+
if (err != nil) != tt.wantErr {
1787+
t.Errorf("checkNotificationCondition() error = %v, wantErr %v", err, tt.wantErr)
1788+
return
1789+
}
1790+
if got != tt.want {
1791+
t.Errorf("checkNotificationCondition() = %v, want %v", got, tt.want)
1792+
}
1793+
})
1794+
}
1795+
}
1796+
1797+
func TestCheckStopCondition(t *testing.T) {
1798+
tests := []struct {
1799+
name string
1800+
condition Condition
1801+
input *StopInput
1802+
want bool
1803+
wantErr bool
1804+
}{
1805+
{
1806+
name: "permission_mode_is match in Stop",
1807+
condition: Condition{
1808+
Type: ConditionPermissionModeIs,
1809+
Value: "default",
1810+
},
1811+
input: &StopInput{
1812+
BaseInput: BaseInput{
1813+
SessionID: "test-stop",
1814+
HookEventName: Stop,
1815+
PermissionMode: "default",
1816+
},
1817+
},
1818+
want: true,
1819+
wantErr: false,
1820+
},
1821+
{
1822+
name: "permission_mode_is no match in Stop",
1823+
condition: Condition{
1824+
Type: ConditionPermissionModeIs,
1825+
Value: "plan",
1826+
},
1827+
input: &StopInput{
1828+
BaseInput: BaseInput{
1829+
SessionID: "test-stop2",
1830+
HookEventName: Stop,
1831+
PermissionMode: "default",
1832+
},
1833+
},
1834+
want: false,
1835+
wantErr: false,
1836+
},
1837+
{
1838+
name: "file_exists common condition still works",
1839+
condition: Condition{
1840+
Type: ConditionFileExists,
1841+
Value: "go.mod",
1842+
},
1843+
input: &StopInput{
1844+
BaseInput: BaseInput{
1845+
SessionID: "test-stop3",
1846+
HookEventName: Stop,
1847+
},
1848+
},
1849+
want: true,
1850+
wantErr: false,
1851+
},
1852+
{
1853+
name: "unsupported condition type for Stop",
1854+
condition: Condition{
1855+
Type: ConditionFileExtension,
1856+
Value: ".go",
1857+
},
1858+
input: &StopInput{
1859+
BaseInput: BaseInput{
1860+
SessionID: "test-stop4",
1861+
HookEventName: Stop,
1862+
},
1863+
},
1864+
want: false,
1865+
wantErr: true,
1866+
},
1867+
}
1868+
1869+
for _, tt := range tests {
1870+
t.Run(tt.name, func(t *testing.T) {
1871+
got, err := checkStopCondition(tt.condition, tt.input)
1872+
if (err != nil) != tt.wantErr {
1873+
t.Errorf("checkStopCondition() error = %v, wantErr %v", err, tt.wantErr)
1874+
return
1875+
}
1876+
if got != tt.want {
1877+
t.Errorf("checkStopCondition() = %v, want %v", got, tt.want)
1878+
}
1879+
})
1880+
}
1881+
}
1882+
1883+
func TestCheckSubagentStopCondition(t *testing.T) {
1884+
tests := []struct {
1885+
name string
1886+
condition Condition
1887+
input *SubagentStopInput
1888+
want bool
1889+
wantErr bool
1890+
}{
1891+
{
1892+
name: "permission_mode_is match in SubagentStop",
1893+
condition: Condition{
1894+
Type: ConditionPermissionModeIs,
1895+
Value: "default",
1896+
},
1897+
input: &SubagentStopInput{
1898+
BaseInput: BaseInput{
1899+
SessionID: "test-sastop",
1900+
HookEventName: SubagentStop,
1901+
PermissionMode: "default",
1902+
},
1903+
},
1904+
want: true,
1905+
wantErr: false,
1906+
},
1907+
{
1908+
name: "permission_mode_is no match in SubagentStop",
1909+
condition: Condition{
1910+
Type: ConditionPermissionModeIs,
1911+
Value: "plan",
1912+
},
1913+
input: &SubagentStopInput{
1914+
BaseInput: BaseInput{
1915+
SessionID: "test-sastop2",
1916+
HookEventName: SubagentStop,
1917+
PermissionMode: "default",
1918+
},
1919+
},
1920+
want: false,
1921+
wantErr: false,
1922+
},
1923+
{
1924+
name: "file_exists common condition still works",
1925+
condition: Condition{
1926+
Type: ConditionFileExists,
1927+
Value: "go.mod",
1928+
},
1929+
input: &SubagentStopInput{
1930+
BaseInput: BaseInput{
1931+
SessionID: "test-sastop3",
1932+
HookEventName: SubagentStop,
1933+
},
1934+
},
1935+
want: true,
1936+
wantErr: false,
1937+
},
1938+
{
1939+
name: "unsupported condition type for SubagentStop",
1940+
condition: Condition{
1941+
Type: ConditionFileExtension,
1942+
Value: ".go",
1943+
},
1944+
input: &SubagentStopInput{
1945+
BaseInput: BaseInput{
1946+
SessionID: "test-sastop4",
1947+
HookEventName: SubagentStop,
1948+
},
1949+
},
1950+
want: false,
1951+
wantErr: true,
1952+
},
1953+
}
1954+
1955+
for _, tt := range tests {
1956+
t.Run(tt.name, func(t *testing.T) {
1957+
got, err := checkSubagentStopCondition(tt.condition, tt.input)
1958+
if (err != nil) != tt.wantErr {
1959+
t.Errorf("checkSubagentStopCondition() error = %v, wantErr %v", err, tt.wantErr)
1960+
return
1961+
}
1962+
if got != tt.want {
1963+
t.Errorf("checkSubagentStopCondition() = %v, want %v", got, tt.want)
1964+
}
1965+
})
1966+
}
1967+
}
1968+
1969+
func TestCheckSubagentStartCondition(t *testing.T) {
1970+
tests := []struct {
1971+
name string
1972+
condition Condition
1973+
input *SubagentStartInput
1974+
want bool
1975+
wantErr bool
1976+
}{
1977+
{
1978+
name: "permission_mode_is match in SubagentStart",
1979+
condition: Condition{
1980+
Type: ConditionPermissionModeIs,
1981+
Value: "default",
1982+
},
1983+
input: &SubagentStartInput{
1984+
BaseInput: BaseInput{
1985+
SessionID: "test-sastart",
1986+
HookEventName: SubagentStart,
1987+
PermissionMode: "default",
1988+
},
1989+
AgentType: "Explore",
1990+
},
1991+
want: true,
1992+
wantErr: false,
1993+
},
1994+
{
1995+
name: "permission_mode_is no match in SubagentStart",
1996+
condition: Condition{
1997+
Type: ConditionPermissionModeIs,
1998+
Value: "plan",
1999+
},
2000+
input: &SubagentStartInput{
2001+
BaseInput: BaseInput{
2002+
SessionID: "test-sastart2",
2003+
HookEventName: SubagentStart,
2004+
PermissionMode: "default",
2005+
},
2006+
AgentType: "Plan",
2007+
},
2008+
want: false,
2009+
wantErr: false,
2010+
},
2011+
{
2012+
name: "file_exists common condition still works",
2013+
condition: Condition{
2014+
Type: ConditionFileExists,
2015+
Value: "go.mod",
2016+
},
2017+
input: &SubagentStartInput{
2018+
BaseInput: BaseInput{
2019+
SessionID: "test-sastart3",
2020+
HookEventName: SubagentStart,
2021+
},
2022+
AgentType: "Bash",
2023+
},
2024+
want: true,
2025+
wantErr: false,
2026+
},
2027+
{
2028+
name: "unsupported condition type for SubagentStart",
2029+
condition: Condition{
2030+
Type: ConditionFileExtension,
2031+
Value: ".go",
2032+
},
2033+
input: &SubagentStartInput{
2034+
BaseInput: BaseInput{
2035+
SessionID: "test-sastart4",
2036+
HookEventName: SubagentStart,
2037+
},
2038+
AgentType: "Explore",
2039+
},
2040+
want: false,
2041+
wantErr: true,
2042+
},
2043+
}
2044+
2045+
for _, tt := range tests {
2046+
t.Run(tt.name, func(t *testing.T) {
2047+
got, err := checkSubagentStartCondition(tt.condition, tt.input)
2048+
if (err != nil) != tt.wantErr {
2049+
t.Errorf("checkSubagentStartCondition() error = %v, wantErr %v", err, tt.wantErr)
2050+
return
2051+
}
2052+
if got != tt.want {
2053+
t.Errorf("checkSubagentStartCondition() = %v, want %v", got, tt.want)
2054+
}
2055+
})
2056+
}
2057+
}

0 commit comments

Comments
 (0)