Skip to content

Commit

Permalink
clean up test
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Mar 3, 2024
1 parent b352446 commit 4cd1c65
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "testdata/charts"]
path = testdata/charts
url = https://github.com/mrjosh/helm-ls.git
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ install-metalinter:
@$(GO) get -v github.com/golangci/golangci-lint/cmd/[email protected]
@$(GO) install -v github.com/golangci/golangci-lint/cmd/[email protected]

install-yamlls:
npm install --global yaml-language-server

integration-test-deps:
@YAMLLS_BIN=$$(command -v yaml-language-server) || { echo "yaml-language-server command not found! Installing..." && $(MAKE) install-yamlls; };
git submodule init
git submodule update --depth 1

test:
$(MAKE) integration-test-deps
@$(GO) test ./... -v -race

coverage:
Expand Down
52 changes: 40 additions & 12 deletions internal/adapter/yamlls/diagnostics_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"go.lsp.dev/uri"
)

// must be relative to this file
var TEST_DATA_DIR = "../../../testdata/charts/bitnami/"

type jsonRpcDiagnostics struct {
Params lsp.PublishDiagnosticsParams `json:"params"`
Jsonrpc string `json:"jsonrpc"`
Expand Down Expand Up @@ -47,11 +50,17 @@ func (proc readWriteCloseMock) Close() error {
return nil
}

func readTestFiles(dir string, channel chan lsp.DidOpenTextDocumentParams) {
func readTestFiles(dir string, channel chan<- lsp.DidOpenTextDocumentParams, doneChan chan<- int) {
libRegEx, e := regexp.Compile(".*/templates/.*\\.yaml")
if e != nil {
log.Fatal(e)
return
}
if _, err := os.Stat(dir); os.IsNotExist(err) {
log.Fatal(err)
return
}

count := 0
filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
if d.Type().IsRegular() && libRegEx.MatchString(path) {
Expand All @@ -68,51 +77,70 @@ func readTestFiles(dir string, channel chan lsp.DidOpenTextDocumentParams) {
}
return nil
})
fmt.Println("Read ", count, " files")
doneChan <- count
}

// Read 2276 files
// Time's up! Checked 2879 diagnostics.
func sendTestFilesToYamlls(documents *lsplocal.DocumentStore, yamllsConnector *Connector, channel chan lsp.DidOpenTextDocumentParams) {
func sendTestFilesToYamlls(documents *lsplocal.DocumentStore, yamllsConnector *Connector, doneInputChan <-chan int, doneChan chan<- int, channel <-chan lsp.DidOpenTextDocumentParams) {
ownCount := 0
for {
select {
case d := <-channel:
documents.DidOpen(d, util.DefaultConfig)
tree := lsplocal.ParseAst(nil, d.TextDocument.Text)
yamllsConnector.DocumentDidOpen(tree, d)
ownCount++
case count := <-doneInputChan:
if count != ownCount {
log.Fatal("Count mismatch: ", count, " != ", ownCount)
}
doneChan <- count
return
}
}
}

func TestYamllsDiagnosticsIntegration(t *testing.T) {
diagnosticsChan := make(chan lsp.PublishDiagnosticsParams)
doneReadingFilesChan := make(chan int)
doneSendingFilesChan := make(chan int)

dir := t.TempDir()
documents := lsplocal.NewDocumentStore()
con := jsonrpc2.NewConn(jsonrpc2.NewStream(readWriteCloseMock{diagnosticsChan}))
config := util.DefaultConfig.YamllsConfiguration
config.Path = "yamlls-debug.sh"
yamllsConnector := NewConnector(config, con, documents)

yamllsConnector.CallInitialize(uri.File(dir))

didOpenChan := make(chan lsp.DidOpenTextDocumentParams)
go readTestFiles("/home/qv/dev/github/charts/bitnami", didOpenChan)
go sendTestFilesToYamlls(documents, yamllsConnector, didOpenChan)
go readTestFiles(TEST_DATA_DIR, didOpenChan, doneReadingFilesChan)
go sendTestFilesToYamlls(documents, yamllsConnector, doneReadingFilesChan, doneSendingFilesChan, didOpenChan)

count := 0
sentCount := 0
receivedDiagnosttcs :=
make(map[uri.URI]lsp.PublishDiagnosticsParams)

afterCh := time.After(30 * time.Second)
afterCh := time.After(300 * time.Second)
for {
if sentCount != 0 && len(receivedDiagnosttcs) == sentCount {
fmt.Println("All files checked")
break
}
select {
case d := <-diagnosticsChan:
count++
receivedDiagnosttcs[d.URI] = d
if len(d.Diagnostics) > 0 {
fmt.Println("Got ", d)
}
case <-afterCh:
fmt.Println("Time's up! Checked ", count, " diagnostics.")
fmt.Println("Time's up! Checked ", len(receivedDiagnosttcs), " diagnostics.")
return
case count := <-doneSendingFilesChan:
sentCount = count
fmt.Println("Checked ", sentCount, " files")
}
}

fmt.Println("Checking ", sentCount, " files")

}
1 change: 1 addition & 0 deletions testdata/charts
Submodule charts added at b85105

0 comments on commit 4cd1c65

Please sign in to comment.