Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/logs_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ func runLogsSearch(cmd *cobra.Command, args []string) error {
api := datadogV1.NewLogsApi(client.V1())

limit := int32(logsLimit)
fromTimeObj := time.Unix(fromTime, 0)
toTimeObj := time.Unix(toTime, 0)
fromTimeObj := time.UnixMilli(fromTime)
toTimeObj := time.UnixMilli(toTime)

body := datadogV1.LogsListRequest{
Query: &logsQuery,
Expand Down
55 changes: 55 additions & 0 deletions cmd/logs_simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,61 @@ func TestLogsCmd(t *testing.T) {
}
}

func TestParseTimeString(t *testing.T) {
tests := []struct {
name string
input string
wantErr bool
check func(int64) bool
}{
{
name: "relative time - 1 hour",
input: "1h",
check: func(ts int64) bool {
// Should be roughly 1 hour ago in milliseconds
// Timestamps should be 13 digits for milliseconds since epoch
return ts > 1000000000000 && ts < 9999999999999
},
},
{
name: "relative time - 7 days",
input: "7d",
check: func(ts int64) bool {
// Should be roughly 7 days ago in milliseconds
return ts > 1000000000000 && ts < 9999999999999
},
},
{
name: "now",
input: "now",
check: func(ts int64) bool {
// Should be current time in milliseconds (13 digits)
return ts > 1000000000000 && ts < 9999999999999
},
},
{
name: "invalid format",
input: "invalid",
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseTimeString(tt.input)

if (err != nil) != tt.wantErr {
t.Errorf("parseTimeString() error = %v, wantErr %v", err, tt.wantErr)
return
}

if !tt.wantErr && tt.check != nil && !tt.check(got) {
t.Errorf("parseTimeString() = %d, validation failed", got)
}
})
}
}

// Helper function to setup logs test client
func setupLogsTestClient(t *testing.T) func() {
t.Helper()
Expand Down
1 change: 0 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func New(cfg *config.Config) (*Client, error) {
// Enable all unstable operations to suppress warnings
// These are beta/preview features that we want to use
unstableOps := []string{
"v2.QueryTimeseriesData",
"v2.ListIncidents",
"v2.GetIncident",
"v2.CreateIncident",
Expand Down