Skip to content

Commit

Permalink
gcp: adding e2e tests
Browse files Browse the repository at this point in the history
For now, those are the basic tests we are adding.

Signed-off-by: Beraldo Leal <bleal@redhat.com>
  • Loading branch information
beraldoleal committed Feb 13, 2025
1 parent 5c100c5 commit 9c13521
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/cloud-api-adaptor/test/e2e/gcp_common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// (C) Copyright Confidential Containers Contributors
// SPDX-License-Identifier: Apache-2.0

package e2e

import (
"context"
"fmt"
"testing"
"time"

compute "cloud.google.com/go/compute/apiv1"
pv "github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/provisioner/gcp"
computepb "cloud.google.com/go/compute/apiv1/computepb"
log "github.com/sirupsen/logrus"
)

// GCPCloudAssert implements the CloudAssert interface for gcp.
type GCPCloudAssert struct{}


func NewGCPAssert() GCPCloudAssert {
return GCPCloudAssert{}
}


func (c GCPCloudAssert) DefaultTimeout() time.Duration {
return 2 * time.Minute
}


func gcpFindVM(prefixName string) (*computepb.Instance, error) {
ctx := context.Background()
instancesClient, err := compute.NewInstancesRESTClient(ctx)
if err != nil {
return nil, fmt.Errorf("NewInstancesRESTClient: %w", err)
}
defer instancesClient.Close()


filter := fmt.Sprintf("name eq ^%s.*", prefixName)
req := &computepb.ListInstancesRequest{
Project: pv.GCPProps.GkeCluster.ProjectID,
Zone: pv.GCPProps.GkeCluster.Zone,
Filter: &filter,
}

it := instancesClient.List(ctx, req)
instance, err := it.Next()
if err != nil {
return nil, err
}

log.Infof("Instance found %s %s", instance.GetName(), instance.GetMachineType())
return instance, nil
}


func (c GCPCloudAssert) HasPodVM(t *testing.T, id string) {
pod_vm_prefix := "podvm-" + id
vm, err := gcpFindVM(pod_vm_prefix)
if vm != nil {
t.Logf("Vitural machine %s found.", id)
} else {
t.Logf("Virtual machine %s not found: %s", id, err)
t.Error("PodVM was not created")
}
}


func (c GCPCloudAssert) GetInstanceType(t *testing.T, podName string) (string, error) {
// Get Instance Type of PodVM

prefixName := "podvm-" + podName
vm, err := gcpFindVM(prefixName)
if err != nil {
t.Logf("Virtual machine %s not found: %s", podName, err)
return "", err
}

return vm.GetMachineType(), nil
}
31 changes: 31 additions & 0 deletions src/cloud-api-adaptor/test/e2e/gcp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build gcp

// (C) Copyright Confidential Containers Contributors
// SPDX-License-Identifier: Apache-2.0

package e2e

import (
_ "github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/provisioner/gcp"
"testing"
)

func TestDeletePodGCP(t *testing.T) {
assert := GCPCloudAssert{}
DoTestDeleteSimplePod(t, testEnv, assert)
}

func TestCreateSimplePodGCP(t *testing.T) {
assert := GCPCloudAssert{}
DoTestCreateSimplePod(t, testEnv, assert)
}

func TestCreatePodWithConfigMapGCP(t *testing.T) {
assert := GCPCloudAssert{}
DoTestCreatePodWithConfigMap(t, testEnv, assert)
}

func TestCreatePodWithSecretGCP(t *testing.T) {
assert := GCPCloudAssert{}
DoTestCreatePodWithSecret(t, testEnv, assert)
}

0 comments on commit 9c13521

Please # to comment.