-
Notifications
You must be signed in to change notification settings - Fork 0
/
go_reclass_model_test.go
52 lines (42 loc) · 2.31 KB
/
go_reclass_model_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package goreclass
import (
"fmt"
"io/ioutil"
"path"
"testing"
"github.com/stretchr/testify/suite"
"gopkg.in/yaml.v3"
)
type ModelTestSuite struct{ suite.Suite }
func (s *ModelTestSuite) TestDefault() { s.compareFromYaml("default") }
func (s *ModelTestSuite) TestFeaturedSimple() { s.compareFromYaml("featured/simple") }
func (s *ModelTestSuite) TestFeaturedWithClasses() { s.compareFromYaml("featured/with-classes") }
func (s *ModelTestSuite) TestFeaturedWithNestedRefs() { s.compareFromYaml("featured/with-nested-refs") }
func (s *ModelTestSuite) TestFeaturedWithOverrides() { s.compareFromYaml("featured/with-overrides") }
func (s *ModelTestSuite) TestFeaturedWithRefs() { s.compareFromYaml("featured/with-refs") }
func (s *ModelTestSuite) TestFeaturedWithRelName() { s.compareFromYaml("featured/with-relative-name") }
func (s *ModelTestSuite) TestExtendedWithClassLoop() { s.compareFromYaml("extended/with-class-loop") }
func (s *ModelTestSuite) TestExtendedWithRefInClass() { s.compareFromYaml("extended/with-ref-in-class") }
func (s *ModelTestSuite) TestErroredOverrideConstant() {
reclassFirstNodePath := path.Join("test/model/errored/override-constant/classes/first.yml")
_, err := BuildInventory(reclassFirstNodePath)
s.Error(err, "BuildInventory must fail if a constant is overrode.")
}
func TestModelSuiteTest(t *testing.T) { suite.Run(t, new(ModelTestSuite)) }
func (s *ModelTestSuite) compareFromYaml(modelName string) {
reclassYamlPath := path.Join("test/model", modelName+".reclassed.yml")
reclassYaml, err := ioutil.ReadFile(reclassYamlPath)
if err != nil {
s.FailNow(fmt.Sprintf("failed to read `reclassed` YAML file %s: %s", reclassYamlPath, err))
}
var reclassInventory Inventory
if err := yaml.Unmarshal(reclassYaml, &reclassInventory); err != nil {
s.FailNow(fmt.Sprintf("failed to unmarshal `reclassed` YAML file %s: %s", reclassYamlPath, err))
}
reclassFirstNodePath := path.Join("test/model", modelName, "classes/first.yml")
goreclassInventory, err := BuildInventory(reclassFirstNodePath)
if err := yaml.Unmarshal(reclassYaml, &reclassInventory); err != nil {
s.FailNow(fmt.Sprintf("failed to build inventory from %s: %s", path.Join("test/model", modelName), err))
}
s.Equalf(&reclassInventory, goreclassInventory, "Inventories differs for model `%s`.", modelName)
}