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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions testworkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,9 @@ func NewTestWorkflow(opts *TestWorkflowOpts, setupFunc func(*TestWorkflow) error
} else {
t.Image, err = t.Client.GetImage(split[1], split[len(split)-1])
}
if err != nil {
return nil, err
}

// Initializing ImageBeta inside the TestWorkflow, this is required to provide Beta support to cvm testsuite
if strings.Contains(opts.Image, "family") {
Expand Down
71 changes: 71 additions & 0 deletions testworkflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package imagetest

import (
"context"
"errors"
"fmt"
"net/http"
"slices"
Expand Down Expand Up @@ -903,6 +904,76 @@ func TestNewTestWorkflow(t *testing.T) {
}
}

func TestNewTestWorkflowV1ImageLookupError(t *testing.T) {
wantErr := errors.New("v1 image lookup failed")
tests := []struct {
name string
image string
}{
{
name: "image_family",
image: "projects/fake-cloud/global/images/family/fakeos",
},
{
name: "image_name",
image: "projects/fake-cloud/global/images/fakeos-v1",
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
srv, client, err := daisycompute.NewTestClient(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintln(w, "Method not recognized:", r.Method, r.URL)
return
}
switch r.URL.String() {
case "/projects/fake-project?alt=json&prettyPrint=false":
fmt.Fprint(w, `{"Name":"fake-project"}`)
case "/projects/fake-project/zones/us-central1-a?alt=json&prettyPrint=false":
fmt.Fprint(w, `{"Name":"us-central1-a"}`)
case fmt.Sprintf("/%s?alt=json&prettyPrint=false", tc.image):
// Simulate Beta image lookup succeeding after the v1 lookup fails.
fmt.Fprint(w, `{"Name":"fakeos","Architecture":"X86_64"}`)
default:
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "URL and Method not recognized:", r.Method, r.URL)
}
}))
if err != nil {
t.Fatalf("daisycompute.NewTestClient() failed: %v", err)
}
defer srv.Close()

client.GetImageFromFamilyFn = func(project, family string) (*compute.Image, error) {
return nil, wantErr
}
client.GetImageFn = func(project, name string) (*compute.Image, error) {
return nil, wantErr
}

opts := &TestWorkflowOpts{
Client: client,
Name: tc.name,
Image: tc.image,
Timeout: "20m",
Project: "fake-project",
Zone: "us-central1-a",
X86Shape: "n1-standard-1",
ARM64Shape: "t2a-standard-1",
}
got, err := NewTestWorkflow(opts, nil)
if !errors.Is(err, wantErr) {
t.Errorf("NewTestWorkflow(image=%q) err = %v, want %v", tc.image, err, wantErr)
}
if got != nil {
t.Errorf("NewTestWorkflow(image=%q) = %v, want nil", tc.image, got)
}
})
}
}

func TestGetLastStepForVM(t *testing.T) {
twf := NewTestWorkflowForUnitTest("name", "image", "30m")
if _, err := twf.CreateTestVM("vm"); err != nil {
Expand Down