Skip to content

Commit 1388920

Browse files
committed
try stupid AI suggestions
1 parent e93aff5 commit 1388920

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

internal/cmd/integration-tests/tests/loki-enrich/enrich_test.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/json"
88
"fmt"
99
"net/http"
10+
"os"
1011
"testing"
1112
"time"
1213

@@ -48,6 +49,18 @@ func TestEnrichWithMissingLabels(t *testing.T) {
4849
)
4950
}
5051

52+
func getLokiAPIEndpoint() string {
53+
host := os.Getenv("ALLOY_HOST")
54+
port := os.Getenv("ALLOY_PORT")
55+
56+
if host != "" && port != "" {
57+
return fmt.Sprintf("http://%s:%s/loki/api/v1/push", host, port)
58+
}
59+
60+
// Fallback for manual testing
61+
return "http://localhost:1514/loki/api/v1/push"
62+
}
63+
5164
func sendTestLogsForDevice(t *testing.T, hostname string) {
5265
networkLogs := []string{
5366
"%LINK-3-UPDOWN: Interface GigabitEthernet1/0/1, changed state to up",
@@ -77,7 +90,7 @@ func sendTestLogsForDevice(t *testing.T, hostname string) {
7790
body, err := json.Marshal(pushReq)
7891
require.NoError(t, err)
7992

80-
resp, err := http.Post("http://alloy-loki-enrich:1514/loki/api/v1/push", "application/json", bytes.NewReader(body))
93+
resp, err := http.Post(getLokiAPIEndpoint(), "application/json", bytes.NewReader(body))
8194
require.NoError(t, err)
8295
defer resp.Body.Close()
8396
require.Equal(t, http.StatusNoContent, resp.StatusCode)

internal/cmd/integration-tests/utils.go

+28
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,34 @@ func runSingleTest(ctx context.Context, testDir string, port int) {
156156

157157
testCmd := exec.Command("go", "test")
158158
testCmd.Dir = testDir
159+
160+
if dirName == "loki-enrich" {
161+
mappedPort, err := alloyContainer.MappedPort(ctx, "1514/tcp")
162+
if err != nil {
163+
logChan <- TestLog{
164+
TestDir: dirName,
165+
AlloyLog: fmt.Sprintf("failed to get mapped port: %v", err),
166+
}
167+
return
168+
}
169+
170+
host, err := alloyContainer.Host(ctx)
171+
if err != nil {
172+
logChan <- TestLog{
173+
TestDir: dirName,
174+
AlloyLog: fmt.Sprintf("failed to get container host: %v", err),
175+
}
176+
return
177+
}
178+
179+
fmt.Printf("Loki API should be available at http://%s:%s/loki/api/v1/push\n",
180+
host, mappedPort.Port())
181+
182+
testCmd.Env = append(os.Environ(),
183+
fmt.Sprintf("ALLOY_HOST=%s", host),
184+
fmt.Sprintf("ALLOY_PORT=%s", mappedPort.Port()))
185+
}
186+
159187
testOutput, errTest := testCmd.CombinedOutput()
160188

161189
alloyLogs, _ := alloyContainer.Logs(ctx)

0 commit comments

Comments
 (0)