package helloworld_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/pingcap/test-infra/sdk/resource"

	_ "github.com/pingcap/endless/pkg/client/tidb"
)

var _ = Describe("HelloWorld", func() {
	Context("hello world", func() {
		It("should always pass #hello_world_1#", func() {
			Expect(nil).Should(Succeed())
		})
	})
})

var _ = Describe("Real world test case", func() {
	It("should pass if you have created your testbed #hello_world_2#", func() {
		ctx := suiteTestCtx

		// Please ensure than you have created your testbed,
		// otherwise the process exits with err "undefined resource: tc".
		_ = ctx.Resource("tc").(resource.TiDBCluster)
	})

	Context("assume that you have created your testbed", func() {
		It("should pass if you have setup your MYSQL_PROXY correctly #hello_world_3#", func() {
			ctx := suiteTestCtx
			tc := ctx.Resource("tc").(resource.TiDBCluster)

			// Please ensure that you have setup MYSQL_PROXY environment variable,
			// for example: export MYSQL_PROXY=socks5://8.8.8.8:30081.
			// Otherwise this fails with err:
			// "dial tcp: lookup tc-tidb.testbed-endless-helloworld-xxxx.svc: no such host"

			// Setup a sql.DB instance
			_, err := tc.GetDB("test")
			// Assert the err should be nil
			Expect(err).Should(Succeed())
		})
	})
})
