Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.