Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kavir1698 committed Apr 24, 2024
1 parent bcf014f commit f41fc75
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions datasetIngestor/testForExistingSourceFolder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"io"
"bytes"
)

func TestTestForExistingSourceFolder(t *testing.T) {
Expand Down Expand Up @@ -52,3 +54,34 @@ func TestTestForExistingSourceFolder(t *testing.T) {
TestForExistingSourceFolder(folders, client, APIServer, accessToken, &allowExistingSourceFolder)
})
}

func TestProcessResponse(t *testing.T) {
// Test with valid JSON
validJSON := `[{"pid": "123", "sourceFolder": "folder", "size": 100}]`
resp := &http.Response{
Body: io.NopCloser(bytes.NewBufferString(validJSON)),
}
result := processResponse(resp)
if len(result) != 1 || result[0].Pid != "123" || result[0].SourceFolder != "folder" || result[0].Size != 100 {
t.Errorf("Unexpected result: %v", result)
}

// Test with invalid JSON
invalidJSON := `{"pid": "123", "sourceFolder": "folder", "size": 100}`
resp = &http.Response{
Body: io.NopCloser(bytes.NewBufferString(invalidJSON)),
}
result = processResponse(resp)
if len(result) != 0 {
t.Errorf("Expected empty QueryResult, got '%v'", result)
}

// Test with empty body
resp = &http.Response{
Body: io.NopCloser(bytes.NewBufferString("")),
}
result = processResponse(resp)
if len(result) != 0 {
t.Errorf("Expected empty QueryResult, got '%v'", result)
}
}

0 comments on commit f41fc75

Please sign in to comment.