Skip to content

Commit 59aa898

Browse files
committed
first part of NFR
1 parent e1f3c02 commit 59aa898

19 files changed

+528
-146
lines changed

tests/conformance/conformance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestConformance(t *testing.T) {
6565
yamlReport, err := yaml.Marshal(report)
6666
g.Expect(err).ToNot(HaveOccurred())
6767

68-
f, err := os.Create(*flags.ReportOutput)
68+
f, err := framework.CreateFile(*flags.ReportOutput)
6969
g.Expect(err).ToNot(HaveOccurred())
7070
defer f.Close()
7171

tests/framework/crossplane.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99
"time"
1010

11+
. "github.com/onsi/ginkgo/v2"
1112
core "k8s.io/api/core/v1"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
"k8s.io/client-go/kubernetes"
@@ -45,7 +46,10 @@ const crossplaneImageName = "nginx-crossplane:latest"
4546
func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) error {
4647
b, err := json.Marshal(conf)
4748
if err != nil {
48-
return fmt.Errorf("error marshaling nginx config: %w", err)
49+
marshalErr := fmt.Errorf("error marshaling nginx config: %w", err)
50+
GinkgoWriter.Printf("%v\n", marshalErr)
51+
52+
return marshalErr
4953
}
5054

5155
for _, config := range conf.Config {
@@ -70,8 +74,10 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
7074
}
7175
}
7276
}
77+
directiveErr := fmt.Errorf("directive %s not found in: nginx config %s", expFieldCfg.Directive, string(b))
78+
GinkgoWriter.Printf("ERROR: %v\n", directiveErr)
7379

74-
return fmt.Errorf("directive %s not found in: nginx config %s", expFieldCfg.Directive, string(b))
80+
return directiveErr
7581
}
7682

