-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix setting nil data values via --data-value flag
- Loading branch information
1 parent
a7971f8
commit c1681b1
Showing
2 changed files
with
57 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package yamlmeta_test | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/k14s/ytt/pkg/yamlmeta" | ||
) | ||
|
||
var _ = fmt.Sprintf | ||
|
||
func TestPlainUnmarshalInt(t *testing.T) { | ||
var val interface{} = "abc" // set to some previous value | ||
|
||
err := yamlmeta.PlainUnmarshal([]byte("123"), &val) | ||
if err != nil { | ||
t.Fatalf("Expected to succeed: %s", err) | ||
} | ||
if !reflect.DeepEqual(val, 123) { | ||
t.Fatalf("Expected to be nil: val=%#v type=%T", val, val) | ||
} | ||
} | ||
|
||
func TestPlainUnmarshalNil(t *testing.T) { | ||
var val interface{} = 123 // set to some previous value | ||
|
||
err := yamlmeta.PlainUnmarshal([]byte("null"), &val) | ||
if err != nil { | ||
t.Fatalf("Expected to succeed: %s", err) | ||
} | ||
if !reflect.DeepEqual(val, nil) { | ||
t.Fatalf("Expected to be nil: val=%#v type=%T", val, val) | ||
} | ||
} | ||
|
||
func TestPlainUnmarshalMap(t *testing.T) { | ||
var val interface{} = 123 // set to some previous value | ||
|
||
err := yamlmeta.PlainUnmarshal([]byte(`{"a":123}`), &val) | ||
if err != nil { | ||
t.Fatalf("Expected to succeed: %s", err) | ||
} | ||
if !reflect.DeepEqual(val, map[interface{}]interface{}{"a": 123}) { | ||
t.Fatalf("Expected to be nil: val=%#v type=%T", val, val) | ||
} | ||
} |