-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inventory-client: remove staleness param from inventory query
With staleness=fresh param, some hosts may be not found, removing this param has been tested to found this hosts again. FIXES: https://issues.redhat.com/browse/THEEDGE-3763
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package inventory_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" // nolint: revive | ||
. "github.com/onsi/gomega" // nolint: revive | ||
) | ||
|
||
func TestInventoryClient(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Inventory Client Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package inventory_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
|
||
"github.com/redhatinsights/edge-api/config" | ||
"github.com/redhatinsights/edge-api/pkg/clients/inventory" | ||
|
||
"github.com/bxcodec/faker/v3" | ||
. "github.com/onsi/ginkgo" // nolint: revive | ||
. "github.com/onsi/gomega" // nolint: revive | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var _ = Describe("Inventory Client Tests", func() { | ||
var client inventory.ClientInterface | ||
var originalInventoryURL string | ||
conf := config.Get() | ||
BeforeEach(func() { | ||
client = inventory.InitClient(context.Background(), log.NewEntry(log.StandardLogger())) | ||
originalInventoryURL = conf.InventoryConfig.URL | ||
}) | ||
AfterEach(func() { | ||
conf.ImageBuilderConfig.URL = originalInventoryURL | ||
}) | ||
It("should init client", func() { | ||
Expect(client).ToNot(BeNil()) | ||
}) | ||
Context("ReturnDevicesByID", func() { | ||
|
||
It("should return inventory hosts by id successfully", func() { | ||
deviceUUID := faker.UUIDHyphenated() | ||
expectedParams := map[string]string{ | ||
"filter[system_profile][host_type]": "edge", | ||
"fields[system_profile]": "host_type,operating_system,greenboot_status," + | ||
"greenboot_fallback_detected,rpm_ostree_deployments,rhc_client_id,rhc_config_state", | ||
"hostname_or_id": deviceUUID, | ||
} | ||
|
||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
w.Header().Set("Content-Type", "application/json") | ||
urlQueryValues := r.URL.Query() | ||
for key, value := range expectedParams { | ||
Expect(value).To(Equal(urlQueryValues.Get(key))) | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
response := inventory.Response{Total: 1, Count: 1, Result: []inventory.Device{{ID: deviceUUID}}} | ||
err := json.NewEncoder(w).Encode(&response) | ||
Expect(err).ToNot(HaveOccurred()) | ||
})) | ||
defer ts.Close() | ||
config.Get().InventoryConfig.URL = ts.URL | ||
result, err := client.ReturnDevicesByID(deviceUUID) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(result.Total).To(Equal(1)) | ||
Expect(result.Count).To(Equal(1)) | ||
Expect(len(result.Result)).To(Equal(1)) | ||
Expect(result.Result[0].ID).To(Equal(deviceUUID)) | ||
}) | ||
}) | ||
}) |