-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat-otlp-support-grpc
- Loading branch information
Showing
109 changed files
with
6,223 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/stretchr/testify/require" | ||
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/config" | ||
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/metric" | ||
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/service" | ||
"github.com/thomaspoignant/go-feature-flag/notifier" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestAwsLambdaHandler_GetAdapter(t *testing.T) { | ||
type test struct { | ||
name string | ||
mode string | ||
request interface{} | ||
} | ||
|
||
tests := []test{ | ||
{ | ||
name: "APIGatewayV2 event handler", | ||
mode: "APIGatewayV2", | ||
request: events.APIGatewayV2HTTPRequest{ | ||
RequestContext: events.APIGatewayV2HTTPRequestContext{ | ||
HTTP: events.APIGatewayV2HTTPRequestContextHTTPDescription{ | ||
Method: "GET", | ||
Path: "/health", | ||
}, | ||
}, | ||
Headers: map[string]string{ | ||
"Content-Type": "application/json", | ||
}, | ||
Body: "", | ||
}, | ||
}, | ||
{ | ||
name: "APIGatewayV1 event handler", | ||
mode: "APIGatewayV1", | ||
request: events.APIGatewayProxyRequest{ | ||
HTTPMethod: "GET", | ||
Path: "/health", | ||
RequestContext: events.APIGatewayProxyRequestContext{ | ||
Path: "/health", | ||
HTTPMethod: "GET", | ||
}, | ||
Headers: map[string]string{ | ||
"Content-Type": "application/json", | ||
}, | ||
Body: "", | ||
}, | ||
}, | ||
{ | ||
name: "ALB event handler", | ||
mode: "ALB", | ||
request: events.ALBTargetGroupRequest{ | ||
HTTPMethod: "GET", | ||
Path: "/health", | ||
Headers: map[string]string{ | ||
"Content-Type": "application/json", | ||
}, | ||
Body: "", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
z, err := zap.NewProduction() | ||
require.NoError(t, err) | ||
c := &config.Config{ | ||
StartAsAwsLambda: true, | ||
AwsLambdaAdapter: tt.mode, | ||
Retriever: &config.RetrieverConf{ | ||
Kind: "file", | ||
Path: "../../../testdata/flag-config.yaml", | ||
}, | ||
} | ||
goff, err := service.NewGoFeatureFlagClient(c, z, []notifier.Notifier{}) | ||
require.NoError(t, err) | ||
apiServer := New(c, service.Services{ | ||
MonitoringService: service.NewMonitoring(goff), | ||
WebsocketService: service.NewWebsocketService(), | ||
GOFeatureFlagService: goff, | ||
Metrics: metric.Metrics{}, | ||
}, z) | ||
|
||
reqJSON, err := json.Marshal(tt.request) | ||
require.NoError(t, err) | ||
|
||
// Create a Lambda handler | ||
handler := lambda.NewHandler(apiServer.getLambdaHandler()) | ||
|
||
// Invoke the handler with the mock event | ||
response, err := handler.Invoke(context.Background(), reqJSON) | ||
require.NoError(t, err) | ||
|
||
switch strings.ToLower(tt.mode) { | ||
case "apigatewayv2": | ||
var res events.APIGatewayV2HTTPResponse | ||
err = json.Unmarshal(response, &res) | ||
require.NoError(t, err) | ||
require.Equal(t, 200, res.StatusCode) | ||
case "apigatewayv1": | ||
var res events.APIGatewayProxyResponse | ||
err = json.Unmarshal(response, &res) | ||
require.NoError(t, err) | ||
require.Equal(t, 200, res.StatusCode) | ||
case "alb": | ||
var res events.ALBTargetGroupResponse | ||
err = json.Unmarshal(response, &res) | ||
require.NoError(t, err) | ||
require.Equal(t, 200, res.StatusCode) | ||
default: | ||
require.Fail(t, "not implemented") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package api_test | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/api" | ||
Check failure on line 9 in cmd/relayproxy/api/routes_monitoring_test.go GitHub Actions / Lint
|
||
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/config" | ||
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/metric" | ||
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/service" | ||
"github.com/thomaspoignant/go-feature-flag/notifier" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestPprofEndpointsStarts(t *testing.T) { | ||
type test struct { | ||
name string | ||
MonitoringPort int | ||
Debug bool | ||
expectedStatusCode int | ||
} | ||
tests := []test{ | ||
{ | ||
name: "pprof available in proxy port", | ||
Debug: true, | ||
expectedStatusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "pprof available in monitoring port", | ||
Debug: true, | ||
MonitoringPort: 1032, | ||
expectedStatusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "pprof not available ii debug not enabled", | ||
Debug: false, | ||
MonitoringPort: 1032, | ||
expectedStatusCode: http.StatusNotFound, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
z, err := zap.NewProduction() | ||
require.NoError(t, err) | ||
c := &config.Config{ | ||
Retriever: &config.RetrieverConf{ | ||
Kind: "file", | ||
Path: "../../../testdata/flag-config.yaml", | ||
}, | ||
MonitoringPort: tt.MonitoringPort, | ||
ListenPort: 1031, | ||
Debug: tt.Debug, | ||
} | ||
|
||
goff, err := service.NewGoFeatureFlagClient(c, z, []notifier.Notifier{}) | ||
require.NoError(t, err) | ||
apiServer := api.New(c, service.Services{ | ||
MonitoringService: service.NewMonitoring(goff), | ||
WebsocketService: service.NewWebsocketService(), | ||
GOFeatureFlagService: goff, | ||
Metrics: metric.Metrics{}, | ||
}, z) | ||
|
||
portToCheck := c.ListenPort | ||
if tt.MonitoringPort != 0 { | ||
portToCheck = tt.MonitoringPort | ||
} | ||
|
||
go apiServer.Start() | ||
defer apiServer.Stop() | ||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/debug/pprof/heap", portToCheck)) | ||
require.NoError(t, err) | ||
require.Equal(t, tt.expectedStatusCode, resp.StatusCode) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.