7783
func fieldExistsInServer(
@@ -95,6 +101,12 @@ func fieldExistsInUpstream(
95101
expFieldCfg ExpectedNginxField,
96102
directive Directive,
97103
) bool {
104+
GinkgoWriter.Printf(
105+
"Checking upstream %q for directive %q with value %q\n",
106+
directive.Args[0],
107+
expFieldCfg.Directive,
108+
expFieldCfg.Value,
109+
)
98110
if directive.Directive == "upstream" && directive.Args[0] == expFieldCfg.Upstream {
99111
for _, directive := range directive.Block {
100112
if expFieldCfg.fieldFound(directive) {
@@ -123,7 +135,18 @@ func (e ExpectedNginxField) fieldFound(directive *Directive) bool {
123135
valueMatch = strings.Contains(arg, e.Value)
124136
}
125137

126-
return directive.Directive == e.Directive && valueMatch
138+
if directive.Directive == e.Directive && valueMatch {
139+
GinkgoWriter.Printf(
140+
"Found field %q with value %q in field %q with value %q\n",
141+
e.Directive,
142+
e.Value,
143+
directive.Directive,
144+
arg,
145+
)
146+
return true
147+
}
148+
149+
return false
127150
}
128151

129152
func fieldExistsInLocation(locationDirective *Directive, expFieldCfg ExpectedNginxField) bool {
@@ -201,7 +224,10 @@ func injectCrossplaneContainer(
201224

202225
podClient := k8sClient.CoreV1().Pods(namespace)
203226
if _, err := podClient.UpdateEphemeralContainers(ctx, ngfPodName, pod, metav1.UpdateOptions{}); err != nil {
204-
return fmt.Errorf("error adding ephemeral container: %w", err)
227+
containerErr := fmt.Errorf("error adding ephemeral container: %w", err)
228+
GinkgoWriter.Printf("%v\n", containerErr)
229+
230+
return containerErr
205231
}
206232

207233
return nil
@@ -231,7 +257,10 @@ func createCrossplaneExecutor(
231257

232258
exec, err := remotecommand.NewSPDYExecutor(k8sConfig, http.MethodPost, req.URL())
233259
if err != nil {
234-
return nil, fmt.Errorf("error creating executor: %w", err)
260+
executorErr := fmt.Errorf("error creating executor: %w", err)
261+
GinkgoWriter.Printf("%v\n", executorErr)
262+
263+
return nil, executorErr
235264
}
236265

237266
return exec, nil

tests/framework/info.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111

1212
// GetLogs returns the logs for all containers in all pods for a release.
1313
func GetLogs(rm ResourceManager, namespace string, releaseName string) string {
14+
GinkgoWriter.Printf(
15+
"Getting logs for all containers in all pods for release %q in namespace %q\n",
16+
releaseName,
17+
namespace,
18+
)
1419
var returnLogs string
1520
pods, err := rm.GetPods(namespace, client.MatchingLabels{
1621
"app.kubernetes.io/instance": releaseName,
@@ -26,6 +31,13 @@ func GetLogs(rm ResourceManager, namespace string, releaseName string) string {
2631
Container: container.Name,
2732
})
2833
if err != nil {
34+
GinkgoWriter.Printf(
35+
"ERROR occurred during getting logs for container %q in pod %q in namespace %q: %v\n",
36+
container.Name,
37+
pod.Name,
38+
pod.Namespace,
39+
err,
40+
)
2941
returnLogs += fmt.Sprintf(" failed to get logs: %v\n", err)
3042
continue
3143
}
@@ -40,6 +52,8 @@ func GetEvents(rm ResourceManager, namespace string) string {
4052
var returnEvents string
4153
events, err := rm.GetEvents(namespace)
4254
if err != nil {
55+
GinkgoWriter.Printf("ERROR occurred during getting events in namespace %q: %v\n", namespace, err)
56+
4357
return fmt.Sprintf("failed to get events: %v", err)
4458
}
4559

@@ -60,6 +74,7 @@ func GetEvents(rm ResourceManager, namespace string) string {
6074

6175
// GetBuildInfo returns the build information.
6276
func GetBuildInfo() (commitHash string, commitTime string, dirtyBuild string) {
77+
GinkgoWriter.Printf("Getting build info\n")
6378
commitHash = "unknown"
6479
commitTime = "unknown"
6580
dirtyBuild = "unknown"
@@ -86,6 +101,7 @@ func GetBuildInfo() (commitHash string, commitTime string, dirtyBuild string) {
86101
// AddNginxLogsAndEventsToReport adds nginx logs and events from the namespace to the report if the spec failed.
87102
func AddNginxLogsAndEventsToReport(rm ResourceManager, namespace string) {
88103
if CurrentSpecReport().Failed() {
104+
GinkgoWriter.Printf("Current spec failed. Adding Nginx logs and events to report for namespace %q\n", namespace)
89105
var returnLogs string
90106

91107
nginxPodNames, _ := GetReadyNginxPodNames(rm.K8sClient, namespace, rm.TimeoutConfig.GetStatusTimeout)

tests/framework/load.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"time"
99

10+
. "github.com/onsi/ginkgo/v2"
1011
vegeta "github.com/tsenart/vegeta/v12/lib"
1112
)
1213

@@ -49,6 +50,7 @@ type Metrics struct {
4950
// RunLoadTest uses Vegeta to send traffic to the provided Targets at the given rate for the given duration and writes
5051
// the results to the provided file.
5152
func RunLoadTest(cfg LoadTestConfig) (vegeta.Results, Metrics) {
53+
GinkgoWriter.Printf("Running load test: %s\n", cfg.Description)
5254
vegTargets := convertTargetToVegetaTarget(cfg.Targets)
5355
targeter := vegeta.NewStaticTargeter(vegTargets...)
5456

@@ -61,7 +63,12 @@ func RunLoadTest(cfg LoadTestConfig) (vegeta.Results, Metrics) {
6163
Timeout: vegeta.DefaultTimeout,
6264
Transport: &http.Transport{
6365
DialContext: func(ctx context.Context, network, _ string) (net.Conn, error) {
64-
return dialer.DialContext(ctx, network, cfg.Proxy)
66+
conn, err := dialer.DialContext(ctx, network, cfg.Proxy)
67+
if err != nil {
68+
GinkgoWriter.Printf("ERROR occurred during dialing %q in %q network, error: %s\n", cfg.Proxy, network, err)
69+
}
70+
71+
return conn, err
6572
},
6673
TLSClientConfig: &tls.Config{
6774
InsecureSkipVerify: true, //nolint:gosec // self-signed cert for testing

0 commit comments

Comments
 (0)