Skip to content

Commit

Permalink
add istio test
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Sep 25, 2024
1 parent 7e7e866 commit 05f9222
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
21 changes: 20 additions & 1 deletion backend/controller/scaling/kube_scaling_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package scaling_test
import (
"context"
"fmt"
"strconv"
"strings"
"sync"
"testing"
Expand All @@ -31,13 +32,31 @@ func runKubeScalingTest(t *testing.T, istio bool) {
done.Store(false)
routineStopped := sync.WaitGroup{}
routineStopped.Add(1)
echoDeployment := map[string]string{}
in.Run(t,
in.WithIstio(istio),
in.CopyModule("echo"),
in.Deploy("echo"),
in.CopyModule("naughty"),
in.Deploy("naughty"),
in.Call("echo", "echo", "Bob", func(t testing.TB, response string) {
assert.Equal(t, "Hello, Bob!!!", response)
}),
in.VerifyKubeState(func(ctx context.Context, t testing.TB, namespace string, client *kubernetes.Clientset) {
deps, err := client.AppsV1().Deployments(namespace).List(ctx, v1.ListOptions{})
assert.NoError(t, err)
for _, dep := range deps.Items {
if strings.HasPrefix(dep.Name, "dpl-echo") {
echoDeployment["name"] = dep.Name
}
}
assert.NotEqual(t, "", echoDeployment["name"])
}),
in.Call("naughty", "beNaughty", echoDeployment, func(t testing.TB, response string) {
// If istio is not present we should be able to ping the echo service directly.
// Istio should prevent this
assert.Equal(t, strconv.FormatBool(!istio), response)
}),
in.EditFile("echo", func(content []byte) []byte {
return []byte(strings.ReplaceAll(string(content), "Hello", "Bye"))
}, "echo.go"),
Expand Down Expand Up @@ -70,7 +89,7 @@ func runKubeScalingTest(t *testing.T, istio bool) {
assert.NoError(t, err)
depCount := 0
for _, dep := range deps.Items {
if strings.HasPrefix(dep.Name, "dpl-echo") || strings.HasPrefix(dep.Name, "dpl-time") {
if strings.HasPrefix(dep.Name, "dpl-echo") {
depCount++
service, err := client.CoreV1().Services(namespace).Get(ctx, dep.Name, v1.GetOptions{})
assert.NoError(t, err)
Expand Down
2 changes: 2 additions & 0 deletions backend/controller/scaling/testdata/go/naughty/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "naughty"
language = "go"
8 changes: 8 additions & 0 deletions backend/controller/scaling/testdata/go/naughty/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module ftl/naughty

go 1.23.0

replace (
github.com/TBD54566975/ftl => ./../../../../../..

)
Empty file.
29 changes: 29 additions & 0 deletions backend/controller/scaling/testdata/go/naughty/naughty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This is the echo module.
package naughty

import (
"context"
"fmt"
"io"
"net/http"
"strconv"
)

// BeNaughty attempts to ping echo directly and returns true if successful
//
//ftl:verb export
func BeNaughty(ctx context.Context, endpoint map[string]string) (string, error) {
url := "http://" + endpoint["name"] + ":8893/healthz" // Replace with your actual URL

resp, err := http.Get(url)
if err != nil {
return fmt.Sprintf("Error making GET request: to %s %v\n", url, err), nil
}
defer resp.Body.Close()

_, err = io.ReadAll(resp.Body)
if err != nil {
return fmt.Sprintf("Error reading response body: %v\n", err), nil
}
return strconv.FormatBool(resp.StatusCode == 200), nil
}

0 comments on commit 05f9222

Please sign in to comment.