Skip to content

Commit

Permalink
fix: error with -Extension index
Browse files Browse the repository at this point in the history
  • Loading branch information
khorevaa committed Dec 19, 2020
1 parent 497ebb9 commit b6c6c6e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
24 changes: 24 additions & 0 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/v8platform/errors"
"github.com/v8platform/marshaler"
"strings"
)

type RepositoryRightType string
Expand Down Expand Up @@ -125,6 +126,7 @@ func (o RepositoryCreateOptions) WithRepository(repository Repository) Repositor
func (ib RepositoryCreateOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand All @@ -143,3 +145,25 @@ func (ib RepositoryCreateOptions) Check() error {
return err.ErrorOrNil()

}

func fixExtensionIndex(values *[]string) {

val := *values
extIdx := -1
for i := 0; i < len(val); i++ {
if strings.Contains(val[i], "-Extension") {
extIdx = i
break
}
}

if extIdx != -1 {
ext := val[extIdx]

val = append(val[:extIdx], val[extIdx+1:]...)
val = append(val, ext)

values = &val
}

}
3 changes: 3 additions & 0 deletions repositoryCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type RepositoryClearGlobalCacheOptions struct {
func (ib RepositoryClearGlobalCacheOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand All @@ -42,6 +43,7 @@ type RepositoryClearCacheOptions struct {
func (ib RepositoryClearCacheOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand All @@ -68,6 +70,7 @@ type RepositoryClearLocalCacheOptions struct {
func (ib RepositoryClearLocalCacheOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand Down
4 changes: 4 additions & 0 deletions repositoryCfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type RepositoryBindCfgOptions struct {
func (ib RepositoryBindCfgOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand Down Expand Up @@ -85,6 +86,7 @@ type RepositoryUnbindCfgOptions struct {
func (ib RepositoryUnbindCfgOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand Down Expand Up @@ -127,6 +129,7 @@ type RepositoryDumpCfgOptions struct {
func (ib RepositoryDumpCfgOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand Down Expand Up @@ -205,6 +208,7 @@ type RepositoryUpdateCfgOptions struct {
func (ib RepositoryUpdateCfgOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand Down
1 change: 1 addition & 0 deletions repositoryService.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type RepositoryReportOptions struct {
func (ib RepositoryReportOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand Down
2 changes: 2 additions & 0 deletions repositoryUsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type RepositoryAddUserOptions struct {
func (o RepositoryAddUserOptions) Values() []string {

v, _ := marshaler.Marshal(o)
fixExtensionIndex(&v)
return v

}
Expand Down Expand Up @@ -93,6 +94,7 @@ type RepositoryCopyUsersOptions struct {
func (ib RepositoryCopyUsersOptions) Values() []string {

v, _ := marshaler.Marshal(ib)
fixExtensionIndex(&v)
return v

}
Expand Down
52 changes: 52 additions & 0 deletions repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,55 @@ func TestRepository_Values(t *testing.T) {
})
}
}

func TestRepository_ValuesFixExtension(t *testing.T) {
type fields interface {
Values() []string
}
tests := []struct {
name string
fields fields
want []string
}{
{
"simple",
Repository{
Path: "./repo",
User: "admin",
Password: "pwd",
Extension: "",
},
[]string{
"/ConfigurationRepositoryF ./repo",
"/ConfigurationRepositoryN admin",
"/ConfigurationRepositoryP pwd",
},
},
{
"ext",
Repository{
Path: "./repo",
User: "admin",
Password: "pwd",
Extension: "test",
}.Report("./file"),
[]string{
"/DisableStartupDialogs",
"/DisableStartupMessages",
"/ConfigurationRepositoryF ./repo",
"/ConfigurationRepositoryN admin",
"/ConfigurationRepositoryP pwd",
"/ConfigurationRepositoryReport ./file",
"-Extension test",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

if got := tt.fields.Values(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Values() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit b6c6c6e

Please sign in to comment.