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


Golang EnvironmentItemModel.FillMissingDefaults方法代码示例

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


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

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

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

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

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


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