Skip to content

Commit

Permalink
feat: use opentofu schema and registry libs
Browse files Browse the repository at this point in the history
Signed-off-by: Gamunu Balagalla <gamunu@fastcode.io>
  • Loading branch information
gamunu committed Sep 12, 2024
1 parent c8b8fa3 commit 649e2a3
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 304 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ require (

require (
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
Expand Down Expand Up @@ -95,8 +94,6 @@ require (
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
go.bobheadxi.dev/streamline v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.53.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0
go.opentelemetry.io/otel v1.28.0
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/mod v0.19.0 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
Expand Down Expand Up @@ -404,10 +402,6 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.53.0 h1:IVtyPth4Rs5P8wIf0mP2KVKFNTJ4paX9qQ4Hkh5gFdc=
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.53.0/go.mod h1:ImRBLMJv177/pwiLZ7tU7HDGNdBv7rS0HQ99eN/zBl8=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
Expand Down
10 changes: 5 additions & 5 deletions internal/features/modules/jobs/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ func TestPreloadEmbeddedSchema_basic(t *testing.T) {
dataDir := "data"
schemasFS := fstest.MapFS{
dataDir: &fstest.MapFile{Mode: fs.ModeDir},
dataDir + "/registry.terraform.io": &fstest.MapFile{Mode: fs.ModeDir},
dataDir + "/registry.terraform.io/hashicorp": &fstest.MapFile{Mode: fs.ModeDir},
dataDir + "/registry.terraform.io/hashicorp/random": &fstest.MapFile{Mode: fs.ModeDir},
dataDir + "/registry.terraform.io/hashicorp/random/1.0.0": &fstest.MapFile{Mode: fs.ModeDir},
dataDir + "/registry.terraform.io/hashicorp/random/1.0.0/schema.json.gz": &fstest.MapFile{
dataDir + "/registry.opentofu.org": &fstest.MapFile{Mode: fs.ModeDir},
dataDir + "/registry.opentofu.org/hashicorp": &fstest.MapFile{Mode: fs.ModeDir},
dataDir + "/registry.opentofu.org/hashicorp/random": &fstest.MapFile{Mode: fs.ModeDir},
dataDir + "/registry.opentofu.org/hashicorp/random/1.0.0": &fstest.MapFile{Mode: fs.ModeDir},
dataDir + "/registry.opentofu.org/hashicorp/random/1.0.0/schema.json.gz": &fstest.MapFile{
Data: gzipCompressBytes(t, []byte(randomSchemaJSON)),
},
}
Expand Down
10 changes: 5 additions & 5 deletions internal/features/rootmodules/jobs/lockfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestParseProviderVersions(t *testing.T) {
fs := fstest.MapFS{
modPath: &fstest.MapFile{Mode: fs.ModeDir},
filepath.Join(modPath, ".terraform.lock.hcl"): &fstest.MapFile{
Data: []byte(`provider "registry.terraform.io/hashicorp/aws" {
Data: []byte(`provider "registry.opentofu.org/hashicorp/aws" {
version = "4.23.0"
hashes = [
"h1:j6RGCfnoLBpzQVOKUbGyxf4EJtRvQClKplO+WdXL5O0=",
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestParseProviderVersions_multipleVersions(t *testing.T) {
fs := fstest.MapFS{
modPathFirst: &fstest.MapFile{Mode: fs.ModeDir},
filepath.Join(modPathFirst, ".terraform.lock.hcl"): &fstest.MapFile{
Data: []byte(`provider "registry.terraform.io/hashicorp/aws" {
Data: []byte(`provider "registry.opentofu.org/hashicorp/aws" {
version = "4.23.0"
hashes = [
"h1:j6RGCfnoLBpzQVOKUbGyxf4EJtRvQClKplO+WdXL5O0=",
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestParseProviderVersions_multipleVersions(t *testing.T) {

modPathSecond: &fstest.MapFile{Mode: fs.ModeDir},
filepath.Join(modPathSecond, ".terraform.lock.hcl"): &fstest.MapFile{
Data: []byte(`provider "registry.terraform.io/hashicorp/aws" {
Data: []byte(`provider "registry.opentofu.org/hashicorp/aws" {
version = "4.25.0"
hashes = [
"h1:j6RGCfnoLBpzQVOKUbGyxf4EJtRvQClKplO+WdXL5O0=",
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestParseProviderVersions_multipleVersions(t *testing.T) {
&tfjson.ProviderSchemas{
FormatVersion: "1.0",
Schemas: map[string]*tfjson.ProviderSchema{
"registry.terraform.io/hashicorp/aws": {
"registry.opentofu.org/hashicorp/aws": {
ConfigSchema: &tfjson.Schema{
Block: &tfjson.SchemaBlock{
Attributes: map[string]*tfjson.SchemaAttribute{
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestParseProviderVersions_multipleVersions(t *testing.T) {
&tfjson.ProviderSchemas{
FormatVersion: "1.0",
Schemas: map[string]*tfjson.ProviderSchema{
"registry.terraform.io/hashicorp/aws": {
"registry.opentofu.org/hashicorp/aws": {
ConfigSchema: &tfjson.Schema{
Block: &tfjson.SchemaBlock{
Attributes: map[string]*tfjson.SchemaAttribute{
Expand Down
38 changes: 13 additions & 25 deletions internal/features/rootmodules/jobs/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,9 @@ func TestStateStore_ListSchemas(t *testing.T) {
},
Schema: &tfschema.ProviderSchema{
Provider: &schema.BodySchema{
Detail: "hashicorp/aws-local 0.9.0",
HoverURL: "https://registry.terraform.io/providers/hashicorp/aws-local/0.9.0/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/aws-local/0.9.0/docs",
Tooltip: "hashicorp/aws-local Documentation",
},
Detail: "hashicorp/aws-local 0.9.0",
HoverURL: "",
DocsLink: nil,
Attributes: map[string]*schema.AttributeSchema{},
Blocks: map[string]*schema.BlockSchema{},
},
Expand All @@ -736,12 +733,9 @@ func TestStateStore_ListSchemas(t *testing.T) {
},
Schema: &tfschema.ProviderSchema{
Provider: &schema.BodySchema{
Detail: "hashicorp/aws-local 1.0.0",
HoverURL: "https://registry.terraform.io/providers/hashicorp/aws-local/1.0.0/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/aws-local/1.0.0/docs",
Tooltip: "hashicorp/aws-local Documentation",
},
Detail: "hashicorp/aws-local 1.0.0",
HoverURL: "",
DocsLink: nil,
Attributes: map[string]*schema.AttributeSchema{},
Blocks: map[string]*schema.BlockSchema{},
},
Expand All @@ -759,12 +753,9 @@ func TestStateStore_ListSchemas(t *testing.T) {
},
Schema: &tfschema.ProviderSchema{
Provider: &schema.BodySchema{
Detail: "hashicorp/aws-local 1.3.0",
HoverURL: "https://registry.terraform.io/providers/hashicorp/aws-local/1.3.0/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/aws-local/1.3.0/docs",
Tooltip: "hashicorp/aws-local Documentation",
},
Detail: "hashicorp/aws-local 1.3.0",
HoverURL: "",
DocsLink: nil,
Attributes: map[string]*schema.AttributeSchema{},
Blocks: map[string]*schema.BlockSchema{},
},
Expand All @@ -782,19 +773,16 @@ func TestStateStore_ListSchemas(t *testing.T) {
},
Schema: &tfschema.ProviderSchema{
Provider: &schema.BodySchema{
Detail: "hashicorp/blah 1.0.0",
HoverURL: "https://registry.terraform.io/providers/hashicorp/blah/1.0.0/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/blah/1.0.0/docs",
Tooltip: "hashicorp/blah Documentation",
},
Detail: "hashicorp/blah 1.0.0",
HoverURL: "",
DocsLink: nil,
Attributes: map[string]*schema.AttributeSchema{},
Blocks: map[string]*schema.BlockSchema{},
},
},
},
}
if diff := cmp.Diff(expectedSchemas, schemas, cmpOpts); diff != "" {
if diff := cmp.Diff(schemas, expectedSchemas, cmpOpts); diff != "" {
t.Fatalf("unexpected schemas: %s", diff)
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/langserver/handlers/command/module_calls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ func Test_parseModuleRecords(t *testing.T) {
SourceAddr: "terraform-aws-modules/ec2-instance/aws",
Version: "2.12.0",
SourceType: "tfregistry",
DocsLink: "https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws/latest?utm_content=workspace%2FexecuteCommand%2Fmodule.calls&utm_source=terraform-ls",
DocsLink: "",
DependentModules: []moduleCall{},
},
{
Name: "eks",
SourceAddr: "terraform-aws-modules/eks/aws",
Version: "17.20.0",
SourceType: "tfregistry",
DocsLink: "https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest?utm_content=workspace%2FexecuteCommand%2Fmodule.calls&utm_source=terraform-ls",
DocsLink: "",
DependentModules: []moduleCall{},
},
{
Expand Down Expand Up @@ -112,7 +112,7 @@ func Test_parseModuleRecords_v1_1(t *testing.T) {
Declared: map[string]tfmod.DeclaredModuleCall{
"ec2_instances": {
LocalName: "ec2_instances",
SourceAddr: tfaddr.MustParseModuleSource("registry.terraform.io/terraform-aws-modules/ec2-instance/aws"),
SourceAddr: tfaddr.MustParseModuleSource("registry.opentofu.org/terraform-aws-modules/ec2-instance/aws"),
Version: version.MustConstraints(version.NewConstraint("2.12.0")),
},
},
Expand All @@ -123,7 +123,7 @@ func Test_parseModuleRecords_v1_1(t *testing.T) {
SourceAddr: "terraform-aws-modules/ec2-instance/aws",
Version: "2.12.0",
SourceType: "tfregistry",
DocsLink: "https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws/latest?utm_content=workspace%2FexecuteCommand%2Fmodule.calls&utm_source=terraform-ls",
DocsLink: "",
DependentModules: []moduleCall{},
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/langserver/handlers/document_link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestDocumentLink_withValidData(t *testing.T) {
"character": 15
}
},
"target": "https://registry.terraform.io/providers/test/test/latest/docs?utm_content=documentLink\u0026utm_source=terraform-ls"
"target": "https://registry.opentofu.org/providers/test/test/latest/docs?utm_content=documentLink\u0026utm_source=terraform-ls"
}
]
}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,18 @@ func TestLangServer_workspaceExecuteCommand_moduleProviders_basic(t *testing.T)
"result": {
"v": 0,
"provider_requirements": {
"registry.terraform.io/hashicorp/aws": {
"registry.opentofu.org/hashicorp/aws": {
"display_name": "hashicorp/aws",
"version_constraint":"1.2.3",
"docs_link": "https://registry.terraform.io/providers/hashicorp/aws/latest?utm_content=workspace%2FexecuteCommand%2Fmodule.providers\u0026utm_source=terraform-ls"
},
"registry.terraform.io/hashicorp/google": {
"registry.opentofu.org/hashicorp/google": {
"display_name": "hashicorp/google",
"version_constraint": "\u003e= 2.0.0",
"docs_link": "https://registry.terraform.io/providers/hashicorp/google/latest?utm_content=workspace%2FexecuteCommand%2Fmodule.providers\u0026utm_source=terraform-ls"
}
},
"installed_providers":{
"registry.terraform.io/hashicorp/aws": "1.2.3",
"registry.terraform.io/hashicorp/google": "2.5.5"
"registry.opentofu.org/hashicorp/aws": "1.2.3",
"registry.opentofu.org/hashicorp/google": "2.5.5"
}
}
}`)
Expand Down
Loading

0 comments on commit 649e2a3

Please sign in to comment.