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


Golang pointers.NewStringPtr函数代码示例

本文整理汇总了Golang中github.com/bitrise-io/go-utils/pointers.NewStringPtr函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStringPtr函数的具体用法?Golang NewStringPtr怎么用?Golang NewStringPtr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewStringPtr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TestValidateStepCommitHash

// Test - Stepman audit step
// Checks if step Source.Commit meets the git commit hash of realese version
// 'auditStep(...)' calls 'cmdex.GitCloneTagOrBranchAndValidateCommitHash(...)', which method validates the commit hash
func TestValidateStepCommitHash(t *testing.T) {
	// Slack step - valid hash
	stepSlack := models.StepModel{
		Title:       pointers.NewStringPtr("hash_test"),
		Summary:     pointers.NewStringPtr("summary"),
		Website:     pointers.NewStringPtr("website"),
		PublishedAt: pointers.NewTimePtr(time.Date(2012, time.January, 1, 0, 0, 0, 0, time.UTC)),
		Source: &models.StepSourceModel{
			Git:    "https://github.com/bitrise-io/steps-slack-message.git",
			Commit: "756f39f76f94d525aaea2fc2d0c5a23799f8ec97",
		},
	}
	if err := auditStepModelBeforeSharePullRequest(stepSlack, "slack", "2.1.0"); err != nil {
		t.Fatal("Step audit failed:", err)
	}

	// Slack step - invalid hash
	stepSlack.Source.Commit = "should fail commit"
	if err := auditStepModelBeforeSharePullRequest(stepSlack, "slack", "2.1.0"); err == nil {
		t.Fatal("Step audit should fail")
	}

	// Slack step - empty hash
	stepSlack.Source.Commit = ""
	if err := auditStepModelBeforeSharePullRequest(stepSlack, "slack", "2.1.0"); err == nil {
		t.Fatal("Step audit should fail")
	}
}
开发者ID:bitrise-io,项目名称:stepman,代码行数:31,代码来源:audit_test.go

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

示例6: TestValidate

func TestValidate(t *testing.T) {
	step := StepModel{
		Title:       pointers.NewStringPtr("title"),
		Summary:     pointers.NewStringPtr("summary"),
		Website:     pointers.NewStringPtr("website"),
		PublishedAt: pointers.NewTimePtr(time.Date(2012, time.January, 1, 0, 0, 0, 0, time.UTC)),
		Source: &StepSourceModel{
			Git:    "https://github.com/bitrise-io/bitrise.git",
			Commit: "1e1482141079fc12def64d88cb7825b8f1cb1dc3",
		},
	}

	require.Equal(t, nil, step.Audit())

	step.Title = nil
	require.EqualError(t, step.Audit(), "Invalid step: missing or empty required 'title' property")

	step.Title = new(string)
	*step.Title = ""
	require.EqualError(t, step.Audit(), "Invalid step: missing or empty required 'title' property")
	*step.Title = "title"

	step.PublishedAt = nil
	require.NotEqual(t, nil, step.Audit())
	require.EqualError(t, step.Audit(), "Invalid step: missing or empty required 'PublishedAt' property")
	step.PublishedAt = new(time.Time)

	*step.PublishedAt = time.Time{}
	require.EqualError(t, step.Audit(), "Invalid step: missing or empty required 'PublishedAt' property")
	step.PublishedAt = pointers.NewTimePtr(time.Date(2012, time.January, 1, 0, 0, 0, 0, time.UTC))

	step.Website = nil
	require.EqualError(t, step.Audit(), "Invalid step: missing or empty required 'website' property")

	step.Website = new(string)
	*step.Website = ""
	require.EqualError(t, step.Audit(), "Invalid step: missing or empty required 'website' property")
	*step.Website = "website"

	step.Source.Git = ""
	require.EqualError(t, step.Audit(), "Invalid step: missing or empty required 'source.git' property")
	step.Source.Git = "git"

	step.Source.Git = "[email protected]:bitrise-io/bitrise.git"
	require.EqualError(t, step.Audit(), "Invalid step: step source should start with http:// or https://")

	step.Source.Git = "https://github.com/bitrise-io/bitrise"
	require.EqualError(t, step.Audit(), "Invalid step: step source should end with .git")
	step.Source.Git = "https://github.com/bitrise-io/bitrise.git"

	step.Source.Commit = ""
	require.EqualError(t, step.Audit(), "Invalid step: missing or empty required 'source.commit' property")
	step.Source.Commit = "1e1482141079fc12def64d88cb7825b8f1cb1dc3"

	step.Timeout = new(int)
	*step.Timeout = -1
	require.EqualError(t, step.Audit(), "Invalid step: timeout less then 0")
}
开发者ID:bitrise-io,项目名称:stepman,代码行数:58,代码来源:models_methods_test.go

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

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

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

示例10: TestValidate

