Skip to content

Commit

Permalink
Remove invalid tests
Browse files Browse the repository at this point in the history
Some of the `fillDefaults` tests were testing invalid situations. To
prevent this, validation is run on the test ins and outs before calling
`fillDefaults`. The invalid tests have been removed.

This commit also removes the sorting from `fillDefaults`, this will be
left to the user instead.

Signed-off-by: Peter Engelbert <[email protected]>
  • Loading branch information
pmengelbert committed Feb 5, 2025
1 parent cf1cf76 commit a21b267
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 78 deletions.
78 changes: 4 additions & 74 deletions load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1281,31 +1281,7 @@ func testSymlinkFillDefaults(t *testing.T) {
Post: &PostInstall{
Symlinks: map[string]SymlinkTarget{
"oldpath": {
Path: "/newpath2",
Paths: []string{"/newpath1"},
},
},
},
},
output: ImageConfig{
Post: &PostInstall{
Symlinks: map[string]SymlinkTarget{
"oldpath": {
Path: "",
Paths: []string{"/newpath1", "/newpath2"},
},
},
},
},
},
{
desc: "Path should be appended to Paths",
input: ImageConfig{
Post: &PostInstall{
Symlinks: map[string]SymlinkTarget{
"oldpath": {
Path: "/newpath3",
Paths: []string{"/newpath1", "/newpath2"},
Path: "/newpath1",
},
},
},
Expand All @@ -1315,7 +1291,7 @@ func testSymlinkFillDefaults(t *testing.T) {
Symlinks: map[string]SymlinkTarget{
"oldpath": {
Path: "",
Paths: []string{"/newpath1", "/newpath2", "/newpath3"},
Paths: []string{"/newpath1"},
},
},
},
Expand Down Expand Up @@ -1344,52 +1320,6 @@ func testSymlinkFillDefaults(t *testing.T) {
},
},
},
{
desc: "should work if Paths is empty",
input: ImageConfig{
Post: &PostInstall{
Symlinks: map[string]SymlinkTarget{
"oldpath": {
Path: "/newpath",
Paths: nil,
},
},
},
},
output: ImageConfig{
Post: &PostInstall{
Symlinks: map[string]SymlinkTarget{
"oldpath": {
Path: "",
Paths: []string{"/newpath"},
},
},
},
},
},
{
desc: "empty Path and multimple Paths should have Paths sorted",
input: ImageConfig{
Post: &PostInstall{
Symlinks: map[string]SymlinkTarget{
"oldpath": {
Path: "",
Paths: []string{"/newpath2", "/newpath1"},
},
},
},
},
output: ImageConfig{
Post: &PostInstall{
Symlinks: map[string]SymlinkTarget{
"oldpath": {
Path: "",
Paths: []string{"/newpath1", "/newpath2"},
},
},
},
},
},
}

for _, test := range table {
Expand All @@ -1406,8 +1336,6 @@ func testSymlinkFillDefaults(t *testing.T) {
return true
}

test.input.fillDefaults()

in := test.input.Post.Symlinks
out := test.output.Post.Symlinks
if err := validateSymlinks(in); err != nil {
Expand All @@ -1420,6 +1348,8 @@ func testSymlinkFillDefaults(t *testing.T) {
return
}

test.input.fillDefaults()

if !maps.EqualFunc(in, out, cmp) {
in, _ := json.MarshalIndent(in, "", "\t")
out, _ := json.MarshalIndent(out, "", "\t")
Expand Down
6 changes: 2 additions & 4 deletions target.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dalec

import (
goerrors "errors"
"sort"

"github.com/moby/buildkit/frontend/dockerfile/shell"
"github.com/pkg/errors"
Expand Down Expand Up @@ -81,10 +80,10 @@ func (i *ImageConfig) fillDefaults() {
return
}

i.Post.fillDefaults()
i.Post.normalizeSymlinks()
}

func (p *PostInstall) fillDefaults() {
func (p *PostInstall) normalizeSymlinks() {
if p == nil {
return
}
Expand All @@ -96,7 +95,6 @@ func (p *PostInstall) fillDefaults() {
cfg.Path = ""
}

sort.Strings(cfg.Paths)
p.Symlinks[oldpath] = cfg
}
}

0 comments on commit a21b267

Please sign in to comment.