From 5b98095ac313e125ba14c2d88036e8ceb3aa04d9 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Tue, 18 Oct 2022 15:18:55 -0400 Subject: [PATCH] implement read ifd from file --- test/e2e/pkg/infrastructure.go | 12 ++++++++++++ test/e2e/runner/main.go | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/test/e2e/pkg/infrastructure.go b/test/e2e/pkg/infrastructure.go index b46aedc08..944225b82 100644 --- a/test/e2e/pkg/infrastructure.go +++ b/test/e2e/pkg/infrastructure.go @@ -1,8 +1,10 @@ package e2e import ( + "encoding/json" "fmt" "net" + "os" ) // InfrastructureData contains the relevant information for a set of existing @@ -42,3 +44,13 @@ func NewDockerInfrastructureData(m Manifest) (InfrastructureData, error) { } return ifd, nil } + +func InfrastructureDataFromFile(p string) (InfrastructureData, error) { + ifd := InfrastructureData{} + b, err := os.ReadFile(p) + err = json.Unmarshal(b, &ifd) + if err != nil { + return InfrastructureData{}, err + } + return ifd, nil +} diff --git a/test/e2e/runner/main.go b/test/e2e/runner/main.go index e346a9ae2..976a52d75 100644 --- a/test/e2e/runner/main.go +++ b/test/e2e/runner/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "errors" "fmt" "math/rand" "os" @@ -59,6 +60,15 @@ func NewCLI() *CLI { if err != nil { return err } + case "digital-ocean": + p, err := cmd.Flags().GetString("infrastructure-data") + if err != nil { + return err + } + if p == "" { + return errors.New("'--infrastructure-data' must be set when using the 'digital-ocean' infrastructure-type") + } + ifd, err = e2e.InfrastructureDataFromFile(p) // TODO(williambanfield): add a section that implements the 'digital-ocean' infrastructure-type default: return fmt.Errorf("unknown infrastructure type '%s'", t)