|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed |
| 2 | +// under the Apache License Version 2.0. |
| 3 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 4 | +// Copyright 2026-Present Datadog, Inc. |
| 5 | + |
| 6 | +package parsing |
| 7 | + |
| 8 | +import ( |
| 9 | + "encoding/json" |
| 10 | + "testing" |
| 11 | +) |
| 12 | + |
| 13 | +func TestDetectInvocationSource(t *testing.T) { |
| 14 | + tests := map[string]struct { |
| 15 | + event json.RawMessage |
| 16 | + wantKey invocationSource |
| 17 | + }{ |
| 18 | + "cloudwatch logs": { |
| 19 | + event: json.RawMessage(`{"awslogs":{"data":"dGVzdA=="}}`), |
| 20 | + wantKey: invocationSourceCloudwatchLogs, |
| 21 | + }, |
| 22 | + "empty object": { |
| 23 | + event: json.RawMessage(`{}`), |
| 24 | + wantKey: invocationSourceUnknown, |
| 25 | + }, |
| 26 | + "s3 not yet implemented": { |
| 27 | + event: json.RawMessage(`{"Records":[{"s3":{"bucket":{"name":"my-bucket"},"object":{"key":"my-key"}}}]}`), |
| 28 | + wantKey: invocationSourceUnknown, |
| 29 | + }, |
| 30 | + "not JSON": { |
| 31 | + event: json.RawMessage(`not a json`), |
| 32 | + wantKey: invocationSourceUnknown, |
| 33 | + }, |
| 34 | + "empty input": { |
| 35 | + event: json.RawMessage(``), |
| 36 | + wantKey: invocationSourceUnknown, |
| 37 | + }, |
| 38 | + } |
| 39 | + |
| 40 | + for name, tc := range tests { |
| 41 | + t.Run(name, func(t *testing.T) { |
| 42 | + got := detectInvocationSource(tc.event) |
| 43 | + if got != tc.wantKey { |
| 44 | + t.Errorf("got %d, want %d", got, tc.wantKey) |
| 45 | + } |
| 46 | + }) |
| 47 | + } |
| 48 | +} |
0 commit comments