-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
795 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
with-expecter: true | ||
packages: | ||
go.lsp.dev/protocol: | ||
# place your package-specific config here | ||
config: | ||
interfaces: | ||
# select the interfaces you want mocked | ||
Client: | ||
# Modify package-level config for this specific interface (if applicable) | ||
config: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package handler | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/mrjosh/helm-ls/internal/charts" | ||
"github.com/mrjosh/helm-ls/internal/util" | ||
mocks "github.com/mrjosh/helm-ls/mocks/go.lsp.dev/protocol" | ||
lsp "go.lsp.dev/protocol" | ||
"go.lsp.dev/uri" | ||
) | ||
|
||
var ( | ||
configurationParams = lsp.ConfigurationParams{Items: []lsp.ConfigurationItem{{Section: "helm-ls"}}} | ||
handler = &langHandler{ | ||
helmlsConfig: util.DefaultConfig, | ||
chartStore: charts.NewChartStore(uri.File("/"), charts.NewChart), | ||
} | ||
) | ||
|
||
func TestConfigurationWorks(t *testing.T) { | ||
mockClient := mocks.NewMockClient(t) | ||
handler.client = mockClient | ||
|
||
userConfig := []interface{}{map[string]interface{}{ | ||
"LogLevel": "debug", | ||
// disable yamlls to avoid configuring it in the test | ||
"yamlls": map[string]interface{}{"enabled": false}, | ||
}} | ||
mockClient.EXPECT().Configuration(mock.Anything, &configurationParams).Return(userConfig, nil) | ||
handler.retrieveWorkspaceConfiguration(context.Background()) | ||
|
||
expectedConfig := util.DefaultConfig | ||
expectedConfig.LogLevel = "debug" | ||
expectedConfig.YamllsConfiguration.Enabled = false | ||
assert.Equal(t, expectedConfig, handler.helmlsConfig) | ||
} | ||
|
||
func TestConfigurationWorksForEmptyConfig(t *testing.T) { | ||
mockClient := mocks.NewMockClient(t) | ||
handler.client = mockClient | ||
// disable yamlls to avoid configuring it in the test | ||
handler.helmlsConfig.YamllsConfiguration.Enabled = false | ||
|
||
userConfig := []interface{}{} | ||
mockClient.EXPECT().Configuration(mock.Anything, &configurationParams).Return(userConfig, nil) | ||
handler.retrieveWorkspaceConfiguration(context.Background()) | ||
|
||
expectedConfig := util.DefaultConfig | ||
expectedConfig.YamllsConfiguration.Enabled = false | ||
assert.Equal(t, expectedConfig, handler.helmlsConfig) | ||
} | ||
|
||
func TestConfigurationWorksForError(t *testing.T) { | ||
mockClient := mocks.NewMockClient(t) | ||
handler.client = mockClient | ||
|
||
// disable yamlls to avoid configuring it in the test | ||
handler.helmlsConfig.YamllsConfiguration.Enabled = false | ||
|
||
userConfig := []interface{}{map[string]interface{}{ | ||
"LogLevel": "debug", | ||
}} | ||
mockClient.EXPECT().Configuration(mock.Anything, &configurationParams).Return(userConfig, errors.New("error")) | ||
handler.retrieveWorkspaceConfiguration(context.Background()) | ||
|
||
expectedConfig := util.DefaultConfig | ||
expectedConfig.YamllsConfiguration.Enabled = false | ||
assert.Equal(t, expectedConfig, handler.helmlsConfig) | ||
} | ||
|
||
func TestConfigurationWorksForJsonError(t *testing.T) { | ||
mockClient := mocks.NewMockClient(t) | ||
handler.client = mockClient | ||
|
||
// disable yamlls to avoid configuring it in the test | ||
handler.helmlsConfig.YamllsConfiguration.Enabled = false | ||
|
||
userConfig := []interface{}{map[string]interface{}{ | ||
"LogLevel": "debug", | ||
"test": func() { | ||
return | ||
}, | ||
}} | ||
mockClient.EXPECT().Configuration(mock.Anything, &configurationParams).Return(userConfig, nil) | ||
handler.retrieveWorkspaceConfiguration(context.Background()) | ||
|
||
expectedConfig := util.DefaultConfig | ||
expectedConfig.YamllsConfiguration.Enabled = false | ||
assert.Equal(t, expectedConfig, handler.helmlsConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.