go-sigsci
go-sigsci copied to clipboard
adding hcl tags so a terraform config can be generated
package marshal
import (
"fmt"
"github.com/hashicorp/hcl2/gohcl"
"github.com/hashicorp/hcl2/hclwrite"
"github.com/signalsciences/go-sigsci"
)
type localCreateSignalTagBody sigsci.CreateSignalTagBody
func (l localCreateSignalTagBody) marshalSiteText(localName, site string) string {
str := fmt.Sprintf(`resource %s "%s" {
site_short_name = "%s"
`, l.TFSiteResourceName(), localName, site)
f := hclwrite.NewEmptyFile()
gohcl.EncodeIntoBody(&l, f.Body())
str += string(f.Bytes())
str += "}\n"
return str
}```
a test for it looks like this
```go
func TestTextMarshalSiteSignalTag(t *testing.T) {
createSignalTagBody := localCreateSignalTagBody{
ShortName: "Example Signal Tag 1",
Description: "An example of a custom signal tag",
}
got := createSignalTagBody.marshalSiteText("test", "splunk-test")
expected := "resource sigsci_site_signal_tag \"test\" {\n\tsite_short_name = \"splunk-test\"\nshort_name = \"Example Signal Tag 1\"\ndescription = \"An example of a custom signal tag\"\n}\n"
assert.Equal(t, expected, got)
}```