From 167a6ebc5ea5a8742fb0a3dce39c41022c8c9608 Mon Sep 17 00:00:00 2001 From: Rafid Bin Mostofa Date: Mon, 25 Nov 2024 20:33:22 +0600 Subject: [PATCH] test: only add tests for GeneratePath 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. --- internal/setup/export_test.go | 1 - internal/setup/setup_test.go | 96 +++-------------------------------- 2 files changed, 8 insertions(+), 89 deletions(-) diff --git a/internal/setup/export_test.go b/internal/setup/export_test.go index aae27c75..35231e50 100644 --- a/internal/setup/export_test.go +++ b/internal/setup/export_test.go @@ -1,4 +1,3 @@ package setup type YAMLPath = yamlPath -type YAMLArch = yamlArch diff --git a/internal/setup/setup_test.go b/internal/setup/setup_test.go index c08bc15f..114dcfd7 100644 --- a/internal/setup/setup_test.go +++ b/internal/setup/setup_test.go @@ -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) }