本文整理汇总了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
}
示例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)
}
示例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)
}
}
示例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}
//.........这里部分代码省略.........