github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/cliconfig/provider_installation_test.go (about)

     1  package cliconfig
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  	"github.com/hashicorp/terraform/internal/addrs"
     9  	"github.com/hashicorp/terraform/internal/getproviders"
    10  )
    11  
    12  func TestLoadConfig_providerInstallation(t *testing.T) {
    13  	for _, configFile := range []string{"provider-installation", "provider-installation.json"} {
    14  		t.Run(configFile, func(t *testing.T) {
    15  			got, diags := loadConfigFile(filepath.Join(fixtureDir, configFile))
    16  			if diags.HasErrors() {
    17  				t.Errorf("unexpected diagnostics: %s", diags.Err().Error())
    18  			}
    19  
    20  			want := &Config{
    21  				ProviderInstallation: []*ProviderInstallation{
    22  					{
    23  						Methods: []*ProviderInstallationMethod{
    24  							{
    25  								Location: ProviderInstallationFilesystemMirror("/tmp/example1"),
    26  								Include:  []string{"example.com/*/*"},
    27  							},
    28  							{
    29  								Location: ProviderInstallationNetworkMirror("https://tf-Mirror.example.com/"),
    30  								Include:  []string{"registry.terraform.io/*/*"},
    31  								Exclude:  []string{"registry.Terraform.io/foobar/*"},
    32  							},
    33  							{
    34  								Location: ProviderInstallationFilesystemMirror("/tmp/example2"),
    35  							},
    36  							{
    37  								Location: ProviderInstallationDirect,
    38  								Exclude:  []string{"example.com/*/*"},
    39  							},
    40  						},
    41  
    42  						DevOverrides: map[addrs.Provider]getproviders.PackageLocalDir{
    43  							addrs.MustParseProviderSourceString("hashicorp/boop"):  getproviders.PackageLocalDir(filepath.FromSlash("/tmp/boop")),
    44  							addrs.MustParseProviderSourceString("hashicorp/blorp"): getproviders.PackageLocalDir(filepath.FromSlash("/tmp/blorp")),
    45  						},
    46  					},
    47  				},
    48  			}
    49  
    50  			if diff := cmp.Diff(want, got); diff != "" {
    51  				t.Errorf("wrong result\n%s", diff)
    52  			}
    53  		})
    54  	}
    55  }
    56  
    57  func TestLoadConfig_providerInstallationErrors(t *testing.T) {
    58  	_, diags := loadConfigFile(filepath.Join(fixtureDir, "provider-installation-errors"))
    59  	want := `7 problems:
    60  
    61  - Invalid provider_installation method block: Unknown provider installation method "not_a_thing" at 2:3.
    62  - Invalid provider_installation method block: Invalid filesystem_mirror block at 1:1: "path" argument is required.
    63  - Invalid provider_installation method block: Invalid network_mirror block at 1:1: "url" argument is required.
    64  - Invalid provider_installation method block: The items inside the provider_installation block at 1:1 must all be blocks.
    65  - Invalid provider_installation method block: The blocks inside the provider_installation block at 1:1 may not have any labels.
    66  - Invalid provider_installation block: The provider_installation block at 9:1 must not have any labels.
    67  - Invalid provider_installation block: The provider_installation block at 11:1 must not be introduced with an equals sign.`
    68  
    69  	// The above error messages include only line/column location information
    70  	// and not file location information because HCL 1 does not store
    71  	// information about the filename a location belongs to. (There is a field
    72  	// for it in token.Pos but it's always an empty string in practice.)
    73  
    74  	if got := diags.Err().Error(); got != want {
    75  		t.Errorf("wrong diagnostics\ngot:\n%s\nwant:\n%s", got, want)
    76  	}
    77  }