Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Issue36 - Eureka integration #46

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

[WIP] Issue36 - Eureka integration #46

wants to merge 4 commits into from

Conversation

dcaba
Copy link
Collaborator

@dcaba dcaba commented Dec 12, 2017

I started to cover this:
#36

And following a tdd approach... tests are quite complete (but end to end), and main pending points are:

  • complete eureka client implementation passing the integration tests
    • we are not using fargo for the client... the things we need to do are too simple, but for tests (where we register a dummy service)
  • refactors / see inline notes and TODOs
  • expose the functionality to the cmd
  • update READMEs...

Feel free to start sharing feedback, @chadell

} else if resp.StatusCode != 200 {
return []string{},errEurekaUnexpectedHttpResponseCode
}
return nil, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guessed you will return the string array with the IPs here instead of nil...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP, WIP, WIP... ;)

var eurekaTestPort int = 8080
var eurekaTestUrl string = "http://127.0.0.1:" + strconv.Itoa(eurekaTestPort) + "/eureka"

func TestMain(m *testing.M) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean with TestMain?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


func TestMain(m *testing.M) {
// uses a sensible default on windows (tcp/http) and linux/osx (socket)
pool, err := dockertest.NewPool("")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you using "dockertest" instead of "dockertest.v3"? has the dot no sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

log.Fatalf("Could not connect to docker: %s", err)
}
// pulls an image, creates a container based on it and runs it
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this resource is the Eureka container running, isn't it? a more descriptive name could be great 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 . I was following the examples to strictly 😸

log.Fatalf("Could not connect to the docker resource: %s", err)
}

code := m.Run()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is Run from Testing doing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the previous reference about what TestMain actually does

func TestEurekaClientWrongEurekaContext(t *testing.T) {
_, err := NewEurekaClient(eurekaTestUrl + "badsuffix")
if err != errEurekaUnexpectedHttpResponseCode {
t.Fatal("Eureka should be reachable but, when asking a wrong URL, it should return a non 200 response code")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmm, reaching this point I suspect that the m.Run() in TestMain does is to start the Eureka server to run the other tests after that. am I right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nops. TestMain does run Eureka (and kills it when tests finish), and in the middle, with m.Run , actually runs all your tests there. Its a mechanism allowing you to wrap all your tests and do things at the beginning and end (init only covers the first part, so that's why golang released this in... 1.5?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 seen in your comment above

}

func TestEurekaClientEurekaDoesNotReply(t *testing.T) {
_, err := NewEurekaClient("http://192.0.2.1:9999/thisshouldtimeout")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Addresses starting with "192.0.2.", "198.51.100.", or "203.0.113." are reserved for use in documentation and sample configurations. They should never be used in a live network configuration. No one has permission to use these addresses on the Internet."
I guess doing testing is no documentation...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you suggest another IP range which traffic will be dropped for sure? In fact, these networks are referenced as "TEST NETWORKs" in the RFC, so that was the best option I found...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you were right, don't change it.

httpclient := http.Client{Timeout: time.Second * eurekaClientTimeoutInSeconds}
resp, err := httpclient.Get(eurekaAppUrl)
req, err := http.NewRequest("GET", eurekaAppUrl, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change from httpclient.Get to http.NewRequest + httpclient.Do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I'm trying to add a request header, and the Get method does not allow me so

@@ -24,8 +24,10 @@ func TestMain(m *testing.M) {
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: "netflixoss/eureka",
Tag: "1.3.1",
PortBindings: map[dc.Port][]dc.PortBinding{
dc.Port(strconv.Itoa(eurekaTestPort) + "/tcp"): {{HostIP: "", HostPort: strconv.Itoa(eurekaTestPort)}},
//Repository: "containers.schibsted.io/spt-infrastructure/eureka-docker",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this comment for? own testing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP. Comparing the (old) public version in eureka with one that is newer, but not public...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants