feat: downloader
This commit is contained in:
parent
b9c1a98895
commit
42e7924be9
37 changed files with 2422 additions and 94 deletions
62
internal/pkg/grib/grib_test.go
Normal file
62
internal/pkg/grib/grib_test.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package grib
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestServiceCreation(t *testing.T) {
|
||||
cfg := ServiceConfig{
|
||||
Dir: "/tmp/grib_test",
|
||||
TTL: 24 * time.Hour,
|
||||
CacheTTL: 1 * time.Hour,
|
||||
Redis: &MockRedis{},
|
||||
Parallel: 2,
|
||||
}
|
||||
|
||||
service, err := New(cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create service: %v", err)
|
||||
}
|
||||
defer service.Close()
|
||||
|
||||
if service == nil {
|
||||
t.Fatal("Service is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNearestRun(t *testing.T) {
|
||||
now := time.Date(2024, 1, 15, 14, 30, 0, 0, time.UTC)
|
||||
expected := time.Date(2024, 1, 15, 12, 0, 0, 0, time.UTC)
|
||||
|
||||
result := nearestRun(now)
|
||||
if !result.Equal(expected) {
|
||||
t.Errorf("Expected %v, got %v", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPressureFromAlt(t *testing.T) {
|
||||
alt := 10000.0 // 10km
|
||||
pressure := pressureFromAlt(alt)
|
||||
|
||||
// At 10km, pressure should be around 264 hPa
|
||||
if pressure < 200 || pressure > 300 {
|
||||
t.Errorf("Unexpected pressure at 10km: %f hPa", pressure)
|
||||
}
|
||||
}
|
||||
|
||||
// MockRedis for testing
|
||||
type MockRedis struct{}
|
||||
|
||||
func (m *MockRedis) Lock(ctx context.Context, key string, ttl time.Duration) (func(context.Context), error) {
|
||||
return func(ctx context.Context) {}, nil
|
||||
}
|
||||
|
||||
func (m *MockRedis) Set(key string, value []byte, ttl time.Duration) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockRedis) Get(key string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue