Skip to content

Commit

Permalink
chore: Added first set of unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maikelpoot committed Feb 14, 2024
1 parent 95431a9 commit 5c063e9
Show file tree
Hide file tree
Showing 6 changed files with 885 additions and 19 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/topicusonderwijs/terraform-provider-octodns
go 1.21

require (
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v55 v55.0.0
github.com/hashicorp/terraform-plugin-docs v0.18.0
github.com/hashicorp/terraform-plugin-framework v1.5.0
Expand Down
100 changes: 85 additions & 15 deletions internal/models/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ func (r *Record) ValuesAsString() []string {
ret = append(ret, v.StringMX())
case TYPE_SRV.String():
ret = append(ret, v.StringSRV())

case TYPE_CAA.String():
ret = append(ret, v.StringCAA())
case TYPE_URLFWD.String():
ret = append(ret, v.StringURLFWD())
case TYPE_SSHFP.String():
ret = append(ret, v.StringSSHFP())
case TYPE_NAPTR.String():
ret = append(ret, v.StringNAPTR())
case TYPE_LOC.String():
ret = append(ret, v.StringLOC())
}

}
Expand Down Expand Up @@ -170,11 +179,9 @@ func (r Record) MarshalYAML() (interface{}, error) {
}
if len(r.Values) > 1 {
err = node.Encode(r.Values)
node.LineComment = "Blaat"
out.Values = node
} else {
err = node.Encode(r.Values[0])
node.LineComment = "Blaat"
out.Value = node
}
if err != nil {
Expand Down Expand Up @@ -212,18 +219,18 @@ type baseRecordValue struct {
//Priority int `yaml:",omitempty"`

// LOC
Altitude *int `yaml:",omitempty"`
Lat_degrees *int `yaml:",omitempty"`
Lat_direction *string `yaml:",omitempty"`
Lat_minutes *int `yaml:",omitempty"`
Lat_seconds *float64 `yaml:",omitempty"`
Long_degrees *int `yaml:",omitempty"`
Long_direction *string `yaml:",omitempty"`
Long_minutes *int `yaml:",omitempty"`
Long_seconds *float64 `yaml:",omitempty"`
Precision_horz *int `yaml:",omitempty"`
Precision_vert *int `yaml:",omitempty"`
Size *int `yaml:",omitempty"`
Altitude *float64 `yaml:",omitempty"`
LatDegrees *int `yaml:"lat_degrees,omitempty"`
LatDirection *string `yaml:"lat_direction,omitempty"`
LatMinutes *int `yaml:"lat_minutes,omitempty"`
LatSeconds *float64 `yaml:"lat_seconds,omitempty"`
LongDegrees *int `yaml:"long_degrees,omitempty"`
LongDirection *string `yaml:"long_direction,omitempty"`
LongMinutes *int `yaml:"long_minutes,omitempty"`
LongSeconds *float64 `yaml:"long_seconds,omitempty"`
PrecisionHorz *int `yaml:"precision_horz,omitempty"`
PrecisionVert *int `yaml:"precision_vert,omitempty"`
Size *int `yaml:",omitempty"`

// NAPTR
//Flags string `yaml:",omitempty"`
Expand Down Expand Up @@ -299,6 +306,69 @@ func (r RecordValue) StringSRV() string {

}

func (r RecordValue) StringCAA() string {

if r.Flags != nil && r.Tag != nil && r.Value != nil {
return fmt.Sprintf("%s %s %s", *r.Flags, *r.Tag, *r.Value)
} else {
return ""
}
}

func (r RecordValue) StringURLFWD() string {

if r.Code != nil && r.Masking != nil && r.Path != nil && r.Query != nil && r.Target != nil {
return fmt.Sprintf(
"%d %d %s %d %s",
*r.Code, *r.Masking, *r.Path, *r.Query, *r.Target,
)
} else {
return ""
}
}
func (r RecordValue) StringSSHFP() string {
if r.Algorithm != nil && r.FingerprintType != nil && r.Fingerprint != nil {
return fmt.Sprintf(
"%d %d %s",
*r.Algorithm, *r.FingerprintType, *r.Fingerprint,
)
} else {
return ""
}
}

func (r RecordValue) StringNAPTR() string {

if r.Order != nil && r.Preference != nil && r.Flags != nil && r.Service != nil && r.Regexp != nil && r.Replacement != nil {
return fmt.Sprintf(
"%d %d %q %q %q %s",
*r.Order, *r.Preference, *r.Flags, *r.Service, *r.Regexp, *r.Replacement,
)
} else {
return ""
}
}

func (r RecordValue) StringLOC() string {

return fmt.Sprintf(
"%d %d %0.2f %s %d %d %0.2f %s %0.2f %d %d %d",
*r.LatDegrees,
*r.LatMinutes,
*r.LatSeconds,
*r.LatDirection,
*r.LongDegrees,
*r.LongMinutes,
*r.LongSeconds,
*r.LongDirection,
*r.Altitude,
*r.Size,
*r.PrecisionHorz,
*r.PrecisionVert,
)

}

func (r RecordValue) MarshalYAML() (interface{}, error) {

if r.StringValue != nil {
Expand Down
Loading

0 comments on commit 5c063e9

Please sign in to comment.