From 4cd1c65010e67c863ce8f7d449865b2eae4f2d68 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sun, 3 Mar 2024 12:34:03 +0100 Subject: [PATCH] clean up test --- .gitmodules | 3 ++ Makefile | 9 ++++ .../yamlls/diagnostics_integration_test.go | 52 ++++++++++++++----- testdata/charts | 1 + 4 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 .gitmodules create mode 160000 testdata/charts diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..e423968f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "testdata/charts"] + path = testdata/charts + url = https://github.com/mrjosh/helm-ls.git diff --git a/Makefile b/Makefile index 2f3f03fa..2d537ee5 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,16 @@ install-metalinter: @$(GO) get -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2 @$(GO) install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2 +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: diff --git a/internal/adapter/yamlls/diagnostics_integration_test.go b/internal/adapter/yamlls/diagnostics_integration_test.go index 807bd4d1..a0039ee8 100644 --- a/internal/adapter/yamlls/diagnostics_integration_test.go +++ b/internal/adapter/yamlls/diagnostics_integration_test.go @@ -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"` @@ -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) { @@ -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") + } diff --git a/testdata/charts b/testdata/charts new file mode 160000 index 00000000..b85105c3 --- /dev/null +++ b/testdata/charts @@ -0,0 +1 @@ +Subproject commit b85105c323a98ec732a58477117e625beec759b7