github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/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("testdata", "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.12.0 core package...") { 35 t.Errorf("success message is missing from output:\n%s", stdout) 36 } 37 if !strings.Contains(stdout, "Creating terraform_0.12.0-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("testdata", "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 // Here we have to check each provider separately 69 // because it's internally held in a map (i.e. not guaranteed order) 70 71 if !strings.Contains(stdout, `- Resolving "aws" provider (~> 2.26.0)... 72 - Checking for provider plugin on https://releases.hashicorp.com... 73 - Downloading plugin for provider "aws" (hashicorp/aws) 2.26.0...`) { 74 t.Errorf("success message is missing from output:\n%s", stdout) 75 } 76 77 if !strings.Contains(stdout, `- Resolving "kubernetes" provider (1.8.0)... 78 - Checking for provider plugin on https://releases.hashicorp.com... 79 - Downloading plugin for provider "kubernetes" (hashicorp/kubernetes) 1.8.0... 80 - Resolving "kubernetes" provider (1.8.1)... 81 - Checking for provider plugin on https://releases.hashicorp.com... 82 - Downloading plugin for provider "kubernetes" (hashicorp/kubernetes) 1.8.1... 83 - Resolving "kubernetes" provider (1.9.0)... 84 - Checking for provider plugin on https://releases.hashicorp.com... 85 - Downloading plugin for provider "kubernetes" (hashicorp/kubernetes) 1.9.0...`) { 86 t.Errorf("success message is missing from output:\n%s", stdout) 87 } 88 89 if !strings.Contains(stdout, `- Resolving "null" provider (2.1.0)... 90 - Checking for provider plugin on https://releases.hashicorp.com... 91 - Downloading plugin for provider "null" (hashicorp/null) 2.1.0...`) { 92 t.Errorf("success message is missing from output:\n%s", stdout) 93 } 94 95 if !strings.Contains(stdout, "Fetching Terraform 0.12.0 core package...") { 96 t.Errorf("success message is missing from output:\n%s", stdout) 97 } 98 if !strings.Contains(stdout, "Creating terraform_0.12.0-bundle") { 99 t.Errorf("success message is missing from output:\n%s", stdout) 100 } 101 if !strings.Contains(stdout, "All done!") { 102 t.Errorf("success message is missing from output:\n%s", stdout) 103 } 104 }