Skip to content

Commit

Permalink
feat: setter can now takes maps
Browse files Browse the repository at this point in the history
  • Loading branch information
LeCrabe committed Apr 4, 2024
1 parent 5f823d9 commit da6907b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
30 changes: 26 additions & 4 deletions pkg/helper/ressource_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,46 @@ func (r *Ressource) SetName(newName string) *Ressource {
return r
}

// String values setter:
// String value setter:
// - desc: set/add key: value to the string values map of a Ressource then return the Ressource
// - args: key + value
// - return: pointer to Ressource
func (p *Ressource) SetStringValues(key, value string) *Ressource {
func (p *Ressource) SetOneStringValue(key, value string) *Ressource {
p.StringValues[key] = value
return p
}

// Integer values setter:
// Integer value setter:
// - desc: set/add key: value to the int values map of a Ressource then return the Ressource
// - args: key + value
// - return: pointer to Ressource
func (p *Ressource) SetIntValues(key string, value int) *Ressource {
func (p *Ressource) SetOneIntValue(key string, value int) *Ressource {
p.IntValues[key] = value
return p
}

// String values setter:
// - desc: set/add a map of key: value to the string values map of a Ressource then return the Ressource
// - args: map of key + value
// - return: pointer to Ressource
func (p *Ressource) SetStringValues(stringMap map[string]string) *Ressource {
for key, value := range stringMap {
p.StringValues[key] = value
}
return p
}

// Integer values setter:
// - desc: set/add a map of key: value to the int values map of a Ressource then return the Ressource
// - args: map of key + value
// - return: pointer to Ressource
func (p *Ressource) SetIntValues(intMap map[string]int) *Ressource {
for key, value := range intMap {
p.IntValues[key] = value
}
return p
}

// Ressource block
// - desc: chained function that stringify Ressource into a terraform block
// - args: none
Expand Down
14 changes: 12 additions & 2 deletions pkg/helper/ressource_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ func TestRessource_String(t *testing.T) {
max_instance_count = 2
min_instance_count = 1
}`},
{name: "test2", fields: NewRessource("clevercloud_python").SetName("test2").SetIntValues("min_instance_count", 3), want: `ressource "clevercloud_python" "test2" {
{name: "test2", fields: NewRessource("clevercloud_python").SetName("test2").SetOneStringValue("biggest_flavor", "XXL").SetOneIntValue("min_instance_count", 3), want: `ressource "clevercloud_python" "test2" {
name = "test2"
biggest_flavor = "M"
biggest_flavor = "XXL"
region = "par"
smallest_flavor = "XS"
max_instance_count = 2
min_instance_count = 3
}`},
{name: "test3", fields: NewRessource("clevercloud_python").SetName("test3").SetStringValues(map[string]string{"region": "ici", "teststring": "smt"}).SetIntValues(map[string]int{"min_instance_count": 0, "testint": 12}), want: `ressource "clevercloud_python" "test3" {
name = "test3"
biggest_flavor = "M"
region = "ici"
smallest_flavor = "XS"
teststring = "smt"
max_instance_count = 2
min_instance_count = 0
testint = 12
}`},
}
for _, tt := range tests {
Expand Down

0 comments on commit da6907b

Please sign in to comment.