本文整理汇总了Golang中github.com/bitrise-io/envman/models.EnvironmentItemModel类的典型用法代码示例。如果您正苦于以下问题:Golang EnvironmentItemModel类的具体用法?Golang EnvironmentItemModel怎么用?Golang EnvironmentItemModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EnvironmentItemModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: addEnv
func addEnv(key string, value string, expand, replace bool) error {
// Validate input
if key == "" {
return errors.New("Key is not specified, required.")
}
// Load envs, or create if not exist
environments, err := envman.ReadEnvsOrCreateEmptyList()
if err != nil {
return err
}
// Add or update envlist
newEnv := models.EnvironmentItemModel{
key: value,
models.OptionsKey: models.EnvironmentItemOptionsModel{
IsExpand: pointers.NewBoolPtr(expand),
},
}
if err := newEnv.NormalizeEnvironmentItemModel(); err != nil {
return err
}
newEnvSlice, err := envman.UpdateOrAddToEnvlist(environments, newEnv, replace)
if err != nil {
return err
}
if err := envman.WriteEnvMapToFile(envman.CurrentEnvStoreFilePath, newEnvSlice); err != nil {
return err
}
return nil
}
开发者ID:bazscsa,项目名称:envman,代码行数:34,代码来源:add.go
示例2: removeDefaults
func removeDefaults(env *models.EnvironmentItemModel) error {
opts, err := env.GetOptions()
if err != nil {
return err
}
if opts.Title != nil && *opts.Title == "" {
opts.Title = nil
}
if opts.Description != nil && *opts.Description == "" {
opts.Description = nil
}
if opts.Summary != nil && *opts.Summary == "" {
opts.Summary = nil
}
if opts.IsRequired != nil && *opts.IsRequired == models.DefaultIsRequired {
opts.IsRequired = nil
}
if opts.IsExpand != nil && *opts.IsExpand == models.DefaultIsExpand {
opts.IsExpand = nil
}
if opts.IsDontChangeValue != nil && *opts.IsDontChangeValue == models.DefaultIsDontChangeValue {
opts.IsDontChangeValue = nil
}
(*env)[models.OptionsKey] = opts
return nil
}
开发者ID:bazscsa,项目名称:envman,代码行数:26,代码来源:util.go
示例3: removeEnvironmentRedundantFields
func removeEnvironmentRedundantFields(env *envmanModels.EnvironmentItemModel) error {
options, err := env.GetOptions()
if err != nil {
return err
}
hasOptions := false
if options.Title != nil {
if *options.Title == "" {
options.Title = nil
} else {
hasOptions = true
}
}
if options.Description != nil {
if *options.Description == "" {
options.Description = nil
} else {
hasOptions = true
}
}
if options.Summary != nil {
if *options.Summary == "" {
options.Summary = nil
} else {
hasOptions = true
}
}
if options.IsRequired != nil {
if *options.IsRequired == envmanModels.DefaultIsRequired {
options.IsRequired = nil
} else {
hasOptions = true
}
}
if options.IsExpand != nil {
if *options.IsExpand == envmanModels.DefaultIsExpand {
options.IsExpand = nil
} else {
hasOptions = true
}
}
if options.IsDontChangeValue != nil {
if *options.IsDontChangeValue == envmanModels.DefaultIsDontChangeValue {
options.IsDontChangeValue = nil
} else {
hasOptions = true
}
}
if hasOptions {
(*env)[envmanModels.OptionsKey] = options
} else {
delete(*env, envmanModels.OptionsKey)
}
return nil
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:59,代码来源:models_methods.go
示例4: convert
func (input InputModel) convert() (envmanModels.EnvironmentItemModel, error) {
environment := envmanModels.EnvironmentItemModel{
input.MappedTo: input.Value,
envmanModels.OptionsKey: input.getOptions(),
}
if err := environment.FillMissingDefaults(); err != nil {
return envmanModels.EnvironmentItemModel{}, err
}
return environment, nil
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:10,代码来源:methods.go
示例5: MergeEnvironmentWith
// MergeEnvironmentWith ...
func MergeEnvironmentWith(env *envmanModels.EnvironmentItemModel, otherEnv envmanModels.EnvironmentItemModel) error {
// merge key-value
key, _, err := env.GetKeyValuePair()
if err != nil {
return err
}
otherKey, otherValue, err := otherEnv.GetKeyValuePair()
if err != nil {
return err
}
if otherKey != key {
return errors.New("Env keys are diferent")
}
(*env)[key] = otherValue
//merge options
options, err := env.GetOptions()
if err != nil {
return err
}
otherOptions, err := otherEnv.GetOptions()
if err != nil {
return err
}
if otherOptions.Title != nil {
options.Title = pointers.NewStringPtr(*otherOptions.Title)
}
if otherOptions.Description != nil {
options.Description = pointers.NewStringPtr(*otherOptions.Description)
}
if otherOptions.Summary != nil {
options.Summary = pointers.NewStringPtr(*otherOptions.Summary)
}
if len(otherOptions.ValueOptions) > 0 {
options.ValueOptions = otherOptions.ValueOptions
}
if otherOptions.IsRequired != nil {
options.IsRequired = pointers.NewBoolPtr(*otherOptions.IsRequired)
}
if otherOptions.IsExpand != nil {
options.IsExpand = pointers.NewBoolPtr(*otherOptions.IsExpand)
}
if otherOptions.IsDontChangeValue != nil {
options.IsDontChangeValue = pointers.NewBoolPtr(*otherOptions.IsDontChangeValue)
}
if otherOptions.IsTemplate != nil {
options.IsTemplate = pointers.NewBoolPtr(*otherOptions.IsTemplate)
}
(*env)[envmanModels.OptionsKey] = options
return nil
}
开发者ID:birmacher,项目名称:bitrise,代码行数:56,代码来源:models_methods.go
示例6: ValidateStepInputOutputModel
// ValidateStepInputOutputModel ...
func ValidateStepInputOutputModel(env envmanModels.EnvironmentItemModel, checkRequiredFields bool) error {
if err := env.Validate(); err != nil {
return err
}
if checkRequiredFields {
options, err := env.GetOptions()
if err != nil {
return err
}
if options.Title == nil || *options.Title == "" {
return errors.New("Invalid environment: missing or empty title")
}
}
return nil
}
开发者ID:andrewhavens,项目名称:bitrise,代码行数:19,代码来源:models_methods.go
示例7: countOfEnvKeyInEnvSlice
func countOfEnvKeyInEnvSlice(env models.EnvironmentItemModel, envSlice []models.EnvironmentItemModel) (cnt int, err error) {
for _, e := range envSlice {
key, _, err := env.GetKeyValuePair()
if err != nil {
return 0, err
}
k, _, err := e.GetKeyValuePair()
if err != nil {
return 0, err
}
if key == k {
cnt++
}
}
return
}
开发者ID:fbernardo,项目名称:envman,代码行数:18,代码来源:util_test.go
示例8: TestRemoveDefaults
func TestRemoveDefaults(t *testing.T) {
defaultIsRequired := models.DefaultIsRequired
defaultIsExpand := models.DefaultIsExpand
defaultIsDontChangeValue := models.DefaultIsDontChangeValue
// Filled env
env := models.EnvironmentItemModel{
testKey: testValue,
models.OptionsKey: models.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(testTitle),
Description: pointers.NewStringPtr(testEmptyString),
ValueOptions: []string{},
IsRequired: pointers.NewBoolPtr(defaultIsRequired),
IsExpand: pointers.NewBoolPtr(defaultIsExpand),
IsDontChangeValue: pointers.NewBoolPtr(defaultIsDontChangeValue),
},
}
err := removeDefaults(&env)
if err != nil {
t.Fatal(err)
}
opts, err := env.GetOptions()
if err != nil {
t.Fatal(err)
}
if opts.Title == nil {
t.Fatal("Removed Title")
}
if opts.Description != nil {
t.Fatal("Failed to remove default Description")
}
if opts.IsRequired != nil {
t.Fatal("Failed to remove default IsRequired")
}
if opts.IsExpand != nil {
t.Fatal("Failed to remove default IsExpand")
}
if opts.IsDontChangeValue != nil {
t.Fatal("Failed to remove default IsDontChangeValue")
}
}
开发者ID:bazscsa,项目名称:envman,代码行数:43,代码来源:util_test.go
示例9: ValidateStepInputOutputModel
// ValidateStepInputOutputModel ...
func ValidateStepInputOutputModel(env envmanModels.EnvironmentItemModel) error {
key, _, err := env.GetKeyValuePair()
if err != nil {
return err
}
if key == "" {
return errors.New("Invalid environment: empty env_key")
}
options, err := env.GetOptions()
if err != nil {
return err
}
if options.Title == nil || *options.Title == "" {
return errors.New("Invalid environment: missing or empty title")
}
return nil
}
开发者ID:viktorbeneitest,项目名称:bitrise,代码行数:21,代码来源:models_methods.go
示例10: addEnv
func addEnv(key string, value string, expand, replace, skipIfEmpty bool) error {
// Load envs, or create if not exist
environments, err := envman.ReadEnvsOrCreateEmptyList()
if err != nil {
return err
}
// Validate input
validatedValue, err := validateEnv(key, value, environments)
if err != nil {
return err
}
value = validatedValue
// Add or update envlist
newEnv := models.EnvironmentItemModel{
key: value,
models.OptionsKey: models.EnvironmentItemOptionsModel{
IsExpand: pointers.NewBoolPtr(expand),
SkipIfEmpty: pointers.NewBoolPtr(skipIfEmpty),
},
}
if err := newEnv.NormalizeValidateFillDefaults(); err != nil {
return err
}
newEnvSlice, err := envman.UpdateOrAddToEnvlist(environments, newEnv, replace)
if err != nil {
return err
}
if err := envman.WriteEnvMapToFile(envman.CurrentEnvStoreFilePath, newEnvSlice); err != nil {
return err
}
return nil
}
开发者ID:fbernardo,项目名称:envman,代码行数:37,代码来源:add.go
示例11: TestRemoveDefaults
func TestRemoveDefaults(t *testing.T) {
// Filled env
env := models.EnvironmentItemModel{
"test_key": "test_value",
models.OptionsKey: models.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr("test_title"),
IsTemplate: pointers.NewBoolPtr(!models.DefaultIsTemplate),
Description: pointers.NewStringPtr(""),
Summary: pointers.NewStringPtr(""),
ValueOptions: []string{},
IsRequired: pointers.NewBoolPtr(models.DefaultIsRequired),
IsDontChangeValue: pointers.NewBoolPtr(models.DefaultIsDontChangeValue),
IsExpand: pointers.NewBoolPtr(models.DefaultIsExpand),
SkipIfEmpty: pointers.NewBoolPtr(models.DefaultSkipIfEmpty),
},
}
require.Equal(t, nil, removeDefaults(&env))
opts, err := env.GetOptions()
require.Equal(t, nil, err)
require.NotEqual(t, (*string)(nil), opts.Title)
require.Equal(t, "test_title", *opts.Title)
require.NotEqual(t, (*bool)(nil), opts.IsTemplate)
require.Equal(t, !models.DefaultIsTemplate, *opts.IsTemplate)
require.Equal(t, (*string)(nil), opts.Description)
require.Equal(t, (*string)(nil), opts.Summary)
require.Equal(t, 0, len(opts.ValueOptions))
require.Equal(t, (*bool)(nil), opts.IsRequired)
require.Equal(t, (*bool)(nil), opts.IsDontChangeValue)
require.Equal(t, (*bool)(nil), opts.IsExpand)
require.Equal(t, (*bool)(nil), opts.SkipIfEmpty)
}
开发者ID:fbernardo,项目名称:envman,代码行数:37,代码来源:util_test.go
示例12: TestMergeEnvironmentWith
func TestMergeEnvironmentWith(t *testing.T) {
diffEnv := envmanModels.EnvironmentItemModel{
"test_key": "test_value",
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr("test_title"),
Description: pointers.NewStringPtr("test_description"),
Summary: pointers.NewStringPtr("test_summary"),
ValueOptions: []string{"test_valu_options1", "test_valu_options2"},
IsRequired: pointers.NewBoolPtr(true),
IsExpand: pointers.NewBoolPtr(false),
IsDontChangeValue: pointers.NewBoolPtr(true),
IsTemplate: pointers.NewBoolPtr(true),
},
}
t.Log("Different keys")
{
env := envmanModels.EnvironmentItemModel{
"test_key1": "test_value",
}
require.Error(t, MergeEnvironmentWith(&env, diffEnv))
}
t.Log("Normal merge")
{
env := envmanModels.EnvironmentItemModel{
"test_key": "test_value",
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
SkipIfEmpty: pointers.NewBoolPtr(true),
Category: pointers.NewStringPtr("test"),
},
}
require.NoError(t, MergeEnvironmentWith(&env, diffEnv))
options, err := env.GetOptions()
require.NoError(t, err)
diffOptions, err := diffEnv.GetOptions()
require.NoError(t, err)
require.Equal(t, *diffOptions.Title, *options.Title)
require.Equal(t, *diffOptions.Description, *options.Description)
require.Equal(t, *diffOptions.Summary, *options.Summary)
require.Equal(t, len(diffOptions.ValueOptions), len(options.ValueOptions))
require.Equal(t, *diffOptions.IsRequired, *options.IsRequired)
require.Equal(t, *diffOptions.IsExpand, *options.IsExpand)
require.Equal(t, *diffOptions.IsDontChangeValue, *options.IsDontChangeValue)
require.Equal(t, *diffOptions.IsTemplate, *options.IsTemplate)
require.Equal(t, true, *options.SkipIfEmpty)
require.Equal(t, "test", *options.Category)
}
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:53,代码来源:models_methods_test.go
示例13: ValidateStepInputOutputModel
// ValidateStepInputOutputModel ...
func ValidateStepInputOutputModel(env envmanModels.EnvironmentItemModel, checkRequiredFields bool) error {
key, _, err := env.GetKeyValuePair()
if err != nil {
return fmt.Errorf("Invalid environment (%s), err: %s", key, err)
}
if err := env.Validate(); err != nil {
return fmt.Errorf("Invalid environment (%s), err: %s", key, err)
}
if checkRequiredFields {
options, err := env.GetOptions()
if err != nil {
return fmt.Errorf("Invalid environment (%s), err: %s", key, err)
}
if options.Title == nil || *options.Title == "" {
return fmt.Errorf("Invalid environment (%s), err: missing or empty title", key)
}
}
return nil
}
开发者ID:birmacher,项目名称:bitrise,代码行数:24,代码来源:models_methods.go
示例14: TestUpdateOrAddToEnvlist
func TestUpdateOrAddToEnvlist(t *testing.T) {
env1 := models.EnvironmentItemModel{
"test_key1": "test_value1",
}
require.Equal(t, nil, env1.FillMissingDefaults())
env2 := models.EnvironmentItemModel{
"test_key2": "test_value2",
}
require.Equal(t, nil, env2.FillMissingDefaults())
// Should add to list, but not override
oldEnvSlice := []models.EnvironmentItemModel{env1, env2}
newEnvSlice, err := UpdateOrAddToEnvlist(oldEnvSlice, env1, false)
require.Equal(t, nil, err)
env1Cnt, err := countOfEnvKeyInEnvSlice(env1, newEnvSlice)
require.Equal(t, nil, err)
require.Equal(t, 2, env1Cnt)
env2Cnt, err := countOfEnvKeyInEnvSlice(env2, newEnvSlice)
require.Equal(t, nil, err)
require.Equal(t, 1, env2Cnt)
// Should update list
oldEnvSlice = []models.EnvironmentItemModel{env1, env2}
newEnvSlice, err = UpdateOrAddToEnvlist(oldEnvSlice, env1, true)
require.Equal(t, nil, err)
env1Cnt, err = countOfEnvKeyInEnvSlice(env1, newEnvSlice)
require.Equal(t, nil, err)
require.Equal(t, 1, env1Cnt)
env2Cnt, err = countOfEnvKeyInEnvSlice(env2, newEnvSlice)
require.Equal(t, nil, err)
require.Equal(t, 1, env2Cnt)
}
开发者ID:fbernardo,项目名称:envman,代码行数:37,代码来源:util_test.go
示例15: TestCommandEnvs
func TestCommandEnvs(t *testing.T) {
t.Log("commandEnvs test")
{
env1 := models.EnvironmentItemModel{
"test_key1": "test_value1",
}
require.Equal(t, nil, env1.FillMissingDefaults())
env2 := models.EnvironmentItemModel{
"test_key2": "test_value2",
}
require.Equal(t, nil, env2.FillMissingDefaults())
envs := []models.EnvironmentItemModel{env1, env2}
sessionEnvs, err := commandEnvs(envs)
require.Equal(t, nil, err)
env1Found := false
env2Found := false
for _, envString := range sessionEnvs {
comp := strings.Split(envString, "=")
key := comp[0]
value := comp[1]
envKey1, envValue1, err := env1.GetKeyValuePair()
require.Equal(t, nil, err)
envKey2, envValue2, err := env2.GetKeyValuePair()
require.Equal(t, nil, err)
if key == envKey1 && value == envValue1 {
env1Found = true
}
if key == envKey2 && value == envValue2 {
env2Found = true
}
}
require.Equal(t, true, env1Found)
require.Equal(t, true, env2Found)
}
// Test skip_if_empty
t.Log("skip_if_empty=false && value=empty => should add")
{
env1 := models.EnvironmentItemModel{
"test_key3": "",
}
require.Equal(t, nil, env1.FillMissingDefaults())
env2 := models.EnvironmentItemModel{
"test_key4": "test_value4",
}
require.Equal(t, nil, env2.FillMissingDefaults())
envs := []models.EnvironmentItemModel{env1, env2}
sessionEnvs, err := commandEnvs(envs)
require.Equal(t, nil, err)
env1Found := false
env2Found := false
for _, envString := range sessionEnvs {
comp := strings.Split(envString, "=")
key := comp[0]
value := comp[1]
envKey1, envValue1, err := env1.GetKeyValuePair()
require.Equal(t, nil, err)
envKey2, envValue2, err := env2.GetKeyValuePair()
require.Equal(t, nil, err)
if key == envKey1 && value == envValue1 {
env1Found = true
}
if key == envKey2 && value == envValue2 {
env2Found = true
}
}
require.Equal(t, true, env1Found)
require.Equal(t, true, env2Found)
}
t.Log("skip_if_empty=true && value=empty => should NOT add")
{
env1 := models.EnvironmentItemModel{
"test_key5": "",
"opts": models.EnvironmentItemOptionsModel{
SkipIfEmpty: pointers.NewBoolPtr(true),
},
}
require.Equal(t, nil, env1.FillMissingDefaults())
env2 := models.EnvironmentItemModel{
"test_key6": "test_value6",
}
require.Equal(t, nil, env2.FillMissingDefaults())
envs := []models.EnvironmentItemModel{env1, env2}
//.........这里部分代码省略.........
开发者ID:viktorbenei,项目名称:envman,代码行数:101,代码来源:run_test.go
示例16: TestRemoveEnvironmentRedundantFields
func TestRemoveEnvironmentRedundantFields(t *testing.T) {
t.Log("Trivial remove - all fields should be default value")
{
env := envmanModels.EnvironmentItemModel{
"TEST_KEY": "test_value",
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(""),
Description: pointers.NewStringPtr(""),
Summary: pointers.NewStringPtr(""),
ValueOptions: []string{},
IsRequired: pointers.NewBoolPtr(envmanModels.DefaultIsRequired),
IsExpand: pointers.NewBoolPtr(envmanModels.DefaultIsExpand),
IsDontChangeValue: pointers.NewBoolPtr(envmanModels.DefaultIsDontChangeValue),
IsTemplate: pointers.NewBoolPtr(envmanModels.DefaultIsTemplate),
},
}
require.NoError(t, removeEnvironmentRedundantFields(&env))
options, err := env.GetOptions()
require.NoError(t, err)
require.Equal(t, (*string)(nil), options.Title)
require.Equal(t, (*string)(nil), options.Description)
require.Equal(t, (*string)(nil), options.Summary)
require.Equal(t, 0, len(options.ValueOptions))
require.Equal(t, (*bool)(nil), options.IsRequired)
require.Equal(t, (*bool)(nil), options.IsExpand)
require.Equal(t, (*bool)(nil), options.IsDontChangeValue)
require.Equal(t, (*bool)(nil), options.IsTemplate)
}
t.Log("Trivial don't remove - no fields should be default value")
{
env := envmanModels.EnvironmentItemModel{
"TEST_KEY": "test_value",
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr("t"),
Description: pointers.NewStringPtr("d"),
Summary: pointers.NewStringPtr("s"),
ValueOptions: []string{"i"},
IsRequired: pointers.NewBoolPtr(true),
IsExpand: pointers.NewBoolPtr(false),
IsDontChangeValue: pointers.NewBoolPtr(true),
IsTemplate: pointers.NewBoolPtr(true),
},
}
require.NoError(t, removeEnvironmentRedundantFields(&env))
options, err := env.GetOptions()
require.NoError(t, err)
require.Equal(t, "t", *options.Title)
require.Equal(t, "d", *options.Description)
require.Equal(t, "s", *options.Summary)
require.Equal(t, "i", options.ValueOptions[0])
require.Equal(t, true, *options.IsRequired)
require.Equal(t, false, *options.IsExpand)
require.Equal(t, true, *options.IsDontChangeValue)
require.Equal(t, true, *options.IsTemplate)
}
t.Log("No options - opts field shouldn't exist")
{
env := envmanModels.EnvironmentItemModel{
"TEST_KEY": "test_value",
}
require.NoError(t, removeEnvironmentRedundantFields(&env))
_, ok := env[envmanModels.OptionsKey]
require.Equal(t, false, ok)
}
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:72,代码来源:models_methods_test.go
示例17: TestUpdateOrAddToEnvlist
func TestUpdateOrAddToEnvlist(t *testing.T) {
env1 := models.EnvironmentItemModel{
"test_key1": "test_value1",
}
err := env1.FillMissingDefaults()
if err != nil {
t.Fatal(err)
}
env2 := models.EnvironmentItemModel{
"test_key2": "test_value2",
}
err = env2.FillMissingDefaults()
if err != nil {
t.Fatal(err)
}
// Should add to list, but not override
oldEnvSlice := []models.EnvironmentItemModel{env1, env2}
newEnvSlice, err := UpdateOrAddToEnvlist(oldEnvSlice, env1, false)
if err != nil {
t.Fatal(err)
}
env1Cnt, err := countOfEnvKeyInEnvSlice(env1, newEnvSlice)
if err != nil {
t.Fatal(err)
}
if env1Cnt != 2 {
t.Fatalf("Failed to proper add env, %d x (test_key1)", env1Cnt)
}
env2Cnt, err := countOfEnvKeyInEnvSlice(env2, newEnvSlice)
if err != nil {
t.Fatal(err)
}
if env2Cnt != 1 {
t.Fatalf("Failed to proper add env, %d x (test_key2)", env2Cnt)
}
// Should update list
oldEnvSlice = []models.EnvironmentItemModel{env1, env2}
newEnvSlice, err = UpdateOrAddToEnvlist(oldEnvSlice, env1, true)
if err != nil {
t.Fatal(err)
}
env1Cnt, err = countOfEnvKeyInEnvSlice(env1, newEnvSlice)
if err != nil {
t.Fatal(err)
}
if env1Cnt != 1 {
t.Fatalf("Failed to proper add env, %d x (test_key1)", env1Cnt)
}
env2Cnt, err = countOfEnvKeyInEnvSlice(env2, newEnvSlice)
if err != nil {
t.Fatal(err)
}
if env2Cnt != 1 {
t.Fatalf("Failed to proper add env, %d x (test_key2)", env2Cnt)
}
}
开发者ID:bazscsa,项目名称:envman,代码行数:63,代码来源:util_test.go
示例18: TestMergeEnvironmentWith
func TestMergeEnvironmentWith(t *testing.T) {
// Different keys
diffEnv := envmanModels.EnvironmentItemModel{
testKey: testValue,
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(testTitle),
Description: pointers.NewStringPtr(testDescription),
Summary: pointers.NewStringPtr(testSummary),
ValueOptions: testValueOptions,
IsRequired: pointers.NewBoolPtr(testTrue),
IsExpand: pointers.NewBoolPtr(testFalse),
IsDontChangeValue: pointers.NewBoolPtr(testTrue),
},
}
env := envmanModels.EnvironmentItemModel{
testKey1: testValue,
}
err := MergeEnvironmentWith(&env, diffEnv)
if err == nil {
t.Fatal("Different keys, should case of error")
}
// Normal merge
env = envmanModels.EnvironmentItemModel{
testKey: testValue,
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{},
}
err = MergeEnvironmentWith(&env, diffEnv)
if err != nil {
t.Fatal(err)
}
options, err := env.GetOptions()
if err != nil {
t.Fatal(err)
}
diffOptions, err := diffEnv.GetOptions()
if err != nil {
t.Fatal(err)
}
if *options.Title != *diffOptions.Title {
t.Fatal("Failed to merge Title")
}
if *options.Description != *diffOptions.Description {
t.Fatal("Failed to merge Description")
}
if *options.Summary != *diffOptions.Summary {
t.Fatal("Failed to merge Summary")
}
if len(options.ValueOptions) != len(diffOptions.ValueOptions) {
t.Fatal("Failed to merge ValueOptions")
}
if *options.IsRequired != *diffOptions.IsRequired {
t.Fatal("Failed to merge IsRequired")
}
if *options.IsExpand != *diffOptions.IsExpand {
t.Fatal("Failed to merge IsExpand")
}
if *options.IsDontChangeValue != *diffOptions.IsDontChangeValue {
t.Fatal("Failed to merge IsDontChangeValue")
}
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:66,代码来源:models_methods_test.go
示例19: TestRemoveEnvironmentRedundantFields
func TestRemoveEnvironmentRedundantFields(t *testing.T) {
// Trivial remove - all fields should be default value
env := envmanModels.EnvironmentItemModel{
"TEST_KEY": "test_value",
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(""),
Description: pointers.NewStringPtr(""),
Summary: pointers.NewStringPtr(""),
ValueOptions: []string{},
IsRequired: pointers.NewBoolPtr(envmanModels.DefaultIsRequired),
IsExpand: pointers.NewBoolPtr(envmanModels.DefaultIsExpand),
IsDontChangeValue: pointers.NewBoolPtr(envmanModels.DefaultIsDontChangeValue),
},
}
if err := removeEnvironmentRedundantFields(&env); err != nil {
t.Fatal("Failed to remove redundant fields:", err)
}
options, err := env.GetOptions()
if err != nil {
t.Fatal("Failed to get env options:", err)
}
if options.Title != nil {
t.Fatal("options.Title should be nil")
}
if options.Description != nil {
t.Fatal("options.Description should be nil")
}
if options.Summary != nil {
t.Fatal("options.Summary should be nil")
}
if len(options.ValueOptions) != 0 {
t.Fatal("options.ValueOptions should be empty")
}
if options.IsRequired != nil {
t.Fatal("options.IsRequired should be nil")
}
if options.IsExpand != nil {
t.Fatal("options.IsExpand should be nil")
}
if options.IsDontChangeValue != nil {
t.Fatal("options.IsDontChangeValue should be nil")
}
// Trivial don't remove - no fields should be default value
env = envmanModels.EnvironmentItemModel{
"TEST_KEY": "test_value",
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr("t"),
Description: pointers.NewStringPtr("d"),
Summary: pointers.NewStringPtr("s"),
ValueOptions: []string{"i"},
IsRequired: pointers.NewBoolPtr(true),
IsExpand: pointers.NewBoolPtr(false),
IsDontChangeValue: pointers.NewBoolPtr(true),
},
}
if err := removeEnvironmentRedundantFields(&env); err != nil {
t.Fatal("Failed to remove redundant fields:", err)
}
options, err = env.GetOptions()
if err != nil {
t.Fatal("Failed to get env options:", err)
}
if *options.Title != "t" {
t.Fatal("options.Title should be: t")
}
if *options.Description != "d" {
t.Fatal("options.Description should be: d")
}
if *options.Summary != "s" {
t.Fatal("options.Summary should be: s")
}
if options.ValueOptions[0] != "i" {
t.Fatal("options.ValueOptions should be: {i}")
}
if *options.IsRequired != true {
t.Fatal("options.IsRequired should be: false")
}
if *options.IsExpand != false {
t.Fatal("options.IsExpand should be: false")
}
if *options.IsDontChangeValue != true {
t.Fatal("options.IsDontChangeValue should be: true")
}
// No options - opts field shouldn't exist
env = envmanModels.EnvironmentItemModel{
"TEST_KEY": "test_value",
}
if err := removeEnvironmentRedundantFields(&env); err != nil {
t.Fatal("Failed to remove redundant fields:", err)
}
//.........这里部分代码省略.........
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:101,代码来源:models_methods_test.go
示例20: UpdateOrAddToEnvlist
// UpdateOrAddToEnvlist ...
func UpdateOrAddToEnvlist(oldEnvSlice []models.EnvironmentItemModel, newEnv models.EnvironmentItemModel, replace bool) ([]models.EnvironmentItemModel, error) {
newKey, _, err := newEnv.GetKeyValuePair()
if err != nil {
return []models.EnvironmentItemModel{}, err
}
var newEnvs []models.EnvironmentItemModel
exist := false
if replace {
match := 0
for _, env := range oldEnvSlice {
key, _, err := env.GetKeyValuePair()
if err != nil {
return []models.EnvironmentItemModel{}, err
}
if key == newKey {
match = match + 1
}
}
if match > 1 {
if ToolMode {
return []models.EnvironmentItemModel{}, errors.New("More then one env exist with key '" + newKey + "'")
}
msg := " More then one env exist with key '" + newKey + "' replace all/append ['replace/append'] ?"
answer, err := goinp.AskForString(msg)
if err != nil {
return []models.EnvironmentItemModel{}, err
}
switch answer {
case "replace":
break
case "append":
replace = false
break
default:
return []models.EnvironmentItemModel{}, errors.New("Failed to parse answer: '" + answer + "' use ['replace/append']!")
}
}
}
for _, env := range oldEnvSlice {
key, _, err := env.GetKeyValuePair()
if err != nil {
return []models.EnvironmentItemModel{}, err
}
if replace && key == newKey {
exist = true
newEnvs = append(newEnvs, newEnv)
} else {
newEnvs = append(newEnvs, env)
}
}
if !exist {
newEnvs = append(newEnvs, newEnv)
}
return newEnvs, nil
}
开发者ID:bazscsa,项目名称:envman,代码行数:64,代码来源:util.go
注:本文中的github.com/bitrise-io/envman/models.EnvironmentItemModel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论