Skip to content

Commit

Permalink
test: only add tests for GeneratePath
Browse files Browse the repository at this point in the history
Per offline comments, let's just have the SameContent tests for
GeneratePath, because every other kind of paths are tested indirectly in
slicer_test and setup_test.
  • Loading branch information
rebornplusplus committed Nov 25, 2024
1 parent 1810c74 commit 167a6eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 89 deletions.
1 change: 0 additions & 1 deletion internal/setup/export_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package setup

type YAMLPath = yamlPath
type YAMLArch = yamlArch
96 changes: 8 additions & 88 deletions internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2241,93 +2241,13 @@ func (s *S) TestParseSliceKey(c *C) {
}
}

var sampleText = "sample"
func (s *S) TestGeneratePathSameContent(c *C) {
path1 := &setup.YAMLPath{Generate: setup.GenerateManifest}
path2 := &setup.YAMLPath{Generate: setup.GenerateManifest}
result := path1.SameContent(path2)
c.Assert(result, Equals, true)

var yamlPathTests = []struct {
summary string
path1, path2 *setup.YAMLPath
result bool
}{{
summary: "Text path",
path1: &setup.YAMLPath{Text: &sampleText, Mutable: true, Mode: 0644},
path2: &setup.YAMLPath{Text: &sampleText, Mutable: true, Mode: 0644},
result: true,
}, {
summary: "Dir path",
path1: &setup.YAMLPath{Dir: true, Mode: 0755},
path2: &setup.YAMLPath{Dir: true, Mode: 0755},
result: true,
}, {
summary: "Symlink path",
path1: &setup.YAMLPath{Symlink: "foo"},
path2: &setup.YAMLPath{Symlink: "foo"},
result: true,
}, {
summary: "Generate path",
path1: &setup.YAMLPath{Generate: setup.GenerateManifest},
path2: &setup.YAMLPath{Generate: setup.GenerateManifest},
result: true,
}, {
summary: "Copy path",
path1: &setup.YAMLPath{Copy: "foo"},
path2: &setup.YAMLPath{Copy: "foo"},
result: true,
}, {
summary: `"arch" is not checked`,
path1: &setup.YAMLPath{Text: nil, Arch: setup.YAMLArch{List: []string{"amd64"}}},
path2: &setup.YAMLPath{Text: nil, Arch: setup.YAMLArch{List: []string{"arm64"}}},
result: true,
}, {
summary: `"until" is not checked`,
path1: &setup.YAMLPath{Copy: "foo", Mutable: true, Until: setup.UntilMutate},
path2: &setup.YAMLPath{Copy: "foo", Mutable: true},
result: true,
}, {
summary: `Empty "text" produces nil pointer`,
path1: &setup.YAMLPath{Text: nil},
path2: &setup.YAMLPath{Text: nil},
result: true,
}, {
summary: `Different "generate" values`,
path1: &setup.YAMLPath{Generate: setup.GenerateManifest},
path2: &setup.YAMLPath{Generate: setup.GenerateNone},
result: false,
}, {
summary: `Different "text" pointers`,
path1: &setup.YAMLPath{Text: new(string)},
path2: &setup.YAMLPath{Text: new(string)},
result: false,
}, {
summary: `Different "copy" values`,
path1: &setup.YAMLPath{Copy: "foo"},
path2: &setup.YAMLPath{Copy: "bar"},
result: false,
}, {
summary: `Different "make" (Dir) values`,
path1: &setup.YAMLPath{Dir: true},
path2: &setup.YAMLPath{Dir: false},
result: false,
}, {
summary: `Different "symlink" values`,
path1: &setup.YAMLPath{Symlink: "foo"},
path2: &setup.YAMLPath{Symlink: "bar"},
result: false,
}, {
summary: `Different "mode" values`,
path1: &setup.YAMLPath{Text: nil, Mode: 0644},
path2: &setup.YAMLPath{Text: nil, Mode: 0755},
result: false,
}, {
summary: `Different "mutable" values`,
path1: &setup.YAMLPath{Text: nil, Mutable: true},
path2: &setup.YAMLPath{Text: nil, Mutable: false},
result: false,
}}

func (s *S) TestYAMLPathSameContent(c *C) {
for _, test := range yamlPathTests {
c.Logf("Summary: %s", test.summary)
result := test.path1.SameContent(test.path2)
c.Assert(result, Equals, test.result)
}
path2.Generate = setup.GenerateNone
result = path1.SameContent(path2)
c.Assert(result, Equals, false)
}

0 comments on commit 167a6eb

Please sign in to comment.