Skip to content

Commit

Permalink
asdfa
Browse files Browse the repository at this point in the history
  • Loading branch information
AsifNawaz-cnic committed Sep 3, 2024
1 parent f6b5a71 commit 8e41279
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
29 changes: 20 additions & 9 deletions response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,23 @@ func (r *Response) IsTmpError() bool {

// IsPending method to check if current operation is returned as pending
func (r *Response) IsPending() bool {
h := r.GetHash()
if val, ok := h["PENDING"]; ok {
if val.(string) == "1" {
return true
cmd := r.GetCommand()

// Check if the COMMAND is AddDomain (case-insensitive)
if command, ok := cmd["COMMAND"]; !ok || !strings.EqualFold(command, "AddDomain") {
return false
}

// Retrieve the STATUS column and check if its data equals REQUESTED (case-insensitive)
status := r.GetColumn("STATUS")
if status != nil {
statusData, err := status.GetDataByIndex(0)
if err != nil {
return false
}
return strings.EqualFold(statusData, "REQUESTED")
}

return false
}

Expand Down Expand Up @@ -199,7 +210,7 @@ func (r *Response) GetColumnIndex(key string, index int) (string, error) {
return d, nil
}
}
return "", errors.New("Column Data Index does not exist")
return "", errors.New("column Data Index does not exist")
}

// GetColumnKeys method to get the list of column names
Expand Down Expand Up @@ -283,14 +294,14 @@ func (r *Response) GetLastRecordIndex() (int, error) {
if err2 == nil {
return idx, nil
}
return 0, errors.New("Could not find last record index")
return 0, errors.New("could not find last record index")
}
}
tlen := r.GetRecordsCount()
if tlen > 0 {
return (tlen - 1), nil
}
return 0, errors.New("Could not find last record index")
return 0, errors.New("could not find last record index")
}

// GetListHash method to get Response as List Hash including useful meta data for tables
Expand Down Expand Up @@ -322,7 +333,7 @@ func (r *Response) GetNextRecord() *record.Record {
func (r *Response) GetNextPageNumber() (int, error) {
cp, err := r.GetCurrentPageNumber()
if err != nil {
return 0, errors.New("Could not find next page number")
return 0, errors.New("could not find next page number")
}
page := cp + 1
pages := r.GetNumberOfPages()
Expand Down Expand Up @@ -385,7 +396,7 @@ func (r *Response) GetPreviousPageNumber() (int, error) {
}
pp := cp - 1
if pp < 1 {
return 0, errors.New("Could not find previous page number")
return 0, errors.New("could not find previous page number")
}
return pp, nil
}
Expand Down
12 changes: 12 additions & 0 deletions response/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func TestMain(m *testing.M) {
"listP0",
"[RESPONSE]\r\nPROPERTY[TOTAL][0]=2701\r\nPROPERTY[FIRST][0]=0\r\nPROPERTY[DOMAIN][0]=0-60motorcycletimes.com\r\nPROPERTY[DOMAIN][1]=0-be-s01-0.com\r\nPROPERTY[COUNT][0]=2\r\nPROPERTY[LAST][0]=1\r\nPROPERTY[LIMIT][0]=2\r\nDESCRIPTION=Command completed successfully\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.023\r\nEOF\r\n",
)
rtm.AddTemplate(
"pendingRegistration",
"[RESPONSE]\r\ncode = 200\r\ndescription = Command completed successfully\r\nruntime = 0.44\r\nqueuetime = 0\r\n\r\nproperty[status][0] = REQUESTED\r\nproperty[updated date][0] = 2023-05-22 12:14:31.0\r\nproperty[zone][0] = se\r\nEOF\r\n",
)
rtm.AddTemplate(
"OK",
rtm.GenerateTemplate("200", "Command completed successfully"),
Expand Down Expand Up @@ -399,3 +403,11 @@ func TestRewindRecordList(t *testing.T) {
t.Error("Expected previous record to be nil.")
}
}

func TestIsPending(t *testing.T) {
plain := rtm.GetTemplate("pendingRegistration")
r := NewResponse(plain, map[string]string{"COMMAND": "AddDomain"})
if got := r.IsPending(); got != true {
t.Errorf("isPending() = %v, want true", got)
}
}

0 comments on commit 8e41279

Please sign in to comment.