Skip to content

Commit

Permalink
Merge pull request #59 from gkiki90/title_desc_summary
Browse files Browse the repository at this point in the history
Summary field
  • Loading branch information
viktorbenei committed Aug 19, 2015
2 parents 7658fe6 + 5770aef commit 8ba15c4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions envman/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func removeDefaults(env *models.EnvironmentItemModel) error {
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
}
Expand Down Expand Up @@ -130,6 +133,9 @@ func generateFormattedYMLForEnvModels(envs []models.EnvironmentItemModel) (model
if opts.Description != nil {
hasOptions = true
}
if opts.Summary != nil {
hasOptions = true
}
if len(opts.ValueOptions) > 0 {
hasOptions = true
}
Expand Down
1 change: 1 addition & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package models
type EnvironmentItemOptionsModel struct {
Title *string `json:"title,omitempty" yaml:"title,omitempty"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
Summary *string `json:"summary,omitempty" yaml:"summary,omitempty"`
ValueOptions []string `json:"value_options,omitempty" yaml:"value_options,omitempty"`
IsRequired *bool `json:"is_required,omitempty" yaml:"is_required,omitempty"`
IsExpand *bool `json:"is_expand,omitempty" yaml:"is_expand,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions models/models_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func (envSerModel *EnvironmentItemOptionsModel) ParseFromInterfaceMap(input map[
return fmt.Errorf("Invalid value type (key:%s): %#v", keyStr, value)
}
envSerModel.Description = pointers.NewStringPtr(castedValue)
case "summary":
castedValue, ok := value.(string)
if !ok {
return fmt.Errorf("Invalid value type (key:%s): %#v", keyStr, value)
}
envSerModel.Summary = pointers.NewStringPtr(castedValue)
case "value_options":
castedValue, ok := value.([]string)
if !ok {
Expand Down Expand Up @@ -187,6 +193,9 @@ func (env *EnvironmentItemModel) FillMissingDefaults() error {
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)
}
Expand Down
21 changes: 21 additions & 0 deletions models/models_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
testValue2 = "test_value2"
testTitle = "test_title"
testDescription = "test_description"
testSummary = "test_summary"
testValueOptions = []string{testKey2, testValue2}
testTrue = true
testFalse = false
Expand All @@ -27,6 +28,7 @@ func TestGetKeyValuePair(t *testing.T) {
OptionsKey: EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(testTitle),
Description: pointers.NewStringPtr(testDescription),
Summary: pointers.NewStringPtr(testSummary),
ValueOptions: testValueOptions,
IsRequired: pointers.NewBoolPtr(testTrue),
IsExpand: pointers.NewBoolPtr(testFalse),
Expand Down Expand Up @@ -211,6 +213,7 @@ func TestNormalize(t *testing.T) {
OptionsKey: map[interface{}]interface{}{
"title": testTitle,
"description": testDescription,
"summary": testSummary,
"value_options": testValueOptions,
"is_required": testTrue,
},
Expand All @@ -232,6 +235,9 @@ func TestNormalize(t *testing.T) {
if opts.Description == nil || *opts.Description != testDescription {
t.Fatal("Description is nil, or not correct")
}
if opts.Summary == nil || *opts.Summary != testSummary {
t.Fatal("Summary is nil, or not correct")
}
if len(opts.ValueOptions) != len(testValueOptions) {
t.Fatal("ValueOptions element num is not correct, or not correct")
}
Expand All @@ -245,6 +251,7 @@ func TestNormalize(t *testing.T) {
OptionsKey: EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(testTitle),
Description: pointers.NewStringPtr(testDescription),
Summary: pointers.NewStringPtr(testSummary),
ValueOptions: testValueOptions,
IsRequired: pointers.NewBoolPtr(testTrue),
},
Expand All @@ -266,6 +273,9 @@ func TestNormalize(t *testing.T) {
if opts.Description == nil || *opts.Description != testDescription {
t.Fatal("Description is nil, or not correct")
}
if opts.Summary == nil || *opts.Summary != testSummary {
t.Fatal("Summary is nil, or not correct")
}
if len(opts.ValueOptions) != len(testValueOptions) {
t.Fatal("ValueOptions element num is not correct")
}
Expand Down Expand Up @@ -294,6 +304,9 @@ func TestNormalize(t *testing.T) {
if opts.Description != nil {
t.Fatal("Description is not nil")
}
if opts.Summary != nil {
t.Fatal("Summary is not nil")
}
if len(opts.ValueOptions) != 0 {
t.Fatal("ValueOptions element num is not correct")
}
Expand Down Expand Up @@ -323,6 +336,9 @@ func TestFillMissingDefaults(t *testing.T) {
if opts.Description == nil || *opts.Description != "" {
t.Fatal("Failed to fill Description default value")
}
if opts.Summary == nil || *opts.Summary != "" {
t.Fatal("Failed to fill Summary default value")
}
if opts.IsRequired == nil || *opts.IsRequired != DefaultIsRequired {
t.Fatal("Failed to fill IsRequired default value")
}
Expand All @@ -339,6 +355,7 @@ func TestFillMissingDefaults(t *testing.T) {
OptionsKey: EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(testTitle),
Description: pointers.NewStringPtr(testDescription),
Summary: pointers.NewStringPtr(testSummary),
ValueOptions: testValueOptions,
IsRequired: pointers.NewBoolPtr(testTrue),
IsExpand: pointers.NewBoolPtr(testTrue),
Expand All @@ -360,6 +377,9 @@ func TestFillMissingDefaults(t *testing.T) {
if opts.Description == nil || *opts.Description != testDescription {
t.Fatal("Description is nil, or not correct")
}
if opts.Summary == nil || *opts.Summary != testSummary {
t.Fatal("Summary is nil, or not correct")
}
if len(opts.ValueOptions) != len(testValueOptions) {
t.Fatal("ValueOptions element num is not correct")
}
Expand All @@ -380,6 +400,7 @@ func TestValidate(t *testing.T) {
OptionsKey: EnvironmentItemOptionsModel{
Title: pointers.NewStringPtr(testTitle),
Description: pointers.NewStringPtr(testDescription),
Summary: pointers.NewStringPtr(testSummary),
ValueOptions: testValueOptions,
IsRequired: pointers.NewBoolPtr(testTrue),
IsExpand: pointers.NewBoolPtr(testTrue),
Expand Down

0 comments on commit 8ba15c4

Please sign in to comment.