当前位置: 首页>>代码示例>>Golang>>正文


Golang EnvironmentItemModel.GetOptions方法代码示例

本文整理汇总了Golang中github.com/bitrise-io/envman/models.EnvironmentItemModel.GetOptions方法的典型用法代码示例。如果您正苦于以下问题:Golang EnvironmentItemModel.GetOptions方法的具体用法?Golang EnvironmentItemModel.GetOptions怎么用?Golang EnvironmentItemModel.GetOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/bitrise-io/envman/models.EnvironmentItemModel的用法示例。


在下文中一共展示了EnvironmentItemModel.GetOptions方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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


注:本文中的github.com/bitrise-io/envman/models.EnvironmentItemModel.GetOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。