Open mchirico opened 3 years ago
A bit more of docker-compose and how the command can be called from Go, and used in testing.
docker-compose
Video
package topic import ( "context" "fmt" "os" "os/exec" "testing" "time" ) func TestMain(m *testing.M) { startKafka() code := m.Run() stopKafka() os.Exit(code) } func startKafka() { ctx, cancel := context.WithTimeout(context.Background(), 10000*time.Millisecond) defer cancel() if err := exec.CommandContext(ctx, "bash", "-c", "cd ./../compose;docker-compose up -d").Run(); err != nil { // This will fail after 100 milliseconds. The 5 second sleep // will be interrupted. fmt.Printf("Error starting compose: %v\n", err) } } func stopKafka() { ctx, cancel := context.WithTimeout(context.Background(), 10000*time.Millisecond) defer cancel() if err := exec.CommandContext(ctx, "bash", "-c", "cd ./../compose;docker-compose down").Run(); err != nil { // This will fail after 100 milliseconds. The 5 second sleep // will be interrupted. fmt.Printf("Error stopping compose: %v\n", err) } } func TestCreate(t *testing.T) { topic := "topic0" broker := "localhost:29099" err := Create(broker, topic, 4, 1) if err != nil { t.Fatalf("Can't create topic: %s\n", topic) } err = Delete(broker, []string{topic}) if err != nil { t.Fatalf("Can't delete topic: %s\n", topic) } }
mchirico, Thanks for opening this issue!
hello
Docker and Go
A bit more of
docker-compose
and how the command can be called from Go, and used in testing.Video