dockertest icon indicating copy to clipboard operation
dockertest copied to clipboard

suggest change another example in readme

Open huahuayu opened this issue 3 years ago • 1 comments
trafficstars

Preflight checklist

Describe your problem

The example can't be run in mac m1, because of the mysql5.7 docker image problem.

Describe your ideal solution

Maybe it's better to use another use case or image which don't have compatibility issue. , AFAIK postgres image works fine in both intel & arm arch.

Workarounds or alternatives

I tried to use arm64v8/mysql:8 no lucky

Version

https://github.com/ory/dockertest/commit/5e64d1ad5af5253d65cc8684f1ce4e7ed6d52412

Additional Context

No response

huahuayu avatar Sep 17 '22 15:09 huahuayu

This snippet works

package dockertest_test

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"github.com/ory/dockertest/v3"
	"log"
	"os"
	"testing"
)

var db *redis.Client

func TestMain(m *testing.M) {
	// uses a sensible default on windows (tcp/http) and linux/osx (socket)
	pool, err := dockertest.NewPool("")
	if err != nil {
		log.Fatalf("Could not connect to docker: %s", err)
	}

	// pulls an image, creates a container based on it and runs it
	resource, err := pool.Run("redis", "latest", nil)
	if err != nil {
		log.Fatalf("Could not start resource: %s", err)
	}

	// exponential backoff-retry, because the application in the container might not be ready to accept connections yet
	if err = pool.Retry(func() error {
		db = redis.NewClient(&redis.Options{
			Addr: fmt.Sprintf("localhost:%s", resource.GetPort("6379/tcp")),
		})
		return db.Ping(context.Background()).Err()
	}); err != nil {
		log.Fatalf("Could not connect to docker: %s", err)
	}

	code := m.Run()

	// When you're done, kill and remove the container, you can't defer this because os.Exit doesn't care for defer
	if err = pool.Purge(resource); err != nil {
		log.Fatalf("Could not purge resource: %s", err)
	}

	os.Exit(code)
}

func TestSomething(t *testing.T) {
	db.Set(context.Background(), "k0", "v0", 0)
	val, err := db.Get(context.Background(), "k0").Result()
	log.Println(val, err)
}

huahuayu avatar Sep 18 '22 03:09 huahuayu

Hello contributors!

I am marking this issue as stale as it has not received any engagement from the community or maintainers for a year. That does not imply that the issue has no merit! If you feel strongly about this issue

  • open a PR referencing and resolving the issue;
  • leave a comment on it and discuss ideas on how you could contribute towards resolving it;
  • leave a comment and describe in detail why this issue is critical for your use case;
  • open a new issue with updated details and a plan for resolving the issue.

Throughout its lifetime, Ory has received over 10.000 issues and PRs. To sustain that growth, we need to prioritize and focus on issues that are important to the community. A good indication of importance, and thus priority, is activity on a topic.

Unfortunately, burnout has become a topic of concern amongst open-source projects.

It can lead to severe personal and health issues as well as opening catastrophic attack vectors.

The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone.

If this issue was marked as stale erroneously you can exempt it by adding the backlog label, assigning someone, or setting a milestone for it.

Thank you for your understanding and to anyone who participated in the conversation! And as written above, please do participate in the conversation if this topic is important to you!

Thank you 🙏✌️

github-actions[bot] avatar Sep 19 '23 00:09 github-actions[bot]