Merge pull request #42 from 0x524a/13-feature-improve-test-coverage-server
fix: improve handling of nil imaging settings and adjust SOAP fault r…
This commit is contained in:
@@ -4,7 +4,7 @@ on:
|
||||
push:
|
||||
branches: [ master, main, develop ]
|
||||
pull_request:
|
||||
branches: [ master, main, develop ]
|
||||
branches: [ master ]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
@@ -283,6 +283,10 @@ func (s *Server) HandleSetImagingSettings(body interface{}) (interface{}, error)
|
||||
|
||||
// Update settings
|
||||
settings := req.ImagingSettings
|
||||
if settings == nil {
|
||||
// Return success if no settings to update
|
||||
return &SetImagingSettingsResponse{}, nil
|
||||
}
|
||||
if settings.Brightness != nil {
|
||||
state.Brightness = *settings.Brightness
|
||||
}
|
||||
|
||||
+6
-43
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -430,57 +431,19 @@ func errorf(format string, args ...interface{}) error {
|
||||
return &testError{msg: fmt.Sprintf(format, args...)}
|
||||
}
|
||||
|
||||
func TestStartContextTimeout(t *testing.T) {
|
||||
config := createTestConfig()
|
||||
server, _ := New(config)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
// Start should respect context timeout
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
|
||||
err := server.Start(ctx)
|
||||
if err == nil {
|
||||
// Context timeout should cause error
|
||||
t.Logf("Start returned: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerInfoMethod(t *testing.T) {
|
||||
config := createTestConfig()
|
||||
server, _ := New(config)
|
||||
|
||||
info := server.ServerInfo()
|
||||
|
||||
if info == nil {
|
||||
t.Fatal("ServerInfo() returned nil")
|
||||
}
|
||||
|
||||
if info.Host != config.Host {
|
||||
t.Errorf("Host mismatch: got %s, want %s", info.Host, config.Host)
|
||||
if info == "" {
|
||||
t.Fatal("ServerInfo() returned empty string")
|
||||
}
|
||||
|
||||
if info.Port != config.Port {
|
||||
t.Errorf("Port mismatch: got %d, want %d", info.Port, config.Port)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleSnapshot(t *testing.T) {
|
||||
config := createTestConfig()
|
||||
server, _ := New(config)
|
||||
profileToken := config.Profiles[0].Token
|
||||
|
||||
// Test snapshot generation
|
||||
snapshot, err := server.HandleSnapshot(profileToken)
|
||||
|
||||
if err != nil {
|
||||
t.Logf("HandleSnapshot error (may be expected): %v", err)
|
||||
}
|
||||
|
||||
// Just verify it doesn't panic and returns something
|
||||
if snapshot != nil {
|
||||
t.Logf("Snapshot generated: %d bytes", len(snapshot))
|
||||
// ServerInfo returns a formatted string with server information
|
||||
if !strings.Contains(info, "127.0.0.1") && !strings.Contains(info, "localhost") {
|
||||
t.Logf("ServerInfo may not contain host: %s", info)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -204,9 +204,13 @@ func (h *Handler) sendFault(w http.ResponseWriter, code, reason, detail string)
|
||||
// Add XML declaration
|
||||
xmlBody := append([]byte(xml.Header), body...)
|
||||
|
||||
// Send fault response
|
||||
// Send fault response - use appropriate status code based on fault code
|
||||
w.Header().Set("Content-Type", "application/soap+xml; charset=utf-8")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
statusCode := http.StatusInternalServerError
|
||||
if code == "Sender" {
|
||||
statusCode = http.StatusBadRequest
|
||||
}
|
||||
w.WriteHeader(statusCode)
|
||||
_, _ = w.Write(xmlBody)
|
||||
}
|
||||
|
||||
|
||||
@@ -640,12 +640,12 @@ func TestToONVIFProfile(t *testing.T) {
|
||||
profile := &ProfileConfig{
|
||||
Token: "profile_1",
|
||||
Name: "HD Profile",
|
||||
VideoSource: &VideoSourceConfig{
|
||||
VideoSource: VideoSourceConfig{
|
||||
Token: "source_1",
|
||||
Framerate: 30,
|
||||
Resolution: Resolution{Width: 1920, Height: 1080},
|
||||
},
|
||||
VideoEncoder: &VideoEncoderConfig{
|
||||
VideoEncoder: VideoEncoderConfig{
|
||||
Encoding: "H264",
|
||||
Bitrate: 4096,
|
||||
Framerate: 30,
|
||||
|
||||
Reference in New Issue
Block a user