All checks were successful
CI / changes (push) Successful in 19s
CI / test (push) Successful in 24s
CI / build-ai-gateway (push) Successful in 1m6s
CI / build-ha-gateway (push) Successful in 1m3s
CI / build-discord-bot (push) Successful in 1m4s
CI / build-alexa-bridge (push) Successful in 1m15s
CI / build-tts-gateway (push) Successful in 1m5s
CI / build-tts-sidecar (push) Has been skipped
CI / build-tts-model (push) Has been skipped
- Implemented SetTemperature in ClimateService for setting an absolute target temperature. - Updated ClimateServiceClient and ClimateServiceServer interfaces to include SetTemperature. - Added corresponding handler and tests for SetTemperature in ClimateGRPC. - Modified ClimateApp to handle SetTemperature requests without clamping. - Updated climate.proto to define SetTemperatureRequest message. - Adjusted Dockerfiles to include alexa-bridge dependencies.
131 lines
3.8 KiB
Go
131 lines
3.8 KiB
Go
package haclient
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestOptUint32(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
params map[string]any
|
|
want *uint32
|
|
}{
|
|
{name: "absent key returns nil", params: map[string]any{}, want: nil},
|
|
{name: "valid string parses", params: map[string]any{"k": "80"}, want: ptrUint32(80)},
|
|
{name: "unparsable string returns nil, not error", params: map[string]any{"k": "not-a-number"}, want: nil},
|
|
{name: "float64 accepted", params: map[string]any{"k": float64(42)}, want: ptrUint32(42)},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := optUint32(tt.params, "k")
|
|
if (got == nil) != (tt.want == nil) {
|
|
t.Fatalf("optUint32() = %v, want %v", got, tt.want)
|
|
}
|
|
if got != nil && *got != *tt.want {
|
|
t.Fatalf("optUint32() = %v, want %v", *got, *tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestReqUint32(t *testing.T) {
|
|
t.Run("missing key errors", func(t *testing.T) {
|
|
if _, err := reqUint32(map[string]any{}, "k"); err == nil {
|
|
t.Fatal("reqUint32() error = nil, want error")
|
|
}
|
|
})
|
|
t.Run("unparsable string errors", func(t *testing.T) {
|
|
if _, err := reqUint32(map[string]any{"k": "nope"}, "k"); err == nil {
|
|
t.Fatal("reqUint32() error = nil, want error")
|
|
}
|
|
})
|
|
t.Run("valid string parses", func(t *testing.T) {
|
|
got, err := reqUint32(map[string]any{"k": "255"}, "k")
|
|
if err != nil {
|
|
t.Fatalf("reqUint32() error = %v", err)
|
|
}
|
|
if got != 255 {
|
|
t.Fatalf("reqUint32() = %v, want 255", got)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestReqFloat64(t *testing.T) {
|
|
t.Run("missing key errors", func(t *testing.T) {
|
|
if _, err := reqFloat64(map[string]any{}, "k"); err == nil {
|
|
t.Fatal("reqFloat64() error = nil, want error")
|
|
}
|
|
})
|
|
t.Run("valid string parses", func(t *testing.T) {
|
|
got, err := reqFloat64(map[string]any{"k": "23.5"}, "k")
|
|
if err != nil {
|
|
t.Fatalf("reqFloat64() error = %v", err)
|
|
}
|
|
if got != 23.5 {
|
|
t.Fatalf("reqFloat64() = %v, want 23.5", got)
|
|
}
|
|
})
|
|
t.Run("negative and integral values parse", func(t *testing.T) {
|
|
got, err := reqFloat64(map[string]any{"k": "-5"}, "k")
|
|
if err != nil {
|
|
t.Fatalf("reqFloat64() error = %v", err)
|
|
}
|
|
if got != -5 {
|
|
t.Fatalf("reqFloat64() = %v, want -5", got)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestReqString(t *testing.T) {
|
|
t.Run("missing key errors", func(t *testing.T) {
|
|
if _, err := reqString(map[string]any{}, "k"); err == nil {
|
|
t.Fatal("reqString() error = nil, want error")
|
|
}
|
|
})
|
|
t.Run("non-string value errors", func(t *testing.T) {
|
|
if _, err := reqString(map[string]any{"k": 5}, "k"); err == nil {
|
|
t.Fatal("reqString() error = nil, want error")
|
|
}
|
|
})
|
|
t.Run("valid string", func(t *testing.T) {
|
|
got, err := reqString(map[string]any{"k": "cool"}, "k")
|
|
if err != nil {
|
|
t.Fatalf("reqString() error = %v", err)
|
|
}
|
|
if got != "cool" {
|
|
t.Fatalf("reqString() = %q, want %q", got, "cool")
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestRGBHelpers(t *testing.T) {
|
|
t.Run("optRGB absent returns nil", func(t *testing.T) {
|
|
if got := optRGB(map[string]any{}, "k"); got != nil {
|
|
t.Fatalf("optRGB() = %v, want nil", got)
|
|
}
|
|
})
|
|
t.Run("optRGB malformed returns nil, not error", func(t *testing.T) {
|
|
if got := optRGB(map[string]any{"k": "not-a-map"}, "k"); got != nil {
|
|
t.Fatalf("optRGB() = %v, want nil", got)
|
|
}
|
|
})
|
|
t.Run("optRGB valid", func(t *testing.T) {
|
|
got := optRGB(map[string]any{"k": map[string]any{"r": "1", "g": "2", "b": "3"}}, "k")
|
|
if got == nil || got.R != 1 || got.G != 2 || got.B != 3 {
|
|
t.Fatalf("optRGB() = %v, want (1,2,3)", got)
|
|
}
|
|
})
|
|
t.Run("reqRGB missing key errors", func(t *testing.T) {
|
|
if _, err := reqRGB(map[string]any{}, "k"); err == nil {
|
|
t.Fatal("reqRGB() error = nil, want error")
|
|
}
|
|
})
|
|
t.Run("reqRGB missing component errors", func(t *testing.T) {
|
|
if _, err := reqRGB(map[string]any{"k": map[string]any{"r": "1", "g": "2"}}, "k"); err == nil {
|
|
t.Fatal("reqRGB() error = nil, want error")
|
|
}
|
|
})
|
|
}
|
|
|
|
func ptrUint32(v uint32) *uint32 { return &v }
|