github.com/hazelops/ize@v1.1.12-0.20230915191306-97d7c0e48f11/tests/e2e/bastion_tunnel_test.go (about)

     1  //go:build e2e && bastion_tunnel
     2  // +build e2e,bastion_tunnel
     3  
     4  package test
     5  
     6  import (
     7  	"io/fs"
     8  	"os"
     9  	"path/filepath"
    10  	"strings"
    11  	"testing"
    12  	"time"
    13  )
    14  
    15  func TestIzeUpInfra(t *testing.T) {
    16  	if examplesRootDir == "" {
    17  		t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH")
    18  	}
    19  
    20  	foundIZEConfig := false
    21  	err := filepath.Walk(examplesRootDir, func(path string, info fs.FileInfo, err error) error {
    22  		if err != nil {
    23  			return err
    24  		}
    25  
    26  		if info.Name() == "ize.toml" {
    27  			foundIZEConfig = true
    28  		}
    29  
    30  		return nil
    31  	})
    32  	if err != nil {
    33  		t.Fatalf("Failed listing files in project template path %s: %s", examplesRootDir, err)
    34  	}
    35  
    36  	if !foundIZEConfig {
    37  		t.Fatalf("No ize.toml file in project template path %s", examplesRootDir)
    38  	}
    39  
    40  	defer recovery(t)
    41  
    42  	ize := NewBinary(t, izeBinary, examplesRootDir)
    43  
    44  	stdout, stderr, err := ize.RunRaw("up", "infra")
    45  
    46  	if err != nil {
    47  		t.Errorf("error: %s", err)
    48  	}
    49  
    50  	if stderr != "" {
    51  		t.Errorf("unexpected stderr output ize up all: %s", err)
    52  	}
    53  
    54  	if !strings.Contains(stdout, "Deploy infra completed!") {
    55  		t.Errorf("No success message detected after all up:\n%s", stdout)
    56  	}
    57  
    58  	if os.Getenv("RUNNER_DEBUG") == "1" {
    59  		t.Log(stdout)
    60  	}
    61  
    62  	time.Sleep(time.Minute)
    63  }
    64  
    65  func TestIzeTunnelUp(t *testing.T) {
    66  	if examplesRootDir == "" {
    67  		t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH")
    68  	}
    69  
    70  	defer recovery(t)
    71  
    72  	ize := NewBinary(t, izeBinary, examplesRootDir)
    73  
    74  	home, err := os.UserHomeDir()
    75  	if err != nil {
    76  		t.Errorf("error: %s", err)
    77  	}
    78  
    79  	stdout, stderr, err := ize.RunRaw("tunnel", "up", "--ssh-public-key", filepath.Join(home, ".ssh", "id_rsa_tunnel_test.pub"), "--ssh-private-key", filepath.Join(home, ".ssh", "id_rsa_tunnel_test"))
    80  
    81  	if err != nil {
    82  		t.Errorf("error: %s", err)
    83  	}
    84  
    85  	if stderr != "" {
    86  		t.Errorf("unexpected stderr output ize tunnel: %s", err)
    87  	}
    88  
    89  	t.Log(stdout)
    90  
    91  	if !strings.Contains(stdout, "Tunnel is up! Forwarded ports:") {
    92  		t.Errorf("No success message detected after tunnel:\n%s", stdout)
    93  	}
    94  
    95  	if os.Getenv("RUNNER_DEBUG") == "1" {
    96  		t.Log(stdout)
    97  	}
    98  }
    99  
   100  func TestIzeTunnelStatus(t *testing.T) {
   101  	if examplesRootDir == "" {
   102  		t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH")
   103  	}
   104  
   105  	defer recovery(t)
   106  
   107  	ize := NewBinary(t, izeBinary, examplesRootDir)
   108  
   109  	stdout, stderr, err := ize.RunRaw("tunnel", "status")
   110  
   111  	if err != nil {
   112  		t.Errorf("error: %s", err)
   113  	}
   114  
   115  	if stderr != "" {
   116  		t.Errorf("unexpected stderr output ize tunnel status: %s", err)
   117  	}
   118  
   119  	if !strings.Contains(stdout, "Tunnel is up. Forwarding config:") {
   120  		t.Errorf("No success message detected after tunnel status:\n%s", stdout)
   121  	}
   122  
   123  	if os.Getenv("RUNNER_DEBUG") == "1" {
   124  		t.Log(stdout)
   125  	}
   126  }
   127  
   128  func TestIzeTunnelDown(t *testing.T) {
   129  	if examplesRootDir == "" {
   130  		t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH")
   131  	}
   132  
   133  	defer recovery(t)
   134  
   135  	ize := NewBinary(t, izeBinary, examplesRootDir)
   136  
   137  	stdout, stderr, err := ize.RunRaw("tunnel", "down")
   138  
   139  	if err != nil {
   140  		t.Errorf("error: %s", err)
   141  	}
   142  
   143  	if stderr != "" {
   144  		t.Errorf("unexpected stderr output ize tunnel down: %s", err)
   145  	}
   146  
   147  	if !strings.Contains(stdout, "Tunnel is down!") {
   148  		t.Errorf("No success message detected after tunnel down:\n%s", stdout)
   149  	}
   150  
   151  	if os.Getenv("RUNNER_DEBUG") == "1" {
   152  		t.Log(stdout)
   153  	}
   154  }
   155  
   156  func TestIzeDown(t *testing.T) {
   157  	if examplesRootDir == "" {
   158  		t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH")
   159  	}
   160  
   161  	defer recovery(t)
   162  
   163  	ize := NewBinary(t, izeBinary, examplesRootDir)
   164  
   165  	stdout, stderr, err := ize.RunRaw("down", "--auto-approve")
   166  
   167  	if err != nil {
   168  		t.Errorf("error: %s", err)
   169  	}
   170  
   171  	if stderr != "" {
   172  		t.Errorf("unexpected stderr output ize down all: %s", err)
   173  	}
   174  
   175  	if !strings.Contains(stdout, "Destroy all completed!") {
   176  		t.Errorf("No success message detected after all down:\n%s", stdout)
   177  	}
   178  
   179  	if os.Getenv("RUNNER_DEBUG") == "1" {
   180  		t.Log(stdout)
   181  	}
   182  }