Skip to content

Instantly share code, notes, and snippets.

@sebastianwebber
Created November 7, 2018 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastianwebber/8ba83c6ceb5e0216a5f811bff84ebeee to your computer and use it in GitHub Desktop.
Save sebastianwebber/8ba83c6ceb5e0216a5f811bff84ebeee to your computer and use it in GitHub Desktop.
exemplo interface e testes #golang
package main
import (
"fmt"
)
type contrato interface {
Insert() string
}
type impl struct {
}
func (i impl) Insert() string {
return "inserido"
}
func execInsert(c contrato) string {
return c.Insert()
}
func main() {
aa := impl{}
fmt.Printf("Insert: %s", execInsert(aa))
}
package main
import (
"testing"
)
type contratoMock struct{}
func (c contratoMock) Insert() string {
return "mock"
}
func Test_execInsert(t *testing.T) {
tests := []struct {
name string
args contrato
}{
{name: "a", args: contratoMock{}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
execInsert(tt.args)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment