53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package http
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"quyun/v2/providers/storage"
|
|
)
|
|
|
|
func TestNewReadyCheck(t *testing.T) {
|
|
t.Run("returns error when database ping fails", func(t *testing.T) {
|
|
checker := newReadyCheck(func(context.Context) error {
|
|
return errors.New("db down")
|
|
}, nil)
|
|
|
|
err := checker(context.Background())
|
|
if err == nil {
|
|
t.Fatalf("expected readiness error when db ping fails")
|
|
}
|
|
})
|
|
|
|
t.Run("returns error when s3 storage config is incomplete and check on boot enabled", func(t *testing.T) {
|
|
checker := newReadyCheck(nil, &storage.Storage{Config: &storage.Config{
|
|
Type: "s3",
|
|
CheckOnBoot: true,
|
|
Endpoint: "",
|
|
Bucket: "",
|
|
}})
|
|
|
|
err := checker(context.Background())
|
|
if err == nil {
|
|
t.Fatalf("expected readiness error when storage config is incomplete")
|
|
}
|
|
})
|
|
|
|
t.Run("returns nil when dependencies are ready", func(t *testing.T) {
|
|
checker := newReadyCheck(func(context.Context) error {
|
|
return nil
|
|
}, &storage.Storage{Config: &storage.Config{
|
|
Type: "s3",
|
|
CheckOnBoot: true,
|
|
Endpoint: "http://127.0.0.1:9000",
|
|
Bucket: "bucket",
|
|
}})
|
|
|
|
err := checker(context.Background())
|
|
if err != nil {
|
|
t.Fatalf("expected nil error, got %v", err)
|
|
}
|
|
})
|
|
}
|