Skip to content

Commit

Permalink
Handle errors from flag setting and tests
Browse files Browse the repository at this point in the history
Signed-off-by: carter.fendley <carter.fendley@gmail.com>
  • Loading branch information
CarterFendley committed Jan 28, 2025
1 parent 5a62e5d commit 13f75c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
7 changes: 5 additions & 2 deletions backend/src/v2/cmd/driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ func main() {
flag.Parse()

glog.Infof("Setting log level to: '%s'", *logLevel)
flag.Set("v", *logLevel)
err := flag.Set("v", *logLevel)
if err != nil {
glog.Warningf("Failed to set log level: %s", err.Error())
}

err := drive()
err = drive()
if err != nil {
glog.Exitf("%v", err)
}
Expand Down
5 changes: 4 additions & 1 deletion backend/src/v2/cmd/launcher-v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func run() error {
ctx := context.Background()

glog.Infof("Setting log level to: '%s'", *logLevel)
flag.Set("v", *logLevel)
err := flag.Set("v", *logLevel)
if err != nil {
glog.Warningf("Failed to set log level: %s", err.Error())
}

if *copy != "" {
// copy is used to copy this binary to a shared volume
Expand Down
19 changes: 19 additions & 0 deletions backend/src/v2/compiler/argocompiler/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"

Expand All @@ -36,6 +37,7 @@ func Test_argo_compiler(t *testing.T) {
jobPath string // path of input PipelineJob to compile
platformSpecPath string // path of possible input PlatformSpec to compile
argoYAMLPath string // path of expected output argo workflow YAML
envVars []string
}{
{
jobPath: "../testdata/hello_world.json",
Expand Down Expand Up @@ -71,6 +73,23 @@ func Test_argo_compiler(t *testing.T) {
for _, tt := range tests {
t.Run(fmt.Sprintf("%+v", tt), func(t *testing.T) {
job, platformSpec := load(t, tt.jobPath, tt.platformSpecPath)
if tt.envVars != nil {
for _, envVar := range tt.envVars {
parts := strings.Split(strings.ReplaceAll(envVar, " ", ""), "=")
err := os.Setenv(parts[0], parts[1])
if err != nil {
t.Fatalf("Failed to set environment variable '%s' with error: %s", parts[0], err.Error())
}

// Unset after test cases has ended
defer func() {
err := os.Unsetenv(parts[0])
if err != nil {
t.Fatalf("Failed to unset env variable '%s' with error: %s", parts[0], err.Error())
}
}()
}
}
if *update {
wf, err := argocompiler.Compile(job, platformSpec, nil)
if err != nil {
Expand Down

0 comments on commit 13f75c2

Please sign in to comment.