本文整理汇总了Golang中github.com/bitrise-io/go-utils/pointers.NewBoolPtr函数的典型用法代码示例。如果您正苦于以下问题:Golang NewBoolPtr函数的具体用法?Golang NewBoolPtr怎么用?Golang NewBoolPtr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewBoolPtr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestValidate
func TestValidate(t *testing.T) {
// No key-value
env := EnvironmentItemModel{
OptionsKey: EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr("test_title"),
Description: pointers.NewStringPtr("test_description"),
Summary: pointers.NewStringPtr("test_summary"),
ValueOptions: []string{"test_key2", "test_value2"},
IsRequired: pointers.NewBoolPtr(true),
IsExpand: pointers.NewBoolPtr(true),
IsDontChangeValue: pointers.NewBoolPtr(false),
},
}
require.NotEqual(t, nil, env.Validate())
// Empty key
env = EnvironmentItemModel{
"": "test_value",
}
require.NotEqual(t, nil, env.Validate())
// Valid env
env = EnvironmentItemModel{
"test_key": "test_value",
}
require.Equal(t, nil, env.Validate())
}
开发者ID:fbernardo,项目名称:envman,代码行数:27,代码来源:models_methods_test.go
示例2: Convert
// Convert ...
func (oldStep StepModel) Convert() (stepmanModels.StepModel, error) {
inputs, err := oldStep.getInputEnvironments()
if err != nil {
return stepmanModels.StepModel{}, err
}
outputs, err := oldStep.getOutputEnvironments()
if err != nil {
return stepmanModels.StepModel{}, err
}
newStep := stepmanModels.StepModel{
Title: pointers.NewStringPtr(oldStep.Name),
Description: pointers.NewStringPtr(oldStep.Description),
Website: pointers.NewStringPtr(oldStep.Website),
Source: oldStep.getSource(),
HostOsTags: oldStep.HostOsTags,
ProjectTypeTags: oldStep.ProjectTypeTags,
TypeTags: oldStep.TypeTags,
IsRequiresAdminUser: pointers.NewBoolPtr(oldStep.IsRequiresAdminUser),
IsAlwaysRun: pointers.NewBoolPtr(oldStep.IsAlwaysRun),
Inputs: inputs,
Outputs: outputs,
}
return newStep, nil
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:28,代码来源:methods.go
示例3: FillMissingDefaults
// FillMissingDefaults ...
func (env *EnvironmentItemModel) FillMissingDefaults() error {
options, err := env.GetOptions()
if err != nil {
return err
}
if options.Title == nil {
options.Title = pointers.NewStringPtr("")
}
if options.Description == nil {
options.Description = pointers.NewStringPtr("")
}
if options.Summary == nil {
options.Summary = pointers.NewStringPtr("")
}
if options.IsRequired == nil {
options.IsRequired = pointers.NewBoolPtr(DefaultIsRequired)
}
if options.IsExpand == nil {
options.IsExpand = pointers.NewBoolPtr(DefaultIsExpand)
}
if options.IsDontChangeValue == nil {
options.IsDontChangeValue = pointers.NewBoolPtr(DefaultIsDontChangeValue)
}
(*env)[OptionsKey] = options
return nil
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:27,代码来源:models_methods.go
示例4: getOptions
func (input InputModel) getOptions() envmanModels.EnvironmentItemOptionsModel {
return envmanModels.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(input.Title),
Description: pointers.NewStringPtr(input.Description),
ValueOptions: input.ValueOptions,
IsRequired: pointers.NewBoolPtr(input.IsRequired),
IsExpand: pointers.NewBoolPtr(input.IsExpand),
IsDontChangeValue: pointers.NewBoolPtr(input.IsDontChangeValue),
}
}
开发者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: TestValidateStepInputOutputModel
func TestValidateStepInputOutputModel(t *testing.T) {
// Filled env
env := 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_key2", "test_value2"},
IsRequired: pointers.NewBoolPtr(true),
IsExpand: pointers.NewBoolPtr(false),
IsDontChangeValue: pointers.NewBoolPtr(true),
},
}
step := StepModel{
Inputs: []envmanModels.EnvironmentItemModel{env},
}
require.NoError(t, step.ValidateInputAndOutputEnvs(true))
// Empty key
env = envmanModels.EnvironmentItemModel{
"": "test_value",
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr("test_title"),
Description: pointers.NewStringPtr("test_description"),
Summary: pointers.NewStringPtr("test_summary"),
ValueOptions: []string{"test_key2", "test_value2"},
IsRequired: pointers.NewBoolPtr(true),
IsExpand: pointers.NewBoolPtr(false),
IsDontChangeValue: pointers.NewBoolPtr(true),
},
}
step = StepModel{
Inputs: []envmanModels.EnvironmentItemModel{env},
}
require.Error(t, step.ValidateInputAndOutputEnvs(true))
// Title is empty
env = envmanModels.EnvironmentItemModel{
"test_key": "test_value",
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
Description: pointers.NewStringPtr("test_description"),
ValueOptions: []string{"test_key2", "test_value2"},
IsRequired: pointers.NewBoolPtr(true),
IsExpand: pointers.NewBoolPtr(false),
IsDontChangeValue: pointers.NewBoolPtr(true),
},
}
step = StepModel{
Inputs: []envmanModels.EnvironmentItemModel{env},
}
require.Error(t, step.ValidateInputAndOutputEnvs(true))
}
开发者ID:godrei,项目名称:stepman,代码行数:59,代码来源:models_methods_test.go
示例7: 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
示例8: TestValidateStepInputOutputModel
func TestValidateStepInputOutputModel(t *testing.T) {
// Filled env
env := 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),
},
}
err := ValidateStepInputOutputModel(env, true)
if err != nil {
t.Fatal(err)
}
// Empty key
env = envmanModels.EnvironmentItemModel{
"": 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),
},
}
err = ValidateStepInputOutputModel(env, true)
if err == nil {
t.Fatal("Empty key, should fail")
}
// Title is empty
env = envmanModels.EnvironmentItemModel{
testKey: testValue,
envmanModels.OptionsKey: envmanModels.EnvironmentItemOptionsModel{
Description: pointers.NewStringPtr(testDescription),
ValueOptions: testValueOptions,
IsRequired: pointers.NewBoolPtr(testTrue),
IsExpand: pointers.NewBoolPtr(testFalse),
IsDontChangeValue: pointers.NewBoolPtr(testTrue),
},
}
err = ValidateStepInputOutputModel(env, true)
if err == nil {
t.Fatal("Empty Title, should fail")
}
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:56,代码来源:models_methods_test.go
示例9: FillMissingDefaults
// FillMissingDefaults ...
func (step *StepModel) FillMissingDefaults() error {
if step.Title == nil {
step.Title = pointers.NewStringPtr("")
}
if step.Description == nil {
step.Description = pointers.NewStringPtr("")
}
if step.Summary == nil {
step.Summary = pointers.NewStringPtr("")
}
if step.Website == nil {
step.Website = pointers.NewStringPtr("")
}
if step.SourceCodeURL == nil {
step.SourceCodeURL = pointers.NewStringPtr("")
}
if step.SupportURL == nil {
step.SupportURL = pointers.NewStringPtr("")
}
if step.IsRequiresAdminUser == nil {
step.IsRequiresAdminUser = pointers.NewBoolPtr(DefaultIsRequiresAdminUser)
}
if step.IsAlwaysRun == nil {
step.IsAlwaysRun = pointers.NewBoolPtr(DefaultIsAlwaysRun)
}
if step.IsSkippable == nil {
step.IsSkippable = pointers.NewBoolPtr(DefaultIsSkippable)
}
if step.RunIf == nil {
step.RunIf = pointers.NewStringPtr("")
}
if step.Timeout == nil {
step.Timeout = pointers.NewIntPtr(DefaultTimeout)
}
for _, input := range step.Inputs {
err := input.FillMissingDefaults()
if err != nil {
return err
}
}
for _, output := range step.Outputs {
err := output.FillMissingDefaults()
if err != nil {
return err
}
}
return nil
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:50,代码来源:models_methods.go
示例10: CastToBoolPtr
// CastToBoolPtr ...
func CastToBoolPtr(value interface{}) (*bool, bool) {
castedValue, ok := CastToBool(value)
if !ok {
return nil, false
}
return pointers.NewBoolPtr(castedValue), true
}
开发者ID:fbernardo,项目名称:envman,代码行数:8,代码来源:parseutil.go
示例11: 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
示例12: TestGetLatestStepVersion
func TestGetLatestStepVersion(t *testing.T) {
defaultIsRequiresAdminUser := DefaultIsRequiresAdminUser
step := StepModel{
Title: pointers.NewStringPtr("name 1"),
Description: pointers.NewStringPtr("desc 1"),
Website: pointers.NewStringPtr("web/1"),
SourceCodeURL: pointers.NewStringPtr("fork/1"),
Source: StepSourceModel{
Git: "https://git.url",
},
HostOsTags: []string{"osx"},
ProjectTypeTags: []string{"ios"},
TypeTags: []string{"test"},
IsRequiresAdminUser: pointers.NewBoolPtr(defaultIsRequiresAdminUser),
Inputs: []envmanModels.EnvironmentItemModel{
envmanModels.EnvironmentItemModel{
"KEY_1": "Value 1",
},
envmanModels.EnvironmentItemModel{
"KEY_2": "Value 2",
},
},
Outputs: []envmanModels.EnvironmentItemModel{
envmanModels.EnvironmentItemModel{
"KEY_3": "Value 3",
},
},
}
collection := StepCollectionModel{
FormatVersion: "1.0.0",
GeneratedAtTimeStamp: 0,
Steps: StepHash{
"step": StepGroupModel{
Versions: map[string]StepModel{
"1.0.0": step,
"2.0.0": step,
},
LatestVersionNumber: "2.0.0",
},
},
SteplibSource: "source",
DownloadLocations: []DownloadLocationModel{
DownloadLocationModel{
Type: "zip",
Src: "amazon/",
},
DownloadLocationModel{
Type: "git",
Src: "step.git",
},
},
}
latest, err := collection.GetLatestStepVersion("step")
require.Equal(t, nil, err)
require.Equal(t, "2.0.0", latest)
}
开发者ID:godrei,项目名称:stepman,代码行数:59,代码来源:models_methods_test.go
示例13: TestGetStep
func TestGetStep(t *testing.T) {
defaultIsRequiresAdminUser := DefaultIsRequiresAdminUser
step := StepModel{
Title: pointers.NewStringPtr(title),
Description: pointers.NewStringPtr(desc),
Website: pointers.NewStringPtr(website),
SourceCodeURL: pointers.NewStringPtr(fork),
Source: StepSourceModel{
Git: git,
},
HostOsTags: []string{"osx"},
ProjectTypeTags: []string{"ios"},
TypeTags: []string{"test"},
IsRequiresAdminUser: pointers.NewBoolPtr(defaultIsRequiresAdminUser),
Inputs: []envmanModels.EnvironmentItemModel{
envmanModels.EnvironmentItemModel{
"KEY_1": "Value 1",
},
envmanModels.EnvironmentItemModel{
"KEY_2": "Value 2",
},
},
Outputs: []envmanModels.EnvironmentItemModel{
envmanModels.EnvironmentItemModel{
"KEY_3": "Value 3",
},
},
}
collection := StepCollectionModel{
FormatVersion: "1.0.0",
GeneratedAtTimeStamp: 0,
Steps: StepHash{
"step": StepGroupModel{
Versions: map[string]StepModel{
"1.0.0": step,
},
},
},
SteplibSource: "source",
DownloadLocations: []DownloadLocationModel{
DownloadLocationModel{
Type: "zip",
Src: "amazon/",
},
DownloadLocationModel{
Type: "git",
Src: "step.git",
},
},
}
step, found := collection.GetStep("step", "1.0.0")
if !found {
t.Fatal("Step not found (step) (1.0.0)")
}
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:58,代码来源:models_methods_test.go
示例14: convertStepsInputs
//
// Converted inputs should:
// * contain all spec inputs
// * keep all original input value (except empty value: "")
// * keep original IsExpand value
//
// originalInputs: readed from StepLib
// diffInputs: readed from workflow to convert
//
func convertStepsInputs(originalInputs, diffInputs []envmanModels.EnvironmentItemModel, conversionMap map[string]string) ([]envmanModels.EnvironmentItemModel, error) {
convertedInputs := []envmanModels.EnvironmentItemModel{}
for _, originalInput := range originalInputs {
originalInputKey, originalInputValue, err := originalInput.GetKeyValuePair()
if err != nil {
return []envmanModels.EnvironmentItemModel{}, err
}
originalInputOptions, err := originalInput.GetOptions()
if err != nil {
return []envmanModels.EnvironmentItemModel{}, err
}
conversionInputKey, found := conversionMap[originalInputKey]
if found == false {
convertedInputs = append(convertedInputs, originalInput)
continue
}
diffInput, found, err := GetInputByKey(diffInputs, conversionInputKey)
if err != nil {
return []envmanModels.EnvironmentItemModel{}, err
}
if !found {
convertedInputs = append(convertedInputs, originalInput)
continue
}
_, diffInputValue, err := diffInput.GetKeyValuePair()
if err != nil {
return []envmanModels.EnvironmentItemModel{}, err
}
if diffInputValue == "" {
diffInputValue = originalInputValue
}
diffInputOptions, err := diffInput.GetOptions()
if err != nil {
return []envmanModels.EnvironmentItemModel{}, err
}
if diffInputOptions.IsExpand != nil {
originalInputOptions.IsExpand = pointers.NewBoolPtr(*diffInputOptions.IsExpand)
}
convertedInput := envmanModels.EnvironmentItemModel{
originalInputKey: diffInputValue,
envmanModels.OptionsKey: originalInputOptions,
}
convertedInputs = append(convertedInputs, convertedInput)
}
return convertedInputs, nil
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:65,代码来源:step_converter.go
示例15: 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
示例16: 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
示例17: 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
示例18: TestValidate
func TestValidate(t *testing.T) {
// No key-value
env := EnvironmentItemModel{
OptionsKey: EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(testTitle),
Description: pointers.NewStringPtr(testDescription),
Summary: pointers.NewStringPtr(testSummary),
ValueOptions: testValueOptions,
IsRequired: pointers.NewBoolPtr(testTrue),
IsExpand: pointers.NewBoolPtr(testTrue),
IsDontChangeValue: pointers.NewBoolPtr(testFalse),
},
}
err := env.Validate()
if err == nil {
t.Fatal("Should be invalid env, no key-value")
}
// Empty key
env = EnvironmentItemModel{
"": testValue,
}
err = env.Validate()
if err == nil {
t.Fatal("Should be invalid env, no empty key")
}
// Valid env
env = EnvironmentItemModel{
testKey: testValue,
}
err = env.Validate()
if err != nil {
t.Fatal(err)
}
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:36,代码来源:models_methods_test.go
示例19: TestParseFromInterfaceMap
func TestParseFromInterfaceMap(t *testing.T) {
envOptions := EnvironmentItemOptionsModel{}
model := map[string]interface{}{}
// Normal
model["title"] = "test_title"
model["value_options"] = []string{"test_key2", "test_value2"}
model["is_expand"] = true
require.Equal(t, nil, envOptions.ParseFromInterfaceMap(model))
// title is not a string
model = map[string]interface{}{}
model["title"] = true
require.Equal(t, nil, envOptions.ParseFromInterfaceMap(model))
// value_options is not a string slice
model = map[string]interface{}{}
model["value_options"] = []interface{}{true, false}
require.Equal(t, nil, envOptions.ParseFromInterfaceMap(model))
// is_required is not a bool
model = map[string]interface{}{}
model["is_required"] = pointers.NewBoolPtr(true)
require.NotEqual(t, nil, envOptions.ParseFromInterfaceMap(model))
model = map[string]interface{}{}
model["is_required"] = "YeS"
require.Equal(t, nil, envOptions.ParseFromInterfaceMap(model))
model = map[string]interface{}{}
model["is_required"] = "NO"
require.Equal(t, nil, envOptions.ParseFromInterfaceMap(model))
model = map[string]interface{}{}
model["is_required"] = "y"
require.Equal(t, nil, envOptions.ParseFromInterfaceMap(model))
model = map[string]interface{}{}
model["skip_if_empty"] = "true"
require.Equal(t, nil, envOptions.ParseFromInterfaceMap(model))
// other_key is not supported key
model = map[string]interface{}{}
model["other_key"] = true
require.NotEqual(t, nil, envOptions.ParseFromInterfaceMap(model))
}
开发者ID:fbernardo,项目名称:envman,代码行数:46,代码来源:models_methods_test.go
示例20: TestParseFromInterfaceMap
func TestParseFromInterfaceMap(t *testing.T) {
envOptions := EnvironmentItemOptionsModel{}
model := map[string]interface{}{}
// Normal
model["title"] = testTitle
model["value_options"] = testValueOptions
model["is_expand"] = testTrue
err := envOptions.ParseFromInterfaceMap(model)
if err != nil {
t.Fatal(err)
}
// title is not a string
model = map[string]interface{}{}
model["title"] = true
err = envOptions.ParseFromInterfaceMap(model)
if err == nil {
t.Fatal("Title value is not a string, should be error")
}
// value_options is not a string slice
model = map[string]interface{}{}
model["value_options"] = []interface{}{true, false}
err = envOptions.ParseFromInterfaceMap(model)
if err == nil {
t.Fatal("value_options is not a string slice, should be error")
}
// is_required is not a bool
model = map[string]interface{}{}
model["is_required"] = pointers.NewBoolPtr(testTrue)
err = envOptions.ParseFromInterfaceMap(model)
if err == nil {
t.Fatal("is_required is not a bool, should be error")
}
// other_key is not supported key
model = map[string]interface{}{}
model["other_key"] = testTrue
err = envOptions.ParseFromInterfaceMap(model)
if err == nil {
t.Fatal("other_key is not a supported key, should be error")
}
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:45,代码来源:models_methods_test.go
注:本文中的github.com/bitrise-io/go-utils/pointers.NewBoolPtr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论