github.com/Azure/tflint-ruleset-basic-ext@v0.6.0/integration/integration_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"bytes"
     5  	"os"
     6  	"os/exec"
     7  	"testing"
     8  )
     9  
    10  func TestIntegration(t *testing.T) {
    11  	cases := []struct {
    12  		Name    string
    13  		Command *exec.Cmd
    14  		Dir     string
    15  	}{
    16  		{
    17  			Name:    "basic",
    18  			Command: exec.Command("tflint", "--format", "json", "--force"),
    19  			Dir:     "basic",
    20  		},
    21  	}
    22  
    23  	dir, _ := os.Getwd()
    24  	defer os.Chdir(dir)
    25  
    26  	for _, tc := range cases {
    27  		testDir := dir + "/" + tc.Dir
    28  		os.Chdir(testDir)
    29  
    30  		var stdout, stderr bytes.Buffer
    31  		tc.Command.Stdout = &stdout
    32  		tc.Command.Stderr = &stderr
    33  		if err := tc.Command.Run(); err != nil {
    34  			t.Fatalf("Failed `%s`: %s, stdout=%s stderr=%s", tc.Name, err, stdout.String(), stderr.String())
    35  		}
    36  	}
    37  }