forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt flyteidl's ordered variable map change (flyteorg#198)
- Loading branch information
1 parent
2e8a22b
commit d76eb15
Showing
18 changed files
with
340 additions
and
111 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
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
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
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,25 @@ | ||
package utils | ||
|
||
import "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
|
||
// This function extracts the variable named "results" from the TaskTemplate | ||
func GetResultsVariable(taskTemplate *core.TaskTemplate) (results *core.Variable, exists bool) { | ||
if taskTemplate == nil { | ||
return nil, false | ||
} | ||
if taskTemplate.Interface == nil { | ||
return nil, false | ||
} | ||
if taskTemplate.Interface.Outputs == nil { | ||
return nil, false | ||
} | ||
if taskTemplate.Interface.Outputs.Variables == nil { | ||
return nil, false | ||
} | ||
for _, e := range taskTemplate.Interface.Outputs.Variables { | ||
if e.Name == "results" { | ||
return e.Var, true | ||
} | ||
} | ||
return nil, false | ||
} |
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,54 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetResultsVariable(t *testing.T) { | ||
t.Run("variable not found with nil pointer", func(t *testing.T) { | ||
emptyTaskTemplate := &core.TaskTemplate{ | ||
Interface: nil, | ||
} | ||
_, found := GetResultsVariable(emptyTaskTemplate) | ||
assert.False(t, found) | ||
}) | ||
|
||
t.Run("variable not found", func(t *testing.T) { | ||
taskTemplate := &core.TaskTemplate{ | ||
Interface: &core.TypedInterface{ | ||
Outputs: &core.VariableMap{ | ||
Variables: []*core.VariableMapEntry{ | ||
{ | ||
Name: "o0", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
_, found := GetResultsVariable(taskTemplate) | ||
assert.False(t, found) | ||
}) | ||
|
||
t.Run("happy case", func(t *testing.T) { | ||
taskTemplate := &core.TaskTemplate{ | ||
Interface: &core.TypedInterface{ | ||
Outputs: &core.VariableMap{ | ||
Variables: []*core.VariableMapEntry{ | ||
{ | ||
Name: "results", | ||
Var: &core.Variable{ | ||
Description: "athena result", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
v, found := GetResultsVariable(taskTemplate) | ||
assert.True(t, found) | ||
assert.Equal(t, "athena result", v.Description) | ||
}) | ||
} |
Oops, something went wrong.