Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Adding tests for kedge build #381

Merged
merged 1 commit into from
Dec 13, 2017
Merged

Conversation

ashetty1
Copy link
Collaborator

@ashetty1 ashetty1 commented Oct 23, 2017

The test here creates a local docker registry, runs kedge build, and verifies if the image has been uploaded.

@ashetty1
Copy link
Collaborator Author

@surajssd would like to have your inputs on this.

@ashetty1
Copy link
Collaborator Author

Working on fixing the travis errors

@ashetty1 ashetty1 force-pushed the build_test branch 3 times, most recently from 9c427ee to c925569 Compare October 24, 2017 09:22
Copy link
Member

@surajssd surajssd left a comment

Choose a reason for hiding this comment

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

So this approach LGTM!

  • Start registry
  • Login to registry
  • Do kedge build/push
  • Verify that image is built locally
  • Verify that image is available on the registry
  • Clean registry and image

_, err = runCmd("docker rm -v kedge_registry")
if err != nil {
t.Error(err)
}
Copy link
Member

Choose a reason for hiding this comment

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

put all of the clean up code in a fucntion and then call it with defer so that we always do the clean up!

@ashetty1 ashetty1 changed the title [WIP] Adding tests for kedge build Adding tests for kedge build Oct 26, 2017
@cdrage cdrage force-pushed the master branch 2 times, most recently from 52766ab to 388b72b Compare November 2, 2017 22:59
@surajssd
Copy link
Member

@ashetty1 tried running it, but getting following error, I think this should also be taken care!

$ go test -run TestBuild github.com/kedgeproject/kedge/tests/e2e
--- FAIL: TestBuild (0.01s)
panic: error running command &{/bin/sh [/bin/sh -c docker run -d -p 5000:5000 --restart=always --name kedge_registry registry:2] []  <nil>  docker: Error response from daemon: Conflict. The container name "/kedge_registry" is already in use by container "889c30df6d0c704c862790f8a6ef489c5e9a3b93638aadf57ce301d402e914d9". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
 [] <nil> 0xc4201a0930 exit status 125 <nil> <nil> true [0xc420302098 0xc4203020b8 0xc4203020d0] [0xc420302098 0xc4203020b8 0xc4203020d0] [0xc4203020a8 0xc4203020c8] [0x552540 0x552540] 0xc4201ce660 <nil>}: exit status 125 [recovered]
        panic: error running command &{/bin/sh [/bin/sh -c docker run -d -p 5000:5000 --restart=always --name kedge_registry registry:2] []  <nil>  docker: Error response from daemon: Conflict. The container name "/kedge_registry" is already in use by container "889c30df6d0c704c862790f8a6ef489c5e9a3b93638aadf57ce301d402e914d9". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
 [] <nil> 0xc4201a0930 exit status 125 <nil> <nil> true [0xc420302098 0xc4203020b8 0xc4203020d0] [0xc420302098 0xc4203020b8 0xc4203020d0] [0xc4203020a8 0xc4203020c8] [0x552540 0x552540] 0xc4201ce660 <nil>}: exit status 125

goroutine 20 [running]:
testing.tRunner.func1(0xc4202b60f0)
        /usr/local/go/src/testing/testing.go:711 +0x2d2
panic(0xfd1000, 0xc42044a080)
        /usr/local/go/src/runtime/panic.go:491 +0x283
github.com/kedgeproject/kedge/tests/e2e.TestBuild(0xc4202b60f0)
        /home/fedora/go/src/github.com/kedgeproject/kedge/tests/e2e/build_test.go:60 +0x80e
testing.tRunner(0xc4202b60f0, 0x11c3820)
        /usr/local/go/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:789 +0x2de
FAIL    github.com/kedgeproject/kedge/tests/e2e 0.068s

@surajssd
Copy link
Member

After cleaning up manually

$ docker stop kedge_registry
$ docker rm -f $(docker ps -aq)

I ran that individual test and it took almost 4mins to complete:

$ go test -run TestBuild github.com/kedgeproject/kedge/tests/e2e                                                                                                                        
ok      github.com/kedgeproject/kedge/tests/e2e 231.089s

This should run in parallel with e2e tests, to make it faster.

@surajssd
Copy link
Member

Also it is using the docker env of the host, not of the minikube or minishift vm!

@ashetty1
Copy link
Collaborator Author

@surajssd I am not sure if we need to check if there is a docker registry with the same name before running the test. What we should expect before the test is a clean setup and then leave the system as it was once the test run is complete

t.Error(err)
}

dockerRegStart := "docker run -d -p 5000:5000 --restart=always --name kedge_registry registry:2"
Copy link
Member

Choose a reason for hiding this comment

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

You can also add the flag --rm which will delete the docker container once the registry is stopped!

Copy link
Member

Choose a reason for hiding this comment

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

This will reduce the whole hassle of deleting the container

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@surajssd
Copy link
Member

@surajssd I am not sure if we need to check if there is a docker registry with the same name before running the test. What we should expect before the test is a clean setup and then leave the system as it was once the test run is complete

why should we assume that? We will also be running tests locally so we don't want to leave the environment dirty in dev machine!

@ashetty1
Copy link
Collaborator Author

ashetty1 commented Dec 4, 2017

@surajssd kindly review this.

Copy link
Member

@surajssd surajssd left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Would be nice to add code comments 👍


defer DeleteRegistry(t)

runKedgeCmd := KedgeLoc + "/kedge build -c " + contextDir + " -i localhost:5000/test:2.0 -p"
Copy link
Collaborator

Choose a reason for hiding this comment

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

have a look at https://github.com/kedgeproject/kedge/blob/master/tests/e2e/e2e_test.go#L30

would be better to throw the binary location up in global variables

var contextDir = KedgeLoc + "/docs/examples/build"

// Cleanup
_, _ = runCmd("docker stop kedge_registry")
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider adding a slower timeout -t 1 in order to speed up tests.

t.Error(err)
}

dockerRegStart := "docker run -d -p 5000:5000 --restart=always --name kedge_registry registry:2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

The test here creates a local docker registry, runs `kedge build`,
and verifies if the image has been uploaded
@ashetty1
Copy link
Collaborator Author

ashetty1 commented Dec 7, 2017

@cdrage could you please do a final review here.

@cdrage
Copy link
Collaborator

cdrage commented Dec 12, 2017

This LGTM 👍 merge when you're comfortable.

@ashetty1
Copy link
Collaborator Author

@surajssd @kadel let me know if you guys think this can be merged.

@ashetty1 ashetty1 mentioned this pull request Dec 13, 2017
2 tasks
@kadel
Copy link
Member

kadel commented Dec 13, 2017

this already has two LGTMs.
I'm merging this

@kadel kadel merged commit f07524d into kedgeproject:master Dec 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants