Created
November 7, 2018 16:36
-
-
Save sebastianwebber/8ba83c6ceb5e0216a5f811bff84ebeee to your computer and use it in GitHub Desktop.
exemplo interface e testes #golang
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
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)) | |
} |
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
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