Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apiv2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ int-test-telemetry: ## Runs telemetry integration tests from test/client
@if [ -z $(PROJECT_ID) ]; then echo "Error: PROJECT_ID is not defined" >&2; false; fi
$(GOCMD_TESTCLIENTJWT_TOKEN) -run TestTelemetry

int-test-oup: ## Runs OS Update Policy integration tests from test/client
@echo "!!!!! Follow instruction in test/client/README.md !!!!!"
@if [ -z $(JWT_TOKEN) ]; then echo "Error: JWT_TOKEN is not defined" >&2; false; fi
@if [ -z $(PROJECT_ID) ]; then echo "Error: PROJECT_ID is not defined" >&2; false; fi
$(GOCMD_TESTCLIENTJWT_TOKEN) -run TestOSUpdatePolicy

int-test-our: ## Runs OS Update Run integration tests from test/client
@echo "!!!!! Follow instruction in test/client/README.md !!!!!"
@if [ -z $(JWT_TOKEN) ]; then echo "Error: JWT_TOKEN is not defined" >&2; false; fi
@if [ -z $(PROJECT_ID) ]; then echo "Error: PROJECT_ID is not defined" >&2; false; fi
$(GOCMD_TESTCLIENTJWT_TOKEN) -run TestOSUpdateRun

buf-update: common-buf-update ## Update buf modules

buf-gen-api: $(VENV_NAME) ## Compile protoc api files into code
Expand Down
2 changes: 1 addition & 1 deletion apiv2/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
2.5.2-dev
35 changes: 35 additions & 0 deletions apiv2/test/client/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,38 @@ func GetHostRequestWithRandomUUID() api.HostResource {
Uuid: &uuidHost,
}
}

func CreateOsUpdatePolicy(
ctx context.Context,
tb testing.TB,
apiClient *api.ClientWithResponses,
reqPolicy api.OSUpdatePolicy,
) *api.OSUpdatePolicyCreateOSUpdatePolicyResponse {
tb.Helper()

policyCreated, err := apiClient.OSUpdatePolicyCreateOSUpdatePolicyWithResponse(
ctx,
reqPolicy,
AddJWTtoTheHeader, AddProjectIDtoTheHeader,
)
require.NoError(tb, err)
assert.Equal(tb, http.StatusOK, policyCreated.StatusCode())

tb.Cleanup(func() {
DeleteOSUpdatePolicy(context.Background(), tb, apiClient, *policyCreated.JSON200.ResourceId)
})

return policyCreated
}

func DeleteOSUpdatePolicy(ctx context.Context, tb testing.TB, apiClient *api.ClientWithResponses, policyID string) {
tb.Helper()

policyDel, err := apiClient.OSUpdatePolicyDeleteOSUpdatePolicyWithResponse(
ctx,
policyID,
AddJWTtoTheHeader, AddProjectIDtoTheHeader,
)
require.NoError(tb, err)
assert.Equal(tb, http.StatusOK, policyDel.StatusCode())
}
59 changes: 59 additions & 0 deletions apiv2/test/client/osupdatepolicy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: (C) 2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

package client

import (
"context"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/open-edge-platform/infra-core/apiv2/v2/pkg/api/v2"
"github.com/open-edge-platform/infra-core/apiv2/v2/test/utils"
)

func TestOSUpdatePolicy_CreateGetListDelete(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

apiClient, err := GetAPIClient()
require.NoError(t, err)

// Create OSUpdatePolicy
policy1 := CreateOsUpdatePolicy(ctx, t, apiClient, utils.OsUpdatePolicyRequest1)
policy2 := CreateOsUpdatePolicy(ctx, t, apiClient, utils.OsUpdatePolicyRequest1)

// Get OSUpdatePolicy
getResp1, err := apiClient.OSUpdatePolicyGetOSUpdatePolicyWithResponse(
ctx, *policy1.JSON200.ResourceId, AddJWTtoTheHeader, AddProjectIDtoTheHeader)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, getResp1.StatusCode())
assert.Equal(t, utils.OsUpdatePolicyName1, getResp1.JSON200.Name)

getResp2, err := apiClient.OSUpdatePolicyGetOSUpdatePolicyWithResponse(
ctx, *policy2.JSON200.ResourceId, AddJWTtoTheHeader, AddProjectIDtoTheHeader)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, getResp2.StatusCode())
assert.Equal(t, utils.OsUpdatePolicyName2, getResp2.JSON200.Name)

// List OSUpdatePolicies
listResp, err := apiClient.OSUpdatePolicyListOSUpdatePolicyWithResponse(
ctx, &api.OSUpdatePolicyListOSUpdatePolicyParams{}, AddJWTtoTheHeader, AddProjectIDtoTheHeader)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, listResp.StatusCode())
found1 := false
found2 := false
for _, p := range listResp.JSON200.OsUpdatePolicies {
if p.Name == policy1.JSON200.Name {
found1 = true
}
if p.Name == policy2.JSON200.Name {
found2 = true
}
}
assert.True(t, found1, "First created policy should be in list")
assert.True(t, found2, "Second created policy should be in list")
}
41 changes: 41 additions & 0 deletions apiv2/test/client/osupdaterun_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: (C) 2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

package client

import (
"context"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/open-edge-platform/infra-core/apiv2/v2/pkg/api/v2"
)

func TestOSUpdateRun_GetListNotFound(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

apiClient, err := GetAPIClient()
require.NoError(t, err)

osUpdateRunNonexistResourceID := "osupdaterun-111111"

// Get OSUpdateRun
getResp, err := apiClient.OSUpdateRunGetOSUpdateRunWithResponse(
ctx, osUpdateRunNonexistResourceID, AddJWTtoTheHeader, AddProjectIDtoTheHeader)
require.NoError(t, err)
assert.Equal(t, http.StatusNotFound, getResp.StatusCode())

// List OSUpdateRuns should not be found
listResp, err := apiClient.OSUpdateRunListOSUpdateRunWithResponse(
ctx, &api.OSUpdateRunListOSUpdateRunParams{}, AddJWTtoTheHeader, AddProjectIDtoTheHeader)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, listResp.StatusCode())

// The returned list is empty
assert.NotNil(t, listResp.JSON200)
assert.Empty(t, listResp.JSON200.OsUpdateRuns, "Expected OSUpdateRuns list to be empty")
}
18 changes: 18 additions & 0 deletions apiv2/test/utils/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ var (
ProviderWrongID = "proider-12345678"
providerBadAPICredentials = []string{"%as", "v1/lxca/password"}

OsUpdatePolicyName1 = "test-policy"
OsUpdatePolicyName2 = "test-policy"
osUpdatePolicyDescription1 = "Test OS Update Policy"
osUpdatePolicyDescription2 = "Test OS Update Policy 2"
updatePolicyLatest = api.UPDATEPOLICYLATEST

MetadataR1 = []api.MetadataItem{
{
Key: "examplekey",
Expand Down Expand Up @@ -789,4 +795,16 @@ var (
Timestamps: nil,
Username: "",
}

OsUpdatePolicyRequest1 = api.OSUpdatePolicy{
Name: OsUpdatePolicyName1,
Description: &osUpdatePolicyDescription1,
UpdatePolicy: &updatePolicyLatest,
}

OsUpdatePolicyRequest2 = api.OSUpdatePolicy{
Name: OsUpdatePolicyName2,
Description: &osUpdatePolicyDescription2,
UpdatePolicy: &updatePolicyLatest,
}
)