Skip to content

Commit

Permalink
test: add tests for setup.yamlPath.SameContent()
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornplusplus committed Nov 25, 2024
1 parent b9a0a4b commit 4c67e31
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/setup/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package setup

type YAMLPath = yamlPath
type YAMLArch = yamlArch
50 changes: 50 additions & 0 deletions internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2240,3 +2240,53 @@ func (s *S) TestParseSliceKey(c *C) {
c.Assert(key, DeepEquals, test.expected)
}
}

var sampleText = "sample"

var yamlPathTests = []struct {
path1, path2 *setup.YAMLPath
areSame bool
}{{
path1: &setup.YAMLPath{
Text: &sampleText,
Mutable: true,
Mode: 0644,
Arch: setup.YAMLArch{List: []string{"amd64", "arm64"}},
},
path2: &setup.YAMLPath{
Text: &sampleText,
Mutable: true,
Mode: 0644,
Arch: setup.YAMLArch{List: []string{"amd64", "arm64"}},
},
areSame: true,
}, {
path1: &setup.YAMLPath{Dir: true, Mode: 0755},
path2: &setup.YAMLPath{Dir: true, Mode: 0755},
areSame: true,
}, {
path1: &setup.YAMLPath{Symlink: "foo"},
path2: &setup.YAMLPath{Symlink: "foo"},
areSame: true,
}, {
path1: &setup.YAMLPath{Generate: setup.GenerateManifest},
path2: &setup.YAMLPath{Generate: setup.GenerateManifest},
areSame: true,
}, {
// "until" is not checked.
path1: &setup.YAMLPath{Copy: "foo", Mutable: true, Until: setup.UntilMutate},
path2: &setup.YAMLPath{Copy: "foo", Mutable: true},
areSame: true,
}, {
// Empty texts produce nil Text pointer.
path1: &setup.YAMLPath{Text: nil},
path2: &setup.YAMLPath{Text: nil},
areSame: true,
}}

func (s *S) TestYAMLPathSameContent(c *C) {
for _, test := range yamlPathTests {
areSame := test.path1.SameContent(test.path2)
c.Assert(areSame, Equals, test.areSame)
}
}

0 comments on commit 4c67e31

Please sign in to comment.