github.com/rebelkathi/terraform-@v0.11.12-beta1/tools/terraform-bundle/e2etest/package_test.go (about)

     1  package e2etest
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/terraform/e2e"
     9  )
    10  
    11  func TestPackage_empty(t *testing.T) {
    12  	t.Parallel()
    13  
    14  	// This test reaches out to releases.hashicorp.com to download the
    15  	// template provider, so it can only run if network access is allowed.
    16  	// We intentionally don't try to stub this here, because there's already
    17  	// a stubbed version of this in the "command" package and so the goal here
    18  	// is to test the interaction with the real repository.
    19  	skipIfCannotAccessNetwork(t)
    20  
    21  	fixturePath := filepath.Join("test-fixtures", "empty")
    22  	tfBundle := e2e.NewBinary(bundleBin, fixturePath)
    23  	defer tfBundle.Close()
    24  
    25  	stdout, stderr, err := tfBundle.Run("package", "terraform-bundle.hcl")
    26  	if err != nil {
    27  		t.Errorf("unexpected error: %s", err)
    28  	}
    29  
    30  	if stderr != "" {
    31  		t.Errorf("unexpected stderr output:\n%s", stderr)
    32  	}
    33  
    34  	if !strings.Contains(stdout, "Fetching Terraform 0.10.1 core package...") {
    35  		t.Errorf("success message is missing from output:\n%s", stdout)
    36  	}
    37  	if !strings.Contains(stdout, "Creating terraform_0.10.1-bundle") {
    38  		t.Errorf("success message is missing from output:\n%s", stdout)
    39  	}
    40  	if !strings.Contains(stdout, "All done!") {
    41  		t.Errorf("success message is missing from output:\n%s", stdout)
    42  	}
    43  }
    44  
    45  func TestPackage_manyProviders(t *testing.T) {
    46  	t.Parallel()
    47  
    48  	// This test reaches out to releases.hashicorp.com to download the
    49  	// template provider, so it can only run if network access is allowed.
    50  	// We intentionally don't try to stub this here, because there's already
    51  	// a stubbed version of this in the "command" package and so the goal here
    52  	// is to test the interaction with the real repository.
    53  	skipIfCannotAccessNetwork(t)
    54  
    55  	fixturePath := filepath.Join("test-fixtures", "many-providers")
    56  	tfBundle := e2e.NewBinary(bundleBin, fixturePath)
    57  	defer tfBundle.Close()
    58  
    59  	stdout, stderr, err := tfBundle.Run("package", "terraform-bundle.hcl")
    60  	if err != nil {
    61  		t.Errorf("unexpected error: %s", err)
    62  	}
    63  
    64  	if stderr != "" {
    65  		t.Errorf("unexpected stderr output:\n%s", stderr)
    66  	}
    67  
    68  	if !strings.Contains(stdout, "Checking for available provider plugins on ") {
    69  		t.Errorf("success message is missing from output:\n%s", stdout)
    70  	}
    71  
    72  	// Here we have to check each provider separately
    73  	// because it's internally held in a map (i.e. not guaranteed order)
    74  
    75  	if !strings.Contains(stdout, `- Resolving "aws" provider (~> 0.1)...
    76  - Downloading plugin for provider "aws" (0.1.4)...`) {
    77  		t.Errorf("success message is missing from output:\n%s", stdout)
    78  	}
    79  
    80  	if !strings.Contains(stdout, `- Resolving "kubernetes" provider (0.1.0)...
    81  - Downloading plugin for provider "kubernetes" (0.1.0)...
    82  - Resolving "kubernetes" provider (0.1.1)...
    83  - Downloading plugin for provider "kubernetes" (0.1.1)...
    84  - Resolving "kubernetes" provider (0.1.2)...
    85  - Downloading plugin for provider "kubernetes" (0.1.2)...`) {
    86  		t.Errorf("success message is missing from output:\n%s", stdout)
    87  	}
    88  
    89  	if !strings.Contains(stdout, `- Resolving "null" provider (0.1.0)...
    90  - Downloading plugin for provider "null" (0.1.0)...`) {
    91  		t.Errorf("success message is missing from output:\n%s", stdout)
    92  	}
    93  
    94  	if !strings.Contains(stdout, "Fetching Terraform 0.10.1 core package...") {
    95  		t.Errorf("success message is missing from output:\n%s", stdout)
    96  	}
    97  	if !strings.Contains(stdout, "Creating terraform_0.10.1-bundle") {
    98  		t.Errorf("success message is missing from output:\n%s", stdout)
    99  	}
   100  	if !strings.Contains(stdout, "All done!") {
   101  		t.Errorf("success message is missing from output:\n%s", stdout)
   102  	}
   103  }