| package main | |
| import ( | |
| "testing" | |
| "time" | |
| dockerinitiator "github.com/Storytel/go-docker-initiator" | |
| ) | |
| func TestGetUsers(t *testing.T) { | |
| // Create a new instance of mysql to connect to | |
| instance, err := dockerinitiator.Mysql(dockerinitiator.MysqlConfig{ | |
| DbName: "testdb", | |
| Password: "", | |
| User: "root", | |
| }) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| // Cleanup after test is done | |
| defer instance.Stop() | |
| // This makes connection details available in the environment | |
| // via e.g. os.Getenv("MYSQL_SERVER") | |
| if err = instance.Setenv(); err != nil { | |
| t.Fatal(err) | |
| } | |
| // Create a new user repository as referred in snippet above | |
| // (this func was excluded for brievity). | |
| repo := NewUserRepository() | |
| // Setup the database and seed it here | |
| // Act and get the users | |
| users, err := repo.GetUsers() | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| // Assert `users` here | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment