Skip to content

Commit

Permalink
Change GetStoreStatus to use XML encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiante committed Feb 2, 2024
1 parent bef6848 commit 0c165a4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 43 deletions.
61 changes: 18 additions & 43 deletions r_get_store_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,35 @@ package easclient

import (
"context"
"time"
"encoding/xml"
)

type StoreStatus struct {
XMLName xml.Name `xml:"status"`
Registry struct {
AllRecords int `json:"allRecords"`
IndexedRecords int `json:"indexedRecords"`
AllAttachments int `json:"allAttachments"`
IndexedAttachments int `json:"indexedAttachments"`
} `json:"registry"`
Records struct {
All int `xml:"all"`
Indexed int `xml:"indexed"`
} `xml:"records"`
Attachments struct {
All int `xml:"all"`
Indexed int `xml:"indexed"`
} `xml:"attachments"`
} `xml:"registry"`
Index struct {
Documents int `json:"documents"`
IsCurrent bool `json:"isCurrent"`
HasDeletions bool `json:"hasDeletions"`
Records int `json:"records"`
Attachments int `json:"attachments"`
} `json:"index"`
Capacity struct {
Maximum int64 `json:"maximum"`
Utilized float64 `json:"utilized"`
GrowthRate float64 `json:"growthRate"`
ExpectedEnd time.Time `json:"expectedEnd"`
Lifetime int `json:"lifetime"`
} `json:"capacity"`
Periods []struct {
Start string `json:"start"`
End string `json:"end"`
Registry struct {
AllRecords int `json:"allRecords"`
IndexedRecords int `json:"indexedRecords"`
AllAttachments int `json:"allAttachments"`
IndexedAttachments int `json:"indexedAttachments"`
} `json:"registry"`
Index struct {
Records int `json:"records"`
Attachments int `json:"attachments"`
} `json:"index"`
Capacity struct {
Utilized float64 `json:"utilized"`
} `json:"capacity"`
} `json:"periods"`
Documents int `xml:"documents"`
IsCurrent bool `xml:"isCurrent"`
HasDeletions bool `xml:"hasDeletions"`
} `xml:"index"`
}

func (c *StoreClient) GetStoreStatus(ctx context.Context) (*StoreStatus, error) {
req, err := c.newRequestJSON(ctx)
req, err := c.newRequestXML(ctx)
if err != nil {
return nil, err
}

type Res struct {
Status *StoreStatus `json:"status"`
}

var result Res
var result StoreStatus

req.SetResult(&result)
res, err := req.Get("/status")
Expand All @@ -67,5 +42,5 @@ func (c *StoreClient) GetStoreStatus(ctx context.Context) (*StoreStatus, error)
return nil, err
}

return result.Status, nil
return &result, nil
}
31 changes: 31 additions & 0 deletions r_get_store_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package easclient_test

import (
"context"
"encoding/xml"
"testing"

"github.com/DEXPRO-Solutions-GmbH/easclient"
Expand All @@ -22,3 +23,33 @@ func TestStoreClient_GetStoreStatus(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, status)
}

func Test_UnmarshalStoreStatus(t *testing.T) {
respBody := `<?xml version="1.0" encoding="UTF-8"?>
<status xmlns="http://namespace.otris.de/2010/09/archive" xmlns:xlink="http://www.w3.org/1999/xlink">
<registry>
<records>
<all>34</all>
<indexed>34</indexed>
</records>
<attachments>
<all>4</all>
<indexed>4</indexed>
</attachments>
</registry>
<index>
<documents>38</documents>
<isCurrent>true</isCurrent>
<hasDeletions>false</hasDeletions>
</index>
</status>`

var resp easclient.StoreStatus

require.NoError(t, xml.Unmarshal([]byte(respBody), &resp))
require.Equal(t, 34, resp.Registry.Records.All)
require.Equal(t, 34, resp.Registry.Records.Indexed)
require.Equal(t, 38, resp.Index.Documents)
require.Equal(t, true, resp.Index.IsCurrent)
require.Equal(t, false, resp.Index.HasDeletions)
}

0 comments on commit 0c165a4

Please sign in to comment.