mirror of https://github.com/go-gost/gost.git
WIP
parent
c8b48dc248
commit
c06eb0d331
|
|
@ -35,6 +35,6 @@ cmd/gost/gost
|
||||||
snap
|
snap
|
||||||
|
|
||||||
*.pem
|
*.pem
|
||||||
*.yaml
|
/*.yaml
|
||||||
*.txt
|
*.txt
|
||||||
dist/
|
dist/
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,20 @@
|
||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/testcontainers/testcontainers-go/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var SharedNetworkName string
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
// Compile the gost binary
|
// Compile the gost binary
|
||||||
cmd := exec.Command("go", "build", "-o", "/tmp/gost-test-bin", "../../cmd/gost")
|
cmd := exec.Command("go", "build", "-o", "/tmp/gost-test-bin", "../../cmd/gost")
|
||||||
cmd.Env = append(os.Environ(), "CGO_ENABLED=0")
|
cmd.Env = append(os.Environ(), "CGO_ENABLED=0")
|
||||||
|
|
@ -17,12 +24,23 @@ func TestMain(m *testing.M) {
|
||||||
fmt.Printf("Failed to compile gost: %v\n", err)
|
fmt.Printf("Failed to compile gost: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
os.Remove("/tmp/gost-test-bin")
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Create a shared Docker network
|
||||||
|
net, err := network.New(ctx)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to create network: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
SharedNetworkName = net.Name
|
||||||
|
|
||||||
// Run tests
|
// Run tests
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
os.Remove("/tmp/gost-test-bin")
|
net.Remove(ctx)
|
||||||
|
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,11 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/testcontainers/testcontainers-go"
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/network"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ParallelSelectorSuite struct {
|
type ParallelSelectorSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
net *testcontainers.DockerNetwork
|
|
||||||
echoC testcontainers.Container
|
echoC testcontainers.Container
|
||||||
echoIP string
|
echoIP string
|
||||||
}
|
}
|
||||||
|
|
@ -22,11 +20,7 @@ type ParallelSelectorSuite struct {
|
||||||
func (s *ParallelSelectorSuite) SetupSuite() {
|
func (s *ParallelSelectorSuite) SetupSuite() {
|
||||||
s.ctx = context.Background()
|
s.ctx = context.Background()
|
||||||
|
|
||||||
net, err := network.New(s.ctx)
|
echoC, err := RunEchoContainer(s.ctx, SharedNetworkName)
|
||||||
s.Require().NoError(err)
|
|
||||||
s.net = net
|
|
||||||
|
|
||||||
echoC, err := RunEchoContainer(s.ctx, s.net.Name)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.echoC = echoC
|
s.echoC = echoC
|
||||||
|
|
||||||
|
|
@ -39,13 +33,10 @@ func (s *ParallelSelectorSuite) TearDownSuite() {
|
||||||
if s.echoC != nil {
|
if s.echoC != nil {
|
||||||
s.echoC.Terminate(s.ctx)
|
s.echoC.Terminate(s.ctx)
|
||||||
}
|
}
|
||||||
if s.net != nil {
|
|
||||||
s.net.Remove(s.ctx)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ParallelSelectorSuite) TestParallelSelector() {
|
func (s *ParallelSelectorSuite) TestParallelSelector() {
|
||||||
gostC, err := RunGostContainer(s.ctx, s.net.Name, "testdata/parallel_selector/server.yaml")
|
gostC, err := RunGostContainer(s.ctx, SharedNetworkName, "testdata/parallel_selector/server.yaml")
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
defer gostC.Terminate(s.ctx)
|
defer gostC.Terminate(s.ctx)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
services:
|
||||||
|
- name: proxy
|
||||||
|
addr: :8080
|
||||||
|
handler:
|
||||||
|
type: http
|
||||||
|
chain: my-chain
|
||||||
|
listener:
|
||||||
|
type: tcp
|
||||||
|
|
||||||
|
- name: dummy-1
|
||||||
|
addr: :18081
|
||||||
|
handler:
|
||||||
|
type: http
|
||||||
|
|
||||||
|
chains:
|
||||||
|
- name: my-chain
|
||||||
|
hops:
|
||||||
|
- name: hop-1
|
||||||
|
selector:
|
||||||
|
strategy: parallel
|
||||||
|
nodes:
|
||||||
|
- name: node-1
|
||||||
|
addr: 127.0.0.1:18081
|
||||||
|
connector:
|
||||||
|
type: http
|
||||||
|
# non existed node
|
||||||
|
- name: node-2
|
||||||
|
addr: 127.0.0.1:18082
|
||||||
|
connector:
|
||||||
|
type: http
|
||||||
|
|
@ -26,6 +26,8 @@ func RunGostContainer(ctx context.Context, networkName, yamlPath string) (testco
|
||||||
FromDockerfile: testcontainers.FromDockerfile{
|
FromDockerfile: testcontainers.FromDockerfile{
|
||||||
Context: ".",
|
Context: ".",
|
||||||
Dockerfile: "Dockerfile",
|
Dockerfile: "Dockerfile",
|
||||||
|
Repo: "gost-e2e",
|
||||||
|
Tag: "latest",
|
||||||
KeepImage: true,
|
KeepImage: true,
|
||||||
},
|
},
|
||||||
Networks: []string{networkName},
|
Networks: []string{networkName},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue