Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/hooks/sdk_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type SDKCLIConfig struct {
Start HookScript `json:"start,omitempty"`
} `json:"hooks,omitempty"`
Config struct {
Watch WatchOpts `json:"watch,omitempty"`
Watch *WatchOpts `json:"watch,omitempty"`
SDKManagedConnection bool `json:"sdk-managed-connection-enabled,omitempty"`
TriggerPaths []string `json:"trigger-paths,omitempty"`
SupportedProtocols ProtocolVersions `json:"protocol-version,omitempty"`
Expand Down
19 changes: 17 additions & 2 deletions internal/hooks/sdk_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package hooks

import (
"encoding/json"
"testing"

"github.com/slackapi/slack-cli/internal/slackerror"
Expand Down Expand Up @@ -54,7 +55,7 @@ func Test_ProtocolResolution(t *testing.T) {
}{
"Returns the first valid protocol version": {
config: SDKCLIConfig{Config: struct {
Watch WatchOpts `json:"watch,omitempty"`
Watch *WatchOpts `json:"watch,omitempty"`
SDKManagedConnection bool `json:"sdk-managed-connection-enabled,omitempty"`
TriggerPaths []string `json:"trigger-paths,omitempty"`
SupportedProtocols ProtocolVersions `json:"protocol-version,omitempty"`
Expand All @@ -72,7 +73,7 @@ func Test_ProtocolResolution(t *testing.T) {
},
"Returns default config if no valid protocols are present": {
config: SDKCLIConfig{Config: struct {
Watch WatchOpts `json:"watch,omitempty"`
Watch *WatchOpts `json:"watch,omitempty"`
SDKManagedConnection bool `json:"sdk-managed-connection-enabled,omitempty"`
TriggerPaths []string `json:"trigger-paths,omitempty"`
SupportedProtocols ProtocolVersions `json:"protocol-version,omitempty"`
Expand Down Expand Up @@ -103,6 +104,7 @@ func Test_ProtocolResolution(t *testing.T) {
func Test_WatchOpts_IsAvailable(t *testing.T) {
tests := map[string]struct {
watchOpts *WatchOpts
hooksJSON string
expectedIsAvailable bool
}{
"WatchOpts exists": {
Expand All @@ -113,9 +115,22 @@ func Test_WatchOpts_IsAvailable(t *testing.T) {
watchOpts: nil,
expectedIsAvailable: false,
},
"Hooks config with watch options": {
hooksJSON: `{"config":{"watch":{"manifest":{"paths":["manifest.json"]}}}}`,
expectedIsAvailable: true,
},
"Hooks config without watch options": {
hooksJSON: `{"config":{}}`,
expectedIsAvailable: false,
},
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 praise: Unmarshalling real hooks JSON with and without watch tests the exact case that was broken, not just a hand-built nil.

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
if tc.hooksJSON != "" {
var sdkCLIConfig SDKCLIConfig
require.NoError(t, json.Unmarshal([]byte(tc.hooksJSON), &sdkCLIConfig))
tc.watchOpts = sdkCLIConfig.Config.Watch
}
returnedIsAvailable := tc.watchOpts.IsAvailable()
require.Equal(t, tc.expectedIsAvailable, returnedIsAvailable)
})
Expand Down
Loading