-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
General cleanup
- Loading branch information
Showing
22 changed files
with
1,348 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
GO ?= go | ||
|
||
GOBINDATA=bin/go/github.com/kevinburke/go-bindata/go-bindata | ||
GOIMPORTS=bin/go/golang.org/x/tools/cmd/goimports | ||
MOCKGEN=bin/go/github.com/golang/mock/mockgen | ||
TOOLS = $(GOBINDATA) \ | ||
$(GOIMPORTS) \ | ||
$(MOCKGEN) | ||
|
||
cleandeps: | ||
if [ -d "./bin" ]; then rm -rf "./bin"; fi | ||
|
||
freshdeps: cleandeps deps | ||
|
||
deps: $(TOOLS) | ||
bin/go/%: | ||
@echo "installing $*" | ||
$(GO) build -o bin/go/$* $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:generate go-enum -f=$GOFILE | ||
//go:generate ../bin/go-enum -f=$GOFILE | ||
|
||
package example | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:generate ../bin/go-enum -f=$GOFILE --prefix=AcmeInc | ||
|
||
package example | ||
|
||
// Products of AcmeInc ENUM( | ||
// Anvil, | ||
// Dynamite, | ||
// Glue | ||
// ) | ||
type Product int32 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package example | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type productData struct { | ||
ProductX Product `json:"product"` | ||
} | ||
|
||
func TestProductString(t *testing.T) { | ||
x := Product(109) | ||
assert.Equal(t, "Product(109)", x.String()) | ||
x = Product(1) | ||
assert.Equal(t, "Dynamite", x.String()) | ||
|
||
y, err := ParseProduct("Anvil") | ||
require.NoError(t, err, "Failed parsing anvil") | ||
assert.Equal(t, AcmeIncProductAnvil, y) | ||
|
||
z, err := ParseProduct("Snake") | ||
require.Error(t, err, "Shouldn't parse a snake") | ||
assert.Equal(t, Product(0), z) | ||
} | ||
|
||
func TestProductUnmarshal(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
output *productData | ||
errorExpected bool | ||
err error | ||
}{ | ||
{ | ||
name: "anvil", | ||
input: `{"product":0}`, | ||
output: &productData{ProductX: AcmeIncProductAnvil}, | ||
errorExpected: false, | ||
err: nil, | ||
}, | ||
{ | ||
name: "dynamite", | ||
input: `{"product":1}`, | ||
output: &productData{ProductX: AcmeIncProductDynamite}, | ||
errorExpected: false, | ||
err: nil, | ||
}, | ||
{ | ||
name: "glue", | ||
input: `{"product":2}`, | ||
output: &productData{ProductX: AcmeIncProductGlue}, | ||
errorExpected: false, | ||
err: nil, | ||
}, | ||
{ | ||
name: "notanproduct", | ||
input: `{"product":22}`, | ||
output: &productData{ProductX: Product(22)}, | ||
errorExpected: false, | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(tt *testing.T) { | ||
x := &productData{} | ||
err := json.Unmarshal([]byte(test.input), x) | ||
if !test.errorExpected { | ||
require.NoError(tt, err, "failed unmarshalling the json.") | ||
assert.Equal(tt, test.output.ProductX, x.ProductX) | ||
} else { | ||
require.Error(tt, err) | ||
assert.EqualError(tt, err, test.err.Error()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestProductMarshal(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input *productData | ||
output string | ||
errorExpected bool | ||
err error | ||
}{ | ||
{ | ||
name: "anvil", | ||
output: `{"product":0}`, | ||
input: &productData{ProductX: AcmeIncProductAnvil}, | ||
errorExpected: false, | ||
err: nil, | ||
}, | ||
{ | ||
name: "dynamite", | ||
output: `{"product":1}`, | ||
input: &productData{ProductX: AcmeIncProductDynamite}, | ||
errorExpected: false, | ||
err: nil, | ||
}, | ||
{ | ||
name: "glue", | ||
output: `{"product":2}`, | ||
input: &productData{ProductX: AcmeIncProductGlue}, | ||
errorExpected: false, | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(tt *testing.T) { | ||
raw, err := json.Marshal(test.input) | ||
require.NoError(tt, err, "failed marshalling to json") | ||
assert.JSONEq(tt, test.output, string(raw)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:generate go-enum -f=$GOFILE --sql | ||
//go:generate ../bin/go-enum -f=$GOFILE --sql | ||
|
||
package example | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.