Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybuckley committed Oct 31, 2019
1 parent 0f21866 commit e86fdb4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
9 changes: 5 additions & 4 deletions fieldpath/serialize-pe.go
Expand Up @@ -292,14 +292,15 @@ func serializePathElementToStreamV2(stream *jsoniter.Stream, pe PathElement, et
return err
}
stream.WriteArrayStart()
for i := range pe.Key.Items {
kvPairs := *pe.Key
for i := range kvPairs {
if i > 0 {
stream.WriteRaw(",")
}
writeStringOrIndex(stream, pe.Key.Items[i].Name, stringTable)
writeStringOrIndex(stream, kvPairs[i].Name, stringTable)

stream.WriteRaw(",")
pe.Key.Items[i].Value.WriteJSONStream(stream)
kvPairs[i].Value.WriteJSONStream(stream)
}
stream.WriteArrayEnd()
case pe.Value != nil:
Expand All @@ -324,4 +325,4 @@ func writeStringOrIndex(stream *jsoniter.Stream, s string, stringTable map[strin
} else {
stream.WriteString(s)
}
}
}
10 changes: 5 additions & 5 deletions fieldpath/serialize.go
Expand Up @@ -23,8 +23,8 @@ import (
"unsafe"

jsoniter "github.com/json-iterator/go"
"sigs.k8s.io/structured-merge-diff/value"
"sigs.k8s.io/structured-merge-diff/fieldpath/strings"
"sigs.k8s.io/structured-merge-diff/value"
)

func (s *Set) ToJSON() ([]byte, error) {
Expand Down Expand Up @@ -465,7 +465,7 @@ func readIter_v2(iter *jsoniter.Iterator, st []string) (children *Set, isMember
}
pe.Value = &v
case vtKey:
kvPairs, currentKey, substep := &value.Map{}, "", KEY
kvPairs, currentKey, substep := value.FieldList{}, "", KEY
if next := iter.WhatIsNext(); next != jsoniter.ArrayValue {
iter.Error = fmt.Errorf("expecting array got: %v", next)
return false
Expand All @@ -486,12 +486,12 @@ func readIter_v2(iter *jsoniter.Iterator, st []string) (children *Set, isMember
iter.Error = err
return false
}
kvPairs.Items = append(kvPairs.Items, value.Field{Name: currentKey, Value: v})
kvPairs = append(kvPairs, value.Field{Name: currentKey, Value: v})
substep = KEY
}
return true
})
pe.Key = kvPairs
pe.Key = &kvPairs
case vtIndex:
i := iter.ReadInt()
pe.Index = &i
Expand Down Expand Up @@ -559,4 +559,4 @@ func readStringOrIndex(iter *jsoniter.Iterator, stringTable []string) (string, e
return stringTable[index], nil
}
return "", fmt.Errorf("expecting string or int but got: %v", next)
}
}
4 changes: 2 additions & 2 deletions fieldpath/strings/table.go
Expand Up @@ -33,7 +33,7 @@ var DefaultVersion = 1

func init() {
for _, v := range versions {
s := strings.Split(strings.TrimSpace(v),"\n")
s := strings.Split(strings.TrimSpace(v), "\n")
stringTables = append(stringTables, s)

m := map[string]int{}
Expand All @@ -56,4 +56,4 @@ func GetReverseTable(i int) (map[string]int, error) {
return nil, fmt.Errorf("unable to lookup reverse string table version %v", i)
}
return reverseTables[i], nil
}
}
2 changes: 1 addition & 1 deletion fieldpath/strings/v0.go
Expand Up @@ -16,4 +16,4 @@ limitations under the License.

package strings

var v0 = ``
var v0 = ``
2 changes: 1 addition & 1 deletion fieldpath/strings/v1.go
Expand Up @@ -21,4 +21,4 @@ var v1 = `
name
port
`
`
6 changes: 6 additions & 0 deletions internal/cli/main_test.go
Expand Up @@ -192,20 +192,26 @@ func TestCompare(t *testing.T) {
func TestFieldSet(t *testing.T) {
cases := []testCase{{
options: Options{
fieldsetVersion: "v1",

schemaPath: testdata("k8s-schema.yaml"),
fieldset: testdata("pod.yaml"),
typeName: "io.k8s.api.core.v1.Pod",
},
expectedOutputPath: testdata("podset.json"),
}, {
options: Options{
fieldsetVersion: "v1",

schemaPath: testdata("k8s-schema.yaml"),
fieldset: testdata("node.yaml"),
typeName: "io.k8s.api.core.v1.Node",
},
expectedOutputPath: testdata("nodeset.json"),
}, {
options: Options{
fieldsetVersion: "v1",

schemaPath: testdata("k8s-schema.yaml"),
fieldset: testdata("endpoints.yaml"),
typeName: "io.k8s.api.core.v1.Endpoints",
Expand Down

0 comments on commit e86fdb4

Please sign in to comment.