Skip to content

Commit

Permalink
fix flyteadmin tests
Browse files Browse the repository at this point in the history
Signed-off-by: Future-Outlier <[email protected]>
  • Loading branch information
Future-Outlier committed Aug 9, 2024
1 parent a005a2d commit 7ece699
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
2 changes: 2 additions & 0 deletions flyteadmin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions flyteadmin/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,10 @@ github.com/unrolled/secure v0.0.0-20181005190816-ff9db2ff917f/go.mod h1:mnPT77IA
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/wI2L/jsondiff v0.5.0 h1:RRMTi/mH+R2aXcPe1VYyvGINJqQfC3R+KSEakuU1Ikw=
github.com/wI2L/jsondiff v0.5.0/go.mod h1:qqG6hnK0Lsrz2BpIVCxWiK9ItsBCpIZQiv0izJjOZ9s=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
Expand Down
50 changes: 32 additions & 18 deletions flytepropeller/pkg/controller/nodes/attr_path_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func resolveAttrPathInPbStruct(nodeID string, st *structpb.Struct, bindAttrPath
}

// After resolve, convert the interface to literal
literal, err := convertInterfaceToLiteral(nodeID, currVal)
literal, err := convertInterfaceToLiteral(nodeID, currVal, false)

return literal, err
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func resolveAttrPathInJson(nodeID string, json_byte []byte, bindAttrPath []*core
}

// After resolve, convert the interface to literal
literal, err := convertInterfaceToLiteral(nodeID, currVal)
literal, err := convertInterfaceToLiteral(nodeID, currVal, true)

Check warning on line 139 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L139

Added line #L139 was not covered by tests

return literal, err

Check warning on line 141 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L141

Added line #L141 was not covered by tests
}
Expand Down Expand Up @@ -168,34 +168,48 @@ func convertNumbers(v interface{}) interface{} {
}

// convertInterfaceToLiteral converts the protobuf struct (e.g. dataclass) to literal
func convertInterfaceToLiteral(nodeID string, obj interface{}) (*core.Literal, error) {
func convertInterfaceToLiteral(nodeID string, obj interface{}, isJson bool) (*core.Literal, error) {

literal := &core.Literal{}

switch obj := obj.(type) {
case map[string]interface{}:
jsonBytes, err := json.Marshal(obj)
if err != nil {
return nil, err
}
jsonBytes, err = msgpack.Marshal(jsonBytes)
if err != nil {
return nil, err
}
literal.Value = &core.Literal_Scalar{
Scalar: &core.Scalar{
Value: &core.Scalar_Json{
Json: &core.Json{
Value: jsonBytes,
if isJson {
jsonBytes, err := json.Marshal(obj)
if err != nil {
return nil, err

Check warning on line 180 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L177-L180

Added lines #L177 - L180 were not covered by tests
}
jsonBytes, err = msgpack.Marshal(jsonBytes)
if err != nil {
return nil, err

Check warning on line 184 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L182-L184

Added lines #L182 - L184 were not covered by tests
}
literal.Value = &core.Literal_Scalar{
Scalar: &core.Scalar{
Value: &core.Scalar_Json{
Json: &core.Json{
Value: jsonBytes,
},
},

Check warning on line 192 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L186-L192

Added lines #L186 - L192 were not covered by tests
},
},
}
} else {
newSt, err := structpb.NewStruct(obj)
if err != nil {
return nil, err

Check warning on line 198 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L195-L198

Added lines #L195 - L198 were not covered by tests
}
literal.Value = &core.Literal_Scalar{
Scalar: &core.Scalar{
Value: &core.Scalar_Generic{
Generic: newSt,
},
},

Check warning on line 205 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L200-L205

Added lines #L200 - L205 were not covered by tests
}
}
case []interface{}:
literals := []*core.Literal{}
for _, v := range obj {
// recursively convert the interface to literal
literal, err := convertInterfaceToLiteral(nodeID, v)
literal, err := convertInterfaceToLiteral(nodeID, v, isJson)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 7ece699

Please sign in to comment.