-
Couldn't load subscription status.
- Fork 62
tests: added golang tests to lib/tests to test image fetching #181
Conversation
| "github.com/appc/docker2aci/lib/internal/typesV2" | ||
| ) | ||
|
|
||
| type Layer map[*tar.Header][]byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will use tar.Header pointer values as keys, not the tar.Header values. If put two equal values of tar.Header, but with distinct memory locations, they will have a different key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I make that change I get:
derek@proton ~/go/src/github.com/appc/docker2aci> go test -v github.com/appc/docker2aci/lib/tests
# github.com/appc/docker2aci/lib/tests
lib/tests/common.go:16: invalid map key type tar.Header
No clue why go doesn't allow this, but I don't think that using pointers will be an issue here. This is only used in the creation of tests, and test writers can avoid creating duplicate tar.Headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I overlooked you're trying to use stdlib's tar.Header as the key type. http://godoc.org/archive/tar#Header contains Xattrs of type map[string]string and that is the problem.
Map key types must have the comparison operators == and != fully defined, hence your struct key type must not contain a function, map, or slice.
I agree that this is used only in tests, but if you'll ever put two equal header values, but with different memory locations, they won't be the same :-/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: can't you take the layer hashes as the map keys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm doing here is trying to work around the fact that Go doesn't have tuples. I want to store a list of pairs, where each pair is a tar header and the file contents. Go's maps kinda let me do this, by being a way to define a set of pairs (where each key and its value is the pair).
I could specify a struct that holds a tar.Header and a []byte, and have a layer be a slice of these structs, but that also would allow duplicate tar headers, so there's no benefit there over the current approach.
I don't think using layer hashes as the map keys here makes sense, as I don't know the hashes at this point in time and the keys here represent a given file in the layer, not the layer itself.
To truly prevent duplicates perhaps I could go with the slice of structs approach and have a helper function to search the slice each time to make sure that I'm not adding duplicates, but that seems rather heavy handed for hardcoded tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right about the layer hashes, it is too late to do reviews ;-) Let's leave it like this then.
If I'll come up with a better idea, I'll do a follow-up PR.
LGTM
|
We should run these tests on Semaphore |
|
or Jenkins? |
|
|
not trolling :-( On 11 July 2016 at 18:12, Iago López Galeiras [email protected]
|
|
What's the benefit of running this on several distros? |
|
I don't think we need to do it on several different distros - but it would On 11 July 2016 at 18:14, Iago López Galeiras [email protected]
|
I don't see a pressing need for this, I think Semaphore works fine for docker2aci's use case. |
|
OK On 11 July 2016 at 18:48, Iago López Galeiras [email protected]
|
8c184d6 to
d6e6537
Compare
|
Added these tests to |
lib/tests/common.go
Outdated
| } | ||
|
|
||
| func GenerateDocker22(destPath string, img Docker22Image) error { | ||
| tmpDir, err := ioutil.TempDir("", "docker2aci-test-") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be used.
|
The tests don't check whether the converted image has the right contents, right? I guess that's tested on the tests in |
|
That's right, at this point these tests aim only to exercise the fetching logic. I'd like to move the checks under |
|
OK. Please remove the unused code I pointed out above and I'll merge it :) |
This commit creates the directory lib/tests, which includes the following: - code for generating a manifest and layers conforming to docker v2.2 - code for emulating a docker registry that hosts these images (the docker daemon can successfully pull images from this) - a few tests that utilize these to test using the docker2aci library to pull/convert an image
|
Removed. |
This commit creates the directory lib/tests, which includes the
following:
docker daemon can successfully pull images from this)
to pull/convert an image
These fetching tests triggered a panic in docker2aci, which this commit also fixes.
I intend to create a followup PR to also test the docker v2.1 logic and the logic for converting a file on disk, and to hopefully pull the logic under tests/ into these golang tests.