Skip to content

Commit

Permalink
change MergeProfiles to work with slice of profiles instead of Content
Browse files Browse the repository at this point in the history
  • Loading branch information
guumaster committed Apr 18, 2020
1 parent f048f62 commit de6ede1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
7 changes: 1 addition & 6 deletions pkg/host/file/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ func (f *File) AddProfile(p *types.Profile) error {
return errors.ErrDefaultProfileError
}

f.MergeProfiles(&types.Content{
ProfileNames: []string{p.Name},
Profiles: map[string]*types.Profile{
p.Name: p,
},
})
f.MergeProfiles([]*types.Profile{p})

return nil
}
6 changes: 3 additions & 3 deletions pkg/host/file/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
)

// MergeProfiles joins new content with existing content
func (f *File) MergeProfiles(content *types.Content) {
for _, newName := range content.ProfileNames {
newP := content.Profiles[newName]
func (f *File) MergeProfiles(profiles []*types.Profile) {
for _, newP := range profiles {
newName := newP.Name

_, ok := f.data.Profiles[newName]
if !ok {
Expand Down
34 changes: 15 additions & 19 deletions pkg/host/file/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,35 @@ func TestFile_MergeProfiles(t *testing.T) {
ip3 := net.ParseIP("2.2.2.2")
ip4 := net.ParseIP("3.3.3.3")

c := &types.Content{
DefaultProfile: nil,
ProfileNames: []string{"profile2", "profile3"},
Profiles: map[string]*types.Profile{
"profile2": {
Name: "profile2",
Status: types.Enabled,
Routes: map[string]*types.Route{
ip3.String(): {IP: ip3, HostNames: []string{"third.new.loc"}},
},
profiles := []*types.Profile{
{
Name: "profile2",
Status: types.Enabled,
Routes: map[string]*types.Route{
ip3.String(): {IP: ip3, HostNames: []string{"third.new.loc"}},
},
"profile3": {
Name: "profile3",
Status: types.Enabled,
Routes: map[string]*types.Route{
ip4.String(): {IP: ip4, HostNames: []string{"third.new.loc", "fourth.new.loc"}},
},
},
{
Name: "profile3",
Status: types.Enabled,
Routes: map[string]*types.Route{
ip4.String(): {IP: ip4, HostNames: []string{"third.new.loc", "fourth.new.loc"}},
},
},
}
m.MergeProfiles(c)
m.MergeProfiles(profiles)

assert.Equal(t, []string{"profile1", "profile3"}, m.GetEnabled())
assert.Equal(t, []string{"profile2"}, m.GetDisabled())

p3, err := m.GetProfile("profile3")
assert.NoError(t, err)
assert.Equal(t, c.Profiles["profile3"], p3)
assert.Equal(t, profiles[1], p3)

p2, err := m.GetProfile("profile2")
assert.NoError(t, err)

modP2 := c.Profiles["profile2"]
modP2 := profiles[0]
modP2.IPList = []string{"127.0.0.1", "2.2.2.2"}
modP2.Routes[Localhost.String()] = &types.Route{IP: Localhost, HostNames: []string{"first.loc", "second.loc"}}
modP2.Status = types.Disabled
Expand Down
8 changes: 4 additions & 4 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ sonar.projectKey=guumaster_hostctl
sonar.projectName=hostctl
sonar.projectVersion=1.0.0
sonar.sources=.
sonar.exclusions=**/*_test.go,**/*docker*.go,*.go,**/*doc?.go,**/*types.go,**/*.xml,**/errors.go
sonar.exclusions=**/*_test.go,**/*docker*.go,*.go,**/*doc?.go,**/types.go,**/*.xml,**/errors.go
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/cmd/*docker*.go,*.go,**/*doc?.go,**/*types.go,**/errors.go,**/*.xml
sonar.coverage.exclusions=**/cmd/*docker*.go,*.go,**/*doc?.go,**/*types.go,**/*.xml,**/errors.go,cmd/**
sonar.go.coverage.exclusions=**/cmd/*docker*.go,*.go,**/*doc?.go,**/*types.go,**/*.xml,**/errors.go,cmd/**
sonar.test.exclusions=**/cmd/*docker*.go,*.go,**/*doc?.go,**/types.go,**/errors.go,**/*.xml
sonar.coverage.exclusions=**/cmd/*docker*.go,*.go,**/*doc?.go,**/types.go,**/*.xml,**/errors.go,cmd/**
sonar.go.coverage.exclusions=**/cmd/*docker*.go,*.go,**/*doc?.go,**/types.go,**/*.xml,**/errors.go,cmd/**
sonar.go.coverage.reportPaths=/github/workspace/ubuntu-latest_coverage/ubuntu-latest_coverage.out
#sonar.go.golangci-lint.reportPaths=/github/workspace/golangci-report.xml

0 comments on commit de6ede1

Please sign in to comment.