-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For now, those are the basic tests we are adding. Signed-off-by: Beraldo Leal <bleal@redhat.com>
- Loading branch information
1 parent
5c100c5
commit 9c13521
Showing
2 changed files
with
113 additions
and
0 deletions.
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
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 | ||
} |
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,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) | ||
} |