@@ -29,6 +29,7 @@ import (
2929 "github.com/slackapi/slack-cli/internal/shared/types"
3030 "github.com/slackapi/slack-cli/internal/slackcontext"
3131 "github.com/slackapi/slack-cli/internal/slackerror"
32+ "github.com/spf13/afero"
3233 "github.com/stretchr/testify/assert"
3334 "github.com/stretchr/testify/mock"
3435 "github.com/stretchr/testify/require"
@@ -1728,6 +1729,86 @@ func TestContinueDespiteWarning(t *testing.T) {
17281729 }
17291730}
17301731
1732+ func Test_resolveIconPath (t * testing.T ) {
1733+ tests := map [string ]struct {
1734+ envIconPath string
1735+ manifestIcon string
1736+ setupFiles func (t * testing.T , fs afero.Fs )
1737+ expected string
1738+ }{
1739+ "env var takes priority over manifest icon" : {
1740+ envIconPath : "env-icon.png" ,
1741+ manifestIcon : "manifest-icon.png" ,
1742+ setupFiles : func (t * testing.T , fs afero.Fs ) {
1743+ require .NoError (t , afero .WriteFile (fs , "env-icon.png" , []byte ("img" ), 0o644 ))
1744+ require .NoError (t , afero .WriteFile (fs , "manifest-icon.png" , []byte ("img" ), 0o644 ))
1745+ },
1746+ expected : "env-icon.png" ,
1747+ },
1748+ "env var takes priority over fallback" : {
1749+ envIconPath : "env-icon.png" ,
1750+ setupFiles : func (t * testing.T , fs afero.Fs ) {
1751+ require .NoError (t , afero .WriteFile (fs , "env-icon.png" , []byte ("img" ), 0o644 ))
1752+ require .NoError (t , afero .WriteFile (fs , "assets/icon.png" , []byte ("img" ), 0o644 ))
1753+ },
1754+ expected : "env-icon.png" ,
1755+ },
1756+ "manifest icon used when no env var" : {
1757+ manifestIcon : "manifest-icon.png" ,
1758+ setupFiles : func (t * testing.T , fs afero.Fs ) {
1759+ require .NoError (t , afero .WriteFile (fs , "manifest-icon.png" , []byte ("img" ), 0o644 ))
1760+ },
1761+ expected : "manifest-icon.png" ,
1762+ },
1763+ "falls back to assets/icon.png when no env var or manifest" : {
1764+ setupFiles : func (t * testing.T , fs afero.Fs ) {
1765+ require .NoError (t , afero .WriteFile (fs , "assets/icon.png" , []byte ("img" ), 0o644 ))
1766+ },
1767+ expected : "assets/icon.png" ,
1768+ },
1769+ "falls back to icon.png in root when no assets" : {
1770+ setupFiles : func (t * testing.T , fs afero.Fs ) {
1771+ require .NoError (t , afero .WriteFile (fs , "icon.png" , []byte ("img" ), 0o644 ))
1772+ },
1773+ expected : "icon.png" ,
1774+ },
1775+ "returns empty when no icon found" : {
1776+ setupFiles : func (t * testing.T , fs afero.Fs ) {},
1777+ expected : "" ,
1778+ },
1779+ "env var file not found returns empty" : {
1780+ envIconPath : "missing-icon.png" ,
1781+ manifestIcon : "manifest-icon.png" ,
1782+ setupFiles : func (t * testing.T , fs afero.Fs ) {
1783+ require .NoError (t , afero .WriteFile (fs , "manifest-icon.png" , []byte ("img" ), 0o644 ))
1784+ },
1785+ expected : "" ,
1786+ },
1787+ "manifest icon file not found returns empty with warning" : {
1788+ manifestIcon : "missing-manifest-icon.png" ,
1789+ setupFiles : func (t * testing.T , fs afero.Fs ) {
1790+ require .NoError (t , afero .WriteFile (fs , "assets/icon.png" , []byte ("img" ), 0o644 ))
1791+ },
1792+ expected : "" ,
1793+ },
1794+ }
1795+ for name , tc := range tests {
1796+ t .Run (name , func (t * testing.T ) {
1797+ ctx := slackcontext .MockContext (t .Context ())
1798+ clientsMock := shared .NewClientsMock ()
1799+ clientsMock .AddDefaultMocks ()
1800+ clientsMock .Config .AppIconPathFlag = tc .envIconPath
1801+ tc .setupFiles (t , clientsMock .Fs )
1802+ output := & bytes.Buffer {}
1803+ clientsMock .IO .Stdout .SetOutput (output )
1804+ clients := shared .NewClientFactory (clientsMock .MockClientFactory ())
1805+
1806+ result := resolveIconPath (ctx , clients , tc .manifestIcon )
1807+ assert .Equal (t , tc .expected , result )
1808+ })
1809+ }
1810+ }
1811+
17311812func Test_updateIcon (t * testing.T ) {
17321813 tests := map [string ]struct {
17331814 isHosted bool
0 commit comments