Skip to content

Commit

Permalink
Add travis
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net>
  • Loading branch information
creack committed Feb 18, 2019
1 parent 34f018e commit 490b33c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sudo: false

language: go

go:
- 1.11
- tip

before_install:
- go get -t -v ./...
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover

script:
- go test -v -covermode=count -coverprofile=profile.cov .
- go tool cover -func profile.cov
- goveralls -coverprofile=profile.cov -service=travis-ci
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# hcler

Encode arbitrary Go types to Hashicorp's HCL format.

## Usage

## Common types

`hcler.Encode()` can be used with most common types.

## Custom types

In order to support custom types, hcler provides the `hcler.Encoder` interface, similar to `json.Marshaler` & co.
The interface only requires the `EncodeHCL() (string, error)` method.

## Benchmark

```
goos: linux
goarch: amd64
pkg: github.com/creack/hcler
BenchmarkMapStringKeyEncoder/hcl_map-32 1000000 1856 ns/op 334 B/op 14 allocs/op
BenchmarkMapStringKeyEncoder/map_str_iface-32 1000000 1883 ns/op 333 B/op 14 allocs/op
BenchmarkMapInterfaceEncoder/hcl_i_map-32 300000 4259 ns/op 1346 B/op 20 allocs/op
BenchmarkMapInterfaceEncoder/map_iface_iface-32 300000 4561 ns/op 1346 B/op 20 allocs/op
BenchmarkDiscarded/map_str_slice_prealloc-32 500000 3654 ns/op 512 B/op 24 allocs/op
BenchmarkDiscarded/map_str_slice_noprealloc-32 500000 3759 ns/op 528 B/op 25 allocs/op
PASS
ok github.com/creack/hcler 10.349s
```
5 changes: 5 additions & 0 deletions value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hcler

import (
"errors"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -27,6 +28,10 @@ func TestStringConvertion(t *testing.T) {
assertString(t, "h", byte('h'))
assertString(t, "h", 'h')
assertString(t, "error", errors.New("error"))

rawURL := "https://user:password@domain.tld/path/subpath?foo=bar#foo=bar"
u, _ := url.Parse(rawURL)
assertString(t, rawURL, u)
})

t.Run("numbers", func(t *testing.T) {
Expand Down

0 comments on commit 490b33c

Please sign in to comment.