-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #633 from adamarnold-msm/master
Add -parent flag to support parent state files, add priority override
- Loading branch information
Showing
7 changed files
with
202 additions
and
12 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,5 @@ | ||
--- | ||
stateFiles: | ||
- path: examples/example.yaml | ||
- path: examples/minimal-example.yaml | ||
- path: examples/minimal-example.toml |
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
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,33 @@ | ||
package app | ||
|
||
import ( | ||
"io/ioutil" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type StatePath struct { | ||
Path string `yaml:"path"` | ||
} | ||
|
||
type StateFiles struct { | ||
StateFiles []StatePath `yaml:"stateFiles"` | ||
} | ||
|
||
// fromYAML reads a yaml file and decodes it to a state type. | ||
// parser which throws an error if the YAML file is not valid. | ||
func (pc *StateFiles) specFromYAML(file string) error { | ||
rawYamlFile, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
log.Errorf("specFromYaml %v %v", file, err) | ||
return err | ||
} | ||
|
||
yamlFile := string(rawYamlFile) | ||
|
||
if err = yaml.UnmarshalStrict([]byte(yamlFile), pc); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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,90 @@ | ||
package app | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_specFromYAML(t *testing.T) { | ||
type args struct { | ||
file string | ||
s *StateFiles | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "test case 1 -- Valid YAML", | ||
args: args{ | ||
file: "../../examples/example-spec.yaml", | ||
s: new(StateFiles), | ||
}, | ||
want: true, | ||
}, { | ||
name: "test case 2 -- Invalid Yaml", | ||
args: args{ | ||
file: "../../tests/Invalid_example_spec.yaml", | ||
s: new(StateFiles), | ||
}, | ||
want: false, | ||
}, | ||
} | ||
|
||
teardownTestCase := setupStateFileTestCase(t) | ||
defer teardownTestCase(t) | ||
for _, tt := range tests { | ||
// os.Args = append(os.Args, "-f ../../examples/example.yaml") | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := tt.args.s.specFromYAML(tt.args.file) | ||
if err != nil { | ||
t.Log(err) | ||
} | ||
|
||
got := err == nil | ||
if got != tt.want { | ||
t.Errorf("specFromYaml() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_specFileSort(t *testing.T) { | ||
type args struct { | ||
files fileOptionArray | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want [3]int | ||
}{ | ||
{ | ||
name: "test case 1 -- Files sorted by priority", | ||
args: args{ | ||
files: fileOptionArray( | ||
[]fileOption{ | ||
fileOption{"third.yaml", 0}, | ||
fileOption{"first.yaml", -20}, | ||
fileOption{"second.yaml", -10}, | ||
}), | ||
}, | ||
want: [3]int{-20, -10, 0}, | ||
}, | ||
} | ||
|
||
teardownTestCase := setupStateFileTestCase(t) | ||
defer teardownTestCase(t) | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.args.files.sort() | ||
|
||
got := [3]int{} | ||
for i, f := range tt.args.files { | ||
got[i] = f.priority | ||
} | ||
if got != tt.want { | ||
t.Errorf("files from spec file are not sorted by priority = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,4 @@ | ||
--- | ||
stateFiles: | ||
name1: invalid/example.yaml | ||
name2: invalid/minimal-example.yaml |