Skip to content

Commit

Permalink
test(yaml): refactor for table tests (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp committed May 13, 2020
1 parent 3d1e3e1 commit 118a4d1
Show file tree
Hide file tree
Showing 12 changed files with 1,543 additions and 1,473 deletions.
675 changes: 325 additions & 350 deletions yaml/build_test.go

Large diffs are not rendered by default.

70 changes: 44 additions & 26 deletions yaml/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,62 @@ import (
)

func TestYaml_Metadata_ToPipeline(t *testing.T) {
// setup types
m := &Metadata{
Template: false,
// setup tests
tests := []struct {
metadata *Metadata
want *pipeline.Metadata
}{
{
metadata: &Metadata{
Template: false,
},
want: &pipeline.Metadata{
Template: false,
},
},
}

want := &pipeline.Metadata{
Template: false,
}

// run test
got := m.ToPipeline()
// run tests
for _, test := range tests {
got := test.metadata.ToPipeline()

if !reflect.DeepEqual(got, want) {
t.Errorf("ToPipeline is %v, want %v", got, want)
if !reflect.DeepEqual(got, test.want) {
t.Errorf("ToPipeline is %v, want %v", got, test.want)
}
}
}

func TestYaml_Metadata_UnmarshalYAML(t *testing.T) {
// setup types
want := &Metadata{
Template: false,
// setup tests
tests := []struct {
file string
want *Metadata
}{
{
file: "testdata/metadata.yml",
want: &Metadata{
Template: false,
},
},
}

got := new(Metadata)
// run tests
for _, test := range tests {
got := new(Metadata)

// run test
b, err := ioutil.ReadFile("testdata/metadata.yml")
if err != nil {
t.Errorf("Reading file for UnmarshalYAML returned err: %v", err)
}
b, err := ioutil.ReadFile(test.file)
if err != nil {
t.Errorf("Reading file for UnmarshalYAML returned err: %v", err)
}

err = yaml.Unmarshal(b, got)
err = yaml.Unmarshal(b, got)

if err != nil {
t.Errorf("UnmarshalYAML returned err: %v", err)
}
if err != nil {
t.Errorf("UnmarshalYAML returned err: %v", err)
}

if !reflect.DeepEqual(got, want) {
t.Errorf("UnmarshalYAML is %v, want %v", got, want)
if !reflect.DeepEqual(got, test.want) {
t.Errorf("UnmarshalYAML is %v, want %v", got, test.want)
}
}
}
Loading

0 comments on commit 118a4d1

Please sign in to comment.