func TestValidate(t *testing.T) {
	step := StepModel{
		Title:       pointers.NewStringPtr("title"),
		Summary:     pointers.NewStringPtr("summary"),
		Website:     pointers.NewStringPtr("website"),
		PublishedAt: pointers.NewTimePtr(time.Date(2012, time.January, 1, 0, 0, 0, 0, time.UTC)),
		Source: StepSourceModel{
			Git:    "https://github.com/bitrise-io/bitrise.git",
			Commit: "1e1482141079fc12def64d88cb7825b8f1cb1dc3",
		},
	}

	require.Equal(t, nil, step.Audit())

	step.Title = nil
	require.NotEqual(t, nil, step.Audit())

	step.Title = new(string)
	*step.Title = ""
	require.NotEqual(t, nil, step.Audit())

	step.PublishedAt = nil
	require.NotEqual(t, nil, step.Audit())
	step.PublishedAt = new(time.Time)

	*step.PublishedAt = time.Time{}
	require.NotEqual(t, nil, step.Audit())

	step.Description = nil
	require.NotEqual(t, nil, step.Audit())
	step.Description = new(string)

	*step.Description = ""
	require.NotEqual(t, nil, step.Audit())

	step.Website = nil
	require.NotEqual(t, nil, step.Audit())
	step.Website = new(string)

	*step.Website = ""
	require.NotEqual(t, nil, step.Audit())

	step.Source.Git = ""
	require.NotEqual(t, nil, step.Audit())

	step.Source.Git = "[email protected]:bitrise-io/bitrise.git"
	require.NotEqual(t, nil, step.Audit())

	step.Source.Git = "https://github.com/bitrise-io/bitrise"
	require.NotEqual(t, nil, step.Audit())

	step.Source.Commit = ""
	require.NotEqual(t, nil, step.Audit())
}
开发者ID:godrei,项目名称:stepman,代码行数:54,代码来源:models_methods_test.go

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

示例12: Test_serialize_StepModel

func Test_serialize_StepModel(t *testing.T) {
	t.Log("Empty")
	{
		step := StepModel{}

		// JSON
		{
			bytes, err := json.Marshal(step)
			require.NoError(t, err)
			require.Equal(t, `{}`, string(bytes))
		}

		// YAML
		{
			bytes, err := yaml.Marshal(step)
			require.NoError(t, err)
			require.Equal(t, `{}
`,
				string(bytes))
		}
	}

	t.Log("Toolkit")
	{
		step := StepModel{
			Title: pointers.NewStringPtr("Test Step"),
			Toolkit: &StepToolkitModel{
				Go: &GoStepToolkitModel{
					PackageName: "go/package",
				},
				Bash: &BashStepToolkitModel{
					EntryFile: "step.sh",
				},
			},
		}

		// JSON
		{
			bytes, err := json.Marshal(step)
			require.NoError(t, err)
			require.Equal(t, `{"title":"Test Step","toolkit":{"bash":{"entry_file":"step.sh"},"go":{"package_name":"go/package"}}}`, string(bytes))
		}

		// YAML
		{
			bytes, err := yaml.Marshal(step)
			require.NoError(t, err)
			require.Equal(t, `title: Test Step
toolkit:
  bash:
    entry_file: step.sh
  go:
    package_name: go/package
`,
				string(bytes))
		}
	}
}
开发者ID:bitrise-io,项目名称:stepman,代码行数:58,代码来源:models_test.go

示例13: TestFillMissingDefaults

func TestFillMissingDefaults(t *testing.T) {
	title := "name 1"
	// "desc 1" := ""desc 1" 1"
	website := "web/1"
	git := "https://git.url"
	// fork := "fork/1"

	step := StepModel{
		Title:   pointers.NewStringPtr(title),
		Website: pointers.NewStringPtr(website),
		Source: &StepSourceModel{
			Git: git,
		},
		HostOsTags:      []string{"osx"},
		ProjectTypeTags: []string{"ios"},
		TypeTags:        []string{"test"},
	}

	require.Equal(t, nil, step.FillMissingDefaults())

	if step.Description == nil || *step.Description != "" {
		t.Fatal("Description missing")
	}
	if step.SourceCodeURL == nil || *step.SourceCodeURL != "" {
		t.Fatal("SourceCodeURL missing")
	}
	if step.SupportURL == nil || *step.SupportURL != "" {
		t.Fatal("SourceCodeURL missing")
	}
	if step.IsRequiresAdminUser == nil || *step.IsRequiresAdminUser != DefaultIsRequiresAdminUser {
		t.Fatal("IsRequiresAdminUser missing")
	}
	if step.IsAlwaysRun == nil || *step.IsAlwaysRun != DefaultIsAlwaysRun {
		t.Fatal("IsAlwaysRun missing")
	}
	if step.IsSkippable == nil || *step.IsSkippable != DefaultIsSkippable {
		t.Fatal("IsSkippable missing")
	}
	if step.RunIf == nil || *step.RunIf != "" {
		t.Fatal("RunIf missing")
	}
	if step.Timeout == nil || *step.Timeout != 0 {
		t.Fatal("Timeout missing")
	}
}
开发者ID:bitrise-io,项目名称:stepman,代码行数:45,代码来源:models_methods_test.go

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

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


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