-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(definition): definition for dependecy charts
- Loading branch information
Showing
24 changed files
with
207 additions
and
44 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
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 was deleted.
Oops, something went wrong.
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,20 @@ | ||
package charts | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"helm.sh/helm/v3/pkg/chart" | ||
) | ||
|
||
type DependencyTemplateFile struct { | ||
Content []byte | ||
Path string | ||
} | ||
|
||
var DependencyCacheFolder = ".helm_ls_cache" | ||
|
||
func (c *Chart) NewDependencyTemplateFile(chartName string, file *chart.File) *DependencyTemplateFile { | ||
path := filepath.Join(c.RootURI.Filename(), "charts", DependencyCacheFolder, chartName, file.Name) | ||
|
||
return &DependencyTemplateFile{Content: file.Data, Path: path} | ||
} |
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,107 @@ | ||
package handler | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/mrjosh/helm-ls/internal/adapter/yamlls" | ||
"github.com/mrjosh/helm-ls/internal/charts" | ||
lsplocal "github.com/mrjosh/helm-ls/internal/lsp" | ||
"github.com/mrjosh/helm-ls/internal/util" | ||
"github.com/stretchr/testify/assert" | ||
lsp "go.lsp.dev/protocol" | ||
"go.lsp.dev/uri" | ||
) | ||
|
||
var ( | ||
rootUri = uri.File("../../testdata/dependenciesExample/") | ||
fileURI = uri.File("../../testdata/dependenciesExample/templates/deployment.yaml") | ||
) | ||
|
||
type testCase struct { | ||
templateLineWithMarker string | ||
expectedFile string | ||
expectedStartPosition lsp.Position | ||
expectedError error | ||
} | ||
|
||
func TestDefinitionChart(t *testing.T) { | ||
testCases := []testCase{ | ||
{ | ||
`{{ include "common.na^mes.name" . }}`, | ||
"charts/.helm_ls_cache/common/templates/_names.tpl", | ||
lsp.Position{Line: 9, Character: 0}, | ||
nil, | ||
}, | ||
{ | ||
`{{- include "dependeciesEx^ample.labels" . | nindent 4 }}`, | ||
"templates/_helpers.tpl", | ||
lsp.Position{Line: 35, Character: 0}, | ||
nil, | ||
}, | ||
} | ||
|
||
fileContent, err := os.ReadFile(fileURI.Filename()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
lines := strings.Split(string(fileContent), "\n") | ||
for _, tC := range testCases { | ||
t.Run("Definition on "+tC.templateLineWithMarker, func(t *testing.T) { | ||
pos := getPosition(tC, lines) | ||
|
||
documents := lsplocal.NewDocumentStore() | ||
|
||
chart := charts.NewChart(rootUri, util.ValuesFilesConfig{}) | ||
|
||
chartStore := charts.NewChartStore(rootUri, charts.NewChart) | ||
chartStore.Charts = map[uri.URI]*charts.Chart{rootUri: chart} | ||
h := &langHandler{ | ||
chartStore: chartStore, | ||
documents: documents, | ||
yamllsConnector: &yamlls.Connector{}, | ||
} | ||
|
||
h.LoadDocsOnNewChart(chart) | ||
|
||
locations, err := h.Definition(context.TODO(), &lsp.DefinitionParams{ | ||
TextDocumentPositionParams: lsp.TextDocumentPositionParams{ | ||
TextDocument: lsp.TextDocumentIdentifier{URI: fileURI}, | ||
Position: pos, | ||
}, | ||
}) | ||
|
||
assert.Equal(t, tC.expectedError, err) | ||
assert.Len(t, locations, 1) | ||
if len(locations) > 0 { | ||
assert.Equal(t, filepath.Join(rootUri.Filename(), tC.expectedFile), locations[0].URI.Filename()) | ||
assert.Equal(t, tC.expectedStartPosition, locations[0].Range.Start) | ||
} | ||
|
||
for _, location := range locations { | ||
assert.FileExists(t, location.URI.Filename()) | ||
} | ||
|
||
os.RemoveAll(filepath.Join(rootUri.Filename(), "charts", charts.DependencyCacheFolder)) | ||
}) | ||
} | ||
} | ||
|
||
func getPosition(tC testCase, lines []string) lsp.Position { | ||
col := strings.Index(tC.templateLineWithMarker, "^") | ||
buf := strings.Replace(tC.templateLineWithMarker, "^", "", 1) | ||
line := uint32(0) | ||
|
||
for i, v := range lines { | ||
if strings.Contains(v, buf) { | ||
line = uint32(i) | ||
col = col + strings.Index(v, buf) | ||
break | ||
} | ||
} | ||
pos := lsp.Position{Line: line, Character: uint32(col)} | ||
return pos | ||
} |
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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -28,3 +28,4 @@ dependencies: | |
tags: | ||
- bitnami-common | ||
version: 2.x.x | ||
- name: subchartexample |
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
testdata/dependenciesExample/charts/subchartexample/.helmignore
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,23 @@ | ||
# Patterns to ignore when building packages. | ||
# This supports shell glob matching, relative path matching, and | ||
# negation (prefixed with !). Only one pattern per line. | ||
.DS_Store | ||
# Common VCS dirs | ||
.git/ | ||
.gitignore | ||
.bzr/ | ||
.bzrignore | ||
.hg/ | ||
.hgignore | ||
.svn/ | ||
# Common backup files | ||
*.swp | ||
*.bak | ||
*.tmp | ||
*.orig | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj | ||
.vscode/ |
24 changes: 24 additions & 0 deletions
24
testdata/dependenciesExample/charts/subchartexample/Chart.yaml
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,24 @@ | ||
apiVersion: v2 | ||
name: subchartexample | ||
description: A Helm chart for Kubernetes | ||
|
||
# A chart can be either an 'application' or a 'library' chart. | ||
# | ||
# Application charts are a collection of templates that can be packaged into versioned archives | ||
# to be deployed. | ||
# | ||
# Library charts provide useful utilities or functions for the chart developer. They're included as | ||
# a dependency of application charts to inject those utilities and functions into the rendering | ||
# pipeline. Library charts do not define any templates and therefore cannot be deployed. | ||
type: application | ||
|
||
# This is the chart version. This version number should be incremented each time you make changes | ||
# to the chart and its templates, including the app version. | ||
# Versions are expected to follow Semantic Versioning (https://semver.org/) | ||
version: 0.1.0 | ||
|
||
# This is the version number of the application being deployed. This version number should be | ||
# incremented each time you make changes to the application. Versions are not expected to | ||
# follow Semantic Versioning. They should reflect the version the application is using. | ||
# It is recommended to use it with quotes. | ||
appVersion: "1.16.0" |
4 changes: 4 additions & 0 deletions
4
testdata/dependenciesExample/charts/subchartexample/values.yaml
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,4 @@ | ||
global: | ||
subchart: works | ||
|
||
subchartWithoutGlobal: works |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.