Skip to content

Commit

Permalink
Removed obsolete function, small refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Fritz Duchardt <[email protected]>
  • Loading branch information
fritzduchardt committed Oct 15, 2023
1 parent 7ae83df commit 09a98c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
1 change: 0 additions & 1 deletion pkg/vendir/cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func (o *SyncOptions) Run() error {
}

if len(dirs) > 0 {

conf, err = conf.Subset(dirOverrides(dirs).Paths())
if err != nil {
return err
Expand Down
17 changes: 2 additions & 15 deletions pkg/vendir/config/lock_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ func NewLockConfigFromBytes(bs []byte) (LockConfig, error) {
return config, nil
}

func LockFileExists(path string) bool {
if _, err := os.Stat(path); err != nil {
if errors.Is(err, fs.ErrNotExist) {
return false
}
panic(fmt.Errorf("can not stat file '%v': %v", path, err))
}
return true
}

func (c LockConfig) WriteToFile(path string) error {
existingBytes, err := os.ReadFile(path)
if err != nil && !errors.Is(err, fs.ErrNotExist) {
Expand Down Expand Up @@ -138,7 +128,7 @@ func (c *LockConfig) Merge(other LockConfig) error {
}
}
if !replaced {
c.AppendDirectory(dir)
c.Directories = append(c.Directories, dir)
}
}
return nil
Expand All @@ -160,7 +150,7 @@ func (c *LockConfig) ReplaceContents(path string, replaceCon LockDirectoryConten
return false
}

func (c LockConfig) AppendContents(path string, appendCon LockDirectoryContents) bool {
func (c *LockConfig) AppendContents(path string, appendCon LockDirectoryContents) bool {
for i, dir := range c.Directories {
if dir.Path == path {
c.Directories[i].Contents = append(dir.Contents, appendCon)
Expand All @@ -169,6 +159,3 @@ func (c LockConfig) AppendContents(path string, appendCon LockDirectoryContents)
}
return false
}
func (c *LockConfig) AppendDirectory(dir LockDirectory) {
c.Directories = append(c.Directories, dir)
}
41 changes: 28 additions & 13 deletions pkg/vendir/config/lock_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,41 @@ func TestLockConfig_AppendContents(t *testing.T) {
})
}

func TestLockConfig_AppendDirectory(t *testing.T) {
func TestLockConfig_Merge(t *testing.T) {
lockConfig := config.LockConfig{
APIVersion: "vendir.k14s.io/v1alpha1",
Kind: "LockConfig",
Directories: []config.LockDirectory{},
}
lockDirectory := config.LockDirectory{
Contents: []config.LockDirectoryContents{
APIVersion: "vendir.k14s.io/v1alpha1",
Kind: "LockConfig",
Directories: []config.LockDirectory{
{
Path: "gitpath",
Path: "gitpath-1",
Contents: []config.LockDirectoryContents{
{
Path: "gitpath-1",
},
},
},
},
}
lockConfig2 := config.LockConfig{
APIVersion: "vendir.k14s.io/v1alpha1",
Kind: "LockConfig",
Directories: []config.LockDirectory{
{
Path: "dirpath",
Path: "gitpath-2",
Contents: []config.LockDirectoryContents{
{
Path: "gitpath-2",
},
},
},
},
}
t.Run("append directory to config", func(t *testing.T) {
lockConfig.AppendDirectory(lockDirectory)
require.Equal(t, 1, len(lockConfig.Directories))
require.Equal(t, 2, len(lockConfig.Directories[0].Contents))
require.Equal(t, config.LockDirectoryContents{Path: "gitpath"}, lockConfig.Directories[0].Contents[0])
lockConfig.Merge(lockConfig2)
require.Equal(t, 2, len(lockConfig.Directories))
require.Equal(t, 1, len(lockConfig.Directories[0].Contents))
require.Equal(t, 1, len(lockConfig.Directories[1].Contents))
require.Equal(t, config.LockDirectoryContents{Path: "gitpath-1"}, lockConfig.Directories[0].Contents[0])
require.Equal(t, config.LockDirectoryContents{Path: "gitpath-2"}, lockConfig.Directories[1].Contents[0])
})
}

0 comments on commit 09a98c8

Please sign in to comment.