diff --git a/.gitignore b/.gitignore index c5a3d2b..5c3299c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,11 +10,9 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out -# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 -.glide/ - -# Compiled binary +# Compiled binaries /lstags +/lstags.* # Vendored dependencies /vendor/* diff --git a/.travis.yml b/.travis.yml index 918a322..79181fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ install: - make dep script: + - make unit-test - make package-test - make integration-test - make lint diff --git a/Makefile b/Makefile index af16429..20dc42e 100644 --- a/Makefile +++ b/Makefile @@ -22,10 +22,10 @@ package-test: integration-test: go test -integration -v -lint: ERRORS=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -i golint {}) +lint: ERRORS:=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -i golint {}) lint: fail-on-errors -vet: ERRORS=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -i go tool vet {}) +vet: ERRORS:=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -i go tool vet {}) vet: fail-on-errors fail-on-errors: @@ -34,3 +34,13 @@ fail-on-errors: build: go build + +build-linux: GOOS:=linux +build-linux: + GOOS=${GOOS} go build -o lstags.${GOOS} + +build-darwin: GOOS:=darwin +build-darwin: + GOOS=${GOOS} go build -o lstags.${GOOS} + +xbuild: build-linux build-darwin diff --git a/main.go b/main.go index 6b25d65..9e3d7d8 100644 --- a/main.go +++ b/main.go @@ -63,12 +63,14 @@ func main() { suicide(err) } - sortKeys, joinedTags := tag.Join(registryTags, localTags) + sortedKeys, names, joinedTags := tag.Join(registryTags, localTags) const format = "%-12s %-45s %-15s %-25s %s\n" fmt.Printf(format, "", "", "<(local) ID>", "", "") - for _, sortKey := range sortKeys { - tg := joinedTags[sortKey] + for _, key := range sortedKeys { + name := names[key] + + tg := joinedTags[name] fmt.Printf( format, diff --git a/main_test.go b/main_test.go index 19ccf56..1ff6d7e 100644 --- a/main_test.go +++ b/main_test.go @@ -30,6 +30,11 @@ func (tr MockedTokenResponse) ExpiresIn() int { } func TestGetAuthorization(t *testing.T) { + flag.Parse() + if *runIntegrationTests { + t.SkipNow() + } + const expected = "Mocked 8c896241e2774507489849ab1981e582" authorization := getAuthorization(MockedTokenResponse{}) diff --git a/tag/local/local.go b/tag/local/local.go index e09f651..4a14e87 100644 --- a/tag/local/local.go +++ b/tag/local/local.go @@ -132,7 +132,7 @@ func FetchTags(repo string) (map[string]*tag.Tag, error) { tg.SetCreated(imageSummary.Created) - tags[tg.SortKey()] = tg + tags[tg.GetName()] = tg } } diff --git a/tag/registry/registry.go b/tag/registry/registry.go index fc25b28..074a2e7 100644 --- a/tag/registry/registry.go +++ b/tag/registry/registry.go @@ -310,7 +310,7 @@ func FetchTags(registry, repo, authorization string, concurrency int) (map[strin tt.SetCreated(dr.Created) - tags[tt.SortKey()] = tt + tags[tt.GetName()] = tt } } diff --git a/tag/tag.go b/tag/tag.go index 9dd779b..cfb2198 100644 --- a/tag/tag.go +++ b/tag/tag.go @@ -19,7 +19,7 @@ type Tag struct { // SortKey returns a sort key func (tg *Tag) SortKey() string { - return tg.name + return tg.GetCreatedKey() + tg.name } // GetName gets tag name @@ -112,9 +112,9 @@ func New(name, digest string) (*Tag, error) { nil } -func calculateState(sortKey string, registryTags, localTags map[string]*Tag) string { - r, definedInRegistry := registryTags[sortKey] - l, definedLocally := localTags[sortKey] +func calculateState(name string, registryTags, localTags map[string]*Tag) string { + r, definedInRegistry := registryTags[name] + l, definedLocally := localTags[name] if definedInRegistry && !definedLocally { return "ABSENT" @@ -137,35 +137,45 @@ func calculateState(sortKey string, registryTags, localTags map[string]*Tag) str // Join joins local tags with ones from registry, performs state processing and returns: // * sorted slice of sort keys -// * joined map of *tag.Tag -func Join(registryTags, localTags map[string]*Tag) ([]string, map[string]*Tag) { +// * joined map of [sortKey]name +// * joined map of [name]*Tag +func Join(registryTags, localTags map[string]*Tag) ([]string, map[string]string, map[string]*Tag) { sortedKeys := make([]string, 0) + names := make(map[string]string) joinedTags := make(map[string]*Tag) - for sortKey := range registryTags { + for name := range registryTags { + sortKey := registryTags[name].SortKey() + sortedKeys = append(sortedKeys, sortKey) - joinedTags[sortKey] = registryTags[sortKey] + names[sortKey] = name + + joinedTags[name] = registryTags[name] - ltg, defined := localTags[sortKey] + ltg, defined := localTags[name] if defined { - joinedTags[sortKey].SetImageID(ltg.GetImageID()) + joinedTags[name].SetImageID(ltg.GetImageID()) } else { - joinedTags[sortKey].SetImageID("n/a") + joinedTags[name].SetImageID("n/a") } } - for sortKey := range localTags { - _, defined := registryTags[sortKey] + for name := range localTags { + _, defined := registryTags[name] if !defined { + sortKey := localTags[name].SortKey() + sortedKeys = append(sortedKeys, sortKey) - joinedTags[sortKey] = localTags[sortKey] + names[sortKey] = name + + joinedTags[name] = localTags[name] } } - for sortKey, jtg := range joinedTags { + for name, jtg := range joinedTags { jtg.SetState( calculateState( - sortKey, + name, registryTags, localTags, ), @@ -174,5 +184,5 @@ func Join(registryTags, localTags map[string]*Tag) ([]string, map[string]*Tag) { sort.Strings(sortedKeys) - return sortedKeys, joinedTags + return sortedKeys, names, joinedTags } diff --git a/tag/tag_test.go b/tag/tag_test.go index 1175add..3929531 100644 --- a/tag/tag_test.go +++ b/tag/tag_test.go @@ -108,7 +108,7 @@ func localTags() map[string]*Tag { func TestJoinLength(t *testing.T) { const expected = 4 - _, tags := Join(registryTags(), localTags()) + _, _, tags := Join(registryTags(), localTags()) c := len(tags) @@ -129,7 +129,7 @@ func TestJoinDigest(t *testing.T) { "v1.2": "sha256:7f7f94f26d23f7aca80a33732161af068f9f62fbe0e824a58cf3a39d209cfa77", } - _, tags := Join(registryTags(), localTags()) + _, _, tags := Join(registryTags(), localTags()) for name, digest := range expected { if tags[name].GetDigest() != digest { @@ -151,7 +151,7 @@ func TestJoinImageID(t *testing.T) { "v1.2": "4c4ebb9614ef", } - _, tags := Join(registryTags(), localTags()) + _, _, tags := Join(registryTags(), localTags()) for name, imageID := range expected { if tags[name].GetImageID() != imageID { @@ -173,7 +173,7 @@ func TestJoinState(t *testing.T) { "v1.2": "PRESENT", } - _, tags := Join(registryTags(), localTags()) + _, _, tags := Join(registryTags(), localTags()) for name, state := range expected { if tags[name].GetState() != state {