github.com/etecs-ru/gnomock@v0.13.2/sdktest/sdk_test.go (about)

     1  package sdktest
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"os"
     7  	"os/exec"
     8  	"testing"
     9  
    10  	"github.com/etecs-ru/gnomock/internal/gnomockd"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestMain(m *testing.M) {
    15  	os.Exit(testMain(m))
    16  }
    17  
    18  func testMain(m *testing.M) int {
    19  	srv := http.Server{
    20  		Addr:    "127.0.0.1:23042",
    21  		Handler: gnomockd.Handler(),
    22  	}
    23  
    24  	defer func() {
    25  		_ = srv.Shutdown(context.Background())
    26  	}()
    27  
    28  	go func() {
    29  		_ = srv.ListenAndServe()
    30  	}()
    31  
    32  	return m.Run()
    33  }
    34  
    35  func TestPython(t *testing.T) {
    36  	t.Parallel()
    37  
    38  	require.NoError(t, os.Chdir("./python"))
    39  
    40  	cmd := exec.Command("/bin/bash", "./run.sh")
    41  	out, err := cmd.CombinedOutput()
    42  	require.NoErrorf(t, err, "got error with output: %s", string(out))
    43  }