Skip to content

Commit

Permalink
removed unused code
Browse files Browse the repository at this point in the history
Signed-off-by: Disaiah Bennett <[email protected]>
  • Loading branch information
dislbenn committed Mar 19, 2024
1 parent 15ec7e2 commit 85dd03a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 22 deletions.
10 changes: 0 additions & 10 deletions pkg/ocm/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,3 @@ func prepareRequest(request Request, endpointURL string) (*http.Request, error)
getRequest = getRequest.WithContext(context.Background())
return getRequest, nil
}

// GetHTTPClient returns the HTTP client
func GetHTTPClient() HTTPRequester {
return httpClient
}

// GetProvider returns the resource loader
func GetProvider() ResourceLoader {
return provider
}
89 changes: 86 additions & 3 deletions pkg/ocm/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"io"
"net/http"
"os"
"strings"
"testing"

v1 "github.com/stolostron/discovery/api/v1"
"github.com/stolostron/discovery/pkg/ocm/cluster"
sub "github.com/stolostron/discovery/pkg/ocm/subscription"
"github.com/stretchr/testify/assert"
Expand All @@ -29,19 +31,16 @@ func TestProviderGetResourcesNoError(t *testing.T) {
name string
endpointURL string
testFilePath string
// want bool
}{
{
name: "Should get cluster resources with no error",
endpointURL: cluster.GetClusterURL(),
testFilePath: "../cluster/testdata/clusters_mgmt_mock.json",
// want: true,
},
{
name: "Should get subscription resources with no error",
endpointURL: sub.GetSubscriptionURL(),
testFilePath: "../subscription/testdata/accounts_mgmt_mock.json",
// want: false,
},
}

Expand All @@ -67,3 +66,87 @@ func TestProviderGetResourcesNoError(t *testing.T) {
})
}
}

func TestParseResponse(t *testing.T) {
tests := []struct {
name string
response *http.Response
want bool
}{
{
name: "Should parse response with no error",
response: &http.Response{
Body: io.NopCloser(strings.NewReader(`{"kind":"example","page":1,"size":10,"total":100,"items":[{"id":1,"name":"item1"},{"id":2,"name":"item2"}]}`)),
StatusCode: 200,
},
want: true,
},
{
name: "Should parse response with error",
response: &http.Response{
Body: io.NopCloser(strings.NewReader(`{"reason":"example reason"}`)),
StatusCode: 400,
},
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseResponse(tt.response)

if tt.response.StatusCode > 299 {
if ok := got == nil; !ok {
t.Errorf("parseResponse(response) got (%v, %v), want %v", got, err, tt.want)
}

} else {
if ok := err == nil; !ok {
t.Errorf("parseResponse(response) got (%v, %v), want %v", got, err, tt.want)
}
}
})
}
}

func TestPrepareRequest(t *testing.T) {
tests := []struct {
name string
endpointURL string
request Request
want bool
}{
{
name: "Should prepare request for getting cluster resources",
endpointURL: cluster.GetClusterURL(),
request: Request{
BaseURL: ocmBaseURL,
Token: "test-token",
Filter: v1.Filter{
LastActive: 2,
},
},
want: true,
},
{
name: "Should prepare request for getting subscription resources",
endpointURL: sub.GetSubscriptionURL(),
request: Request{
BaseURL: ocmBaseURL,
Token: "test-token",
Filter: v1.Filter{
LastActive: 2,
},
},
want: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got, err := prepareRequest(tt.request, tt.endpointURL); err != nil {
t.Errorf("prepareRequest(request, endpointURL), got %v, want %v", got, tt.want)
}
})
}
}
9 changes: 0 additions & 9 deletions pkg/ocm/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ type Request struct {
// Add any other common fields here.
}

// NewError creates a new Error object with the provided code and reason.
func NewError(code, reason string) *Error {
// Implement NewError function here
return &Error{
Code: code,
Reason: reason,
}
}

// HTTPRequester represents an interface for making HTTP requests
type HTTPRequester interface {
Get(*http.Request) (*http.Response, error)
Expand Down

0 comments on commit 85dd03a

Please sign in to comment.