refactor: introduce constants for improved maintainability in tests and server configurations
- Added constants for test endpoints, usernames, and XML headers in client_test.go and device_certificates_test.go to enhance readability and reduce hardcoded values. - Updated various test cases to utilize these constants, ensuring consistency across tests. - Refactored imaging settings and server configurations to use defined constants for default values, improving clarity and maintainability in server/device.go and server/imaging.go. - Enhanced comments throughout the code to clarify functionality and adhere to best practices.
This commit is contained in:
@@ -10,6 +10,11 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
testCertID = "cert-001"
|
||||
testXMLHeader = `<?xml version="1.0" encoding="UTF-8"?>`
|
||||
)
|
||||
|
||||
func newMockDeviceCertificatesServer() *httptest.Server {
|
||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/soap+xml")
|
||||
@@ -167,7 +172,7 @@ func newMockDeviceCertificatesServer() *httptest.Server {
|
||||
</SOAP-ENV:Envelope>`
|
||||
|
||||
default:
|
||||
response = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
response = testXMLHeader + `
|
||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
|
||||
<SOAP-ENV:Body>
|
||||
<SOAP-ENV:Fault>
|
||||
@@ -201,8 +206,8 @@ func TestGetCertificates(t *testing.T) {
|
||||
t.Error("Expected at least one certificate")
|
||||
}
|
||||
|
||||
if certs[0].CertificateID != "cert-001" {
|
||||
t.Errorf("Expected certificate ID 'cert-001', got '%s'", certs[0].CertificateID)
|
||||
if certs[0].CertificateID != testCertID {
|
||||
t.Errorf("Expected certificate ID '%s', got '%s'", testCertID, certs[0].CertificateID)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user