Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Sep 1, 2022
1 parent 47eb00b commit 37e172f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ jobs:
-
name: Run go fmt
run: go run github.com/mh-cbon/go-fmt-fail ./...
-
name: Run verbose test / debug
run: go test -cover -covermode=atomic -timeout=5m -race ./internal/terraform/module -run=TestParseProviderVersions_multipleVersions -v
-
name: Run tests
run: go test -cover -covermode=atomic -timeout=5m -race ./...
9 changes: 9 additions & 0 deletions internal/terraform/module/module_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log"

"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -137,6 +138,7 @@ func ObtainSchema(ctx context.Context, modStore *state.ModuleStore, schemaStore
return err
}
if exist {
log.Printf("all schemas already exist: %#v", pReqs)
// avoid obtaining schemas if we already have it
return nil
}
Expand All @@ -159,6 +161,8 @@ func ObtainSchema(ctx context.Context, modStore *state.ModuleStore, schemaStore
return err
}

log.Printf("received schemas: %#v", ps)

for rawAddr, pJsonSchema := range ps.Schemas {
pAddr, err := tfaddr.ParseProviderSource(rawAddr)
if err != nil {
Expand Down Expand Up @@ -202,6 +206,7 @@ func ParseModuleConfiguration(ctx context.Context, fs ReadOnlyFS, modStore *stat
}

files, diags, err := parser.ParseModuleFiles(fs, modPath)
log.Printf("parsed module files: %#v, %s\nfiles (%d): %#v", err, diags, len(files), files)

sErr := modStore.UpdateParsedModuleFiles(modPath, files, err)
if sErr != nil {
Expand Down Expand Up @@ -313,6 +318,8 @@ func ParseProviderVersions(ctx context.Context, fs ReadOnlyFS, modStore *state.M

pvm, err := datadir.ParsePluginVersions(fs, modPath)

log.Printf("storing provider versions: %#v", pvm)

sErr := modStore.UpdateInstalledProviders(modPath, pvm, err)
if sErr != nil {
return sErr
Expand Down Expand Up @@ -359,6 +366,8 @@ func LoadModuleMetadata(ctx context.Context, modStore *state.ModuleStore, modPat
}
meta.ProviderReferences = providerRefs

log.Printf("storing module meta: %#v", meta)

sErr := modStore.UpdateMetadata(modPath, meta, mErr)
if sErr != nil {
return sErr
Expand Down
12 changes: 12 additions & 0 deletions internal/terraform/module/module_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ func TestParseProviderVersions_multipleVersions(t *testing.T) {
}
`),
},
// These are somewhat awkward two entries
// to account for io/fs and our own path separator differences
// See https://github.com/hashicorp/terraform-ls/issues/1025
modPathFirst + "/main.tf": &fstest.MapFile{
Data: []byte{},
},
filepath.Join(modPathFirst, "main.tf"): &fstest.MapFile{
Data: []byte(`terraform {
required_providers {
Expand Down Expand Up @@ -455,6 +461,12 @@ func TestParseProviderVersions_multipleVersions(t *testing.T) {
}
`),
},
// These are somewhat awkward two entries
// to account for io/fs and our own path separator differences
// See https://github.com/hashicorp/terraform-ls/issues/1025
modPathSecond + "/main.tf": &fstest.MapFile{
Data: []byte{},
},
filepath.Join(modPathSecond, "main.tf"): &fstest.MapFile{
Data: []byte(`terraform {
required_providers {
Expand Down
10 changes: 7 additions & 3 deletions internal/terraform/parser/module.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package parser

import (
"log"
"path/filepath"

"github.com/hashicorp/terraform-ls/internal/terraform/ast"
)

func ParseModuleFiles(fs FS, modPath string) (ast.ModFiles, ast.ModDiags, error) {
func ParseModuleFiles(filesystem FS, modPath string) (ast.ModFiles, ast.ModDiags, error) {
files := make(ast.ModFiles, 0)
diags := make(ast.ModDiags, 0)

infos, err := fs.ReadDir(modPath)
infos, err := filesystem.ReadDir(modPath)
if err != nil {
return nil, nil, err
}

log.Printf("dir entries (%d): %#v", len(infos), infos)

for _, info := range infos {
if info.IsDir() {
// We only care about files
Expand All @@ -28,9 +31,10 @@ func ParseModuleFiles(fs FS, modPath string) (ast.ModFiles, ast.ModDiags, error)

// TODO: overrides

info.Info()
fullPath := filepath.Join(modPath, name)

src, err := fs.ReadFile(fullPath)
src, err := filesystem.ReadFile(fullPath)
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 37e172f

Please sign in to comment.