Skip to content

Commit

Permalink
Different port for each server test case
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Mar 7, 2024
1 parent 6927578 commit 95e8a28
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
18 changes: 9 additions & 9 deletions diag/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (
func TestNewServer(t *testing.T) {
errChan := make(chan error)
conf := config.DiagConfig{
Port: 5050,
Port: 5051,
Enabled: true,
Status: config.StatusConfig{Enabled: true},
Metrics: config.MetricsConfig{Enabled: true},
}
srv := NewServer(&conf, status.NewReporter(&config.Config{SDKs: map[string]*config.SDKConfig{"sdk": {Key: "key"}}}), metrics.NewReporter(), log.NewNullLogger(), errChan)
go srv.Listen()

req, _ := http.NewRequest(http.MethodGet, "http://localhost:5050/status", http.NoBody)
req, _ := http.NewRequest(http.MethodGet, "http://localhost:5051/status", http.NoBody)
resp, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)

req, _ = http.NewRequest(http.MethodGet, "http://localhost:5050/metrics", http.NoBody)
req, _ = http.NewRequest(http.MethodGet, "http://localhost:5051/metrics", http.NoBody)
resp, err = http.DefaultClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
Expand All @@ -39,7 +39,7 @@ func TestNewServer(t *testing.T) {
func TestNewServer_NotEnabled(t *testing.T) {
errChan := make(chan error)
conf := config.DiagConfig{
Port: 5050,
Port: 5052,
Enabled: true,
Status: config.StatusConfig{Enabled: false},
Metrics: config.MetricsConfig{Enabled: false},
Expand All @@ -48,12 +48,12 @@ func TestNewServer_NotEnabled(t *testing.T) {
srv := NewServer(&conf, status.NewReporter(&config.Config{SDKs: map[string]*config.SDKConfig{"sdk": {Key: "key"}}}), metrics.NewReporter(), log.NewNullLogger(), errChan)
go srv.Listen()

req, _ := http.NewRequest(http.MethodGet, "http://localhost:5050/status", http.NoBody)
req, _ := http.NewRequest(http.MethodGet, "http://localhost:5052/status", http.NoBody)
resp, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)

req, _ = http.NewRequest(http.MethodGet, "http://localhost:5050/metrics", http.NoBody)
req, _ = http.NewRequest(http.MethodGet, "http://localhost:5052/metrics", http.NoBody)
resp, err = http.DefaultClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
Expand All @@ -66,20 +66,20 @@ func TestNewServer_NotEnabled(t *testing.T) {
func TestNewServer_NilReporters(t *testing.T) {
errChan := make(chan error)
conf := config.DiagConfig{
Port: 5050,
Port: 5053,
Enabled: true,
Status: config.StatusConfig{Enabled: true},
Metrics: config.MetricsConfig{Enabled: true},
}
srv := NewServer(&conf, nil, nil, log.NewNullLogger(), errChan)
go srv.Listen()

req, _ := http.NewRequest(http.MethodGet, "http://localhost:5050/status", http.NoBody)
req, _ := http.NewRequest(http.MethodGet, "http://localhost:5053/status", http.NoBody)
resp, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)

req, _ = http.NewRequest(http.MethodGet, "http://localhost:5050/metrics", http.NoBody)
req, _ = http.NewRequest(http.MethodGet, "http://localhost:5053/metrics", http.NoBody)
resp, err = http.DefaultClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
Expand Down
6 changes: 3 additions & 3 deletions grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNewServer(t *testing.T) {
sdkClient := sdk.NewClient(ctx, log.NewNullLogger())
defer sdkClient.Close()

srv, _ := NewServer(map[string]sdk.Client{"test": sdkClient}, nil, &config.Config{Grpc: config.GrpcConfig{Port: 5060}}, log.NewNullLogger(), errChan)
srv, _ := NewServer(map[string]sdk.Client{"test": sdkClient}, nil, &config.Config{Grpc: config.GrpcConfig{Port: 5061}}, log.NewNullLogger(), errChan)

wg := sync.WaitGroup{}
wg.Add(1)
Expand Down Expand Up @@ -117,7 +117,7 @@ MK4Li/LGWcksyoF+hbPNXMFCIA==
sdkClient := sdk.NewClient(ctx, log.NewNullLogger())
defer sdkClient.Close()

srv, _ := NewServer(map[string]sdk.Client{"test": sdkClient}, nil, &config.Config{Grpc: config.GrpcConfig{Port: 5060}, Tls: tlsConf}, log.NewNullLogger(), errChan)
srv, _ := NewServer(map[string]sdk.Client{"test": sdkClient}, nil, &config.Config{Grpc: config.GrpcConfig{Port: 5062}, Tls: tlsConf}, log.NewNullLogger(), errChan)

wg := sync.WaitGroup{}
wg.Add(1)
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestNewServer_TLS_Missing_Cert(t *testing.T) {
sdkClient := sdk.NewClient(ctx, log.NewNullLogger())
defer sdkClient.Close()

_, err := NewServer(map[string]sdk.Client{"test": sdkClient}, nil, &config.Config{Grpc: config.GrpcConfig{Port: 5060}, Tls: tlsConf}, log.NewDebugLogger(), errChan)
_, err := NewServer(map[string]sdk.Client{"test": sdkClient}, nil, &config.Config{Grpc: config.GrpcConfig{Port: 5063}, Tls: tlsConf}, log.NewDebugLogger(), errChan)
assert.Error(t, err)
}

Expand Down
3 changes: 3 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
func TestAppMain(t *testing.T) {
resetFlags()
t.Setenv("CONFIGCAT_SDKS", `{"sdk1":"XxPbCKmzIUGORk4vsufpzw/iC_KABprDEueeQs3yovVnQ"}`)
t.Setenv("CONFIGCAT_HTTP_PORT", "5081")
t.Setenv("CONFIGCAT_GRPC_PORT", "5082")
t.Setenv("CONFIGCAT_DIAG_PORT", "5083")

var exitCode int
closeSignal := make(chan os.Signal, 1)
Expand Down
6 changes: 3 additions & 3 deletions web/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestNewServer(t *testing.T) {
errChan := make(chan error)
srv, _ := NewServer(http.HandlerFunc(ServeHTTP), log.NewNullLogger(), &config.Config{Http: config.HttpConfig{Port: 5050}}, errChan)
srv, _ := NewServer(http.HandlerFunc(ServeHTTP), log.NewNullLogger(), &config.Config{Http: config.HttpConfig{Port: 5071}}, errChan)

wg := sync.WaitGroup{}
wg.Add(1)
Expand Down Expand Up @@ -84,7 +84,7 @@ MK4Li/LGWcksyoF+hbPNXMFCIA==
{Cert: strings.ReplaceAll(cert, "\\", "/"), Key: strings.ReplaceAll(key, "\\", "/")},
},
}
srv, _ := NewServer(http.HandlerFunc(ServeHTTP), log.NewNullLogger(), &config.Config{Http: config.HttpConfig{Port: 5050}, Tls: tlsConf}, errChan)
srv, _ := NewServer(http.HandlerFunc(ServeHTTP), log.NewNullLogger(), &config.Config{Http: config.HttpConfig{Port: 5072}, Tls: tlsConf}, errChan)

wg := sync.WaitGroup{}
wg.Add(1)
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestNewServer_TLS_Missing_Cert(t *testing.T) {
{Cert: "./non-existing.cert", Key: "./non-existing.key"},
},
}
_, err := NewServer(http.HandlerFunc(ServeHTTP), log.NewNullLogger(), &config.Config{Http: config.HttpConfig{Port: 5050}, Tls: tlsConf}, errChan)
_, err := NewServer(http.HandlerFunc(ServeHTTP), log.NewNullLogger(), &config.Config{Http: config.HttpConfig{Port: 5073}, Tls: tlsConf}, errChan)
assert.Error(t, err)
}

Expand Down

0 comments on commit 95e8a28

Please sign in to comment.