github.com/codykaup/genqlient@v0.6.2/generate/example_test.go (about)

     1  package generate_test
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/codykaup/genqlient/internal/integration"
    10  )
    11  
    12  func TestGenerateExample(t *testing.T) {
    13  	integration.RunGenerateTest(t, "example/genqlient.yaml")
    14  }
    15  
    16  func TestRunExample(t *testing.T) {
    17  	if _, ok := os.LookupEnv("GITHUB_TOKEN"); !ok {
    18  		t.Skip("requires GITHUB_TOKEN to be set")
    19  	}
    20  
    21  	cmd := exec.Command("go", "run", "./example", "benjaminjkraft")
    22  	cmd.Dir = integration.RepoRoot(t)
    23  	out, err := cmd.CombinedOutput()
    24  	if err != nil {
    25  		t.Error(err)
    26  	}
    27  
    28  	got := strings.TrimSpace(string(out))
    29  	want := "benjaminjkraft is Ben Kraft created on 2009-08-03"
    30  	if got != want {
    31  		t.Errorf("output incorrect\ngot:\n%s\nwant:\n%s", got, want)
    32  	}
    33  }