forked from kgateway-dev/kgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo_logging_test.go
68 lines (55 loc) · 2.25 KB
/
info_logging_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//go:build ignore
package example
// This file is an example for developers.
import (
"context"
"os"
"path/filepath"
"testing"
"time"
"github.com/kgateway-dev/kgateway/pkg/utils/envutils"
"github.com/kgateway-dev/kgateway/test/testutils"
"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
"github.com/stretchr/testify/suite"
"github.com/kgateway-dev/kgateway/test/kubernetes/e2e"
"github.com/kgateway-dev/kgateway/test/kubernetes/e2e/features/example"
"github.com/kgateway-dev/kgateway/test/kubernetes/testutils/gloogateway"
)
// TestInstallationWithInfoLogLevel is the function which executes a series of tests against a given installation
func TestInstallationWithInfoLogLevel(t *testing.T) {
ctx := context.Background()
installNs, nsEnvPredefined := envutils.LookupOrDefault(testutils.InstallNamespace, "info-log-test")
testInstallation := e2e.CreateTestInstallation(
t,
&gloogateway.Context{
InstallNamespace: installNs,
ProfileValuesManifestFile: filepath.Join(fsutils.MustGetThisDir(), "manifests", "example-profile.yaml"),
ValuesManifestFile: filepath.Join(fsutils.MustGetThisDir(), "manifests", "info-example.yaml"),
},
)
testHelper := e2e.MustTestHelper(ctx, testInstallation)
// Set the env to the install namespace if it is not already set
if !nsEnvPredefined {
os.Setenv(testutils.InstallNamespace, installNs)
}
// We register the cleanup function _before_ we actually perform the installation.
// This allows us to uninstall Gloo Gateway, in case the original installation only completed partially
t.Cleanup(func() {
if !nsEnvPredefined {
os.Unsetenv(testutils.InstallNamespace)
}
if t.Failed() {
testInstallation.PreFailHandler(ctx)
}
testInstallation.UninstallGlooGatewayWithTestHelper(ctx, testHelper)
})
testInstallation.InstallGlooGatewayWithTestHelper(ctx, testHelper, 5*time.Minute)
// The name here is important for debuggability
// When tests are logged, they follow the shape TestSuiteName/SubtestName/TestName
// In this case, the output would be:
// TestInstallationWithDebugLogLevel/Example/{test name}
// We prefer to follow CamelCase convention for names of these subtests
t.Run("Example", func(t *testing.T) {
suite.Run(t, example.NewTestingSuite(ctx, testInstallation))
})
}