Skip to content

Commit

Permalink
refactor project structure; use subpackages
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoodman committed Jun 5, 2018
1 parent ed62646 commit d78abce
Show file tree
Hide file tree
Showing 21 changed files with 852 additions and 646 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea
/.idea

# Binaries for programs and plugins
*.exe
Expand All @@ -13,4 +13,7 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

image
/build
/_vendor*
/vendor
/.image
104 changes: 104 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/docker/docker"
version = "1.13.1"

[[constraint]]
name = "github.com/jroimartin/gocui"
# version = "0.3.0"
branch = "master"

[[constraint]]
branch = "master"
name = "golang.org/x/net"

[prune]
go-tests = true
unused-packages = true
46 changes: 34 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
SHELL := /bin/bash
.DEFAULT_GOAL := run
.PHONY: run

run:
go run main.go \
filechangeinfo.go \
filenode.go \
filetree.go \
tar_read.go \
filetreeview.go \
layerview.go
BIN = die

all: clean build

run: build
./build/$(BIN)

build: deps
go build -o build/$(BIN) ./cmd/...

install: deps
go install ./...

deps:
command -v dep >/dev/null || go get -u github.com/golang/dep/cmd/dep
dep ensure

test: build
@! git grep tcell -- ':!tui/' ':!Gopkg.lock' ':!Gopkg.toml' ':!Makefile'
go test -v ./...

lint: lintdeps build
golint -set_exit_status $$(go list ./... | grep -v /vendor/)

lintdeps:
go get -d -v -t ./...
command -v golint >/dev/null || go get -u github.com/golang/lint/golint

clean:
rm -rf build
rm -rf vendor
go clean

.PHONY: build install deps test lint lintdeps clean
25 changes: 25 additions & 0 deletions cmd/die/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"os"
"github.com/wagoodman/docker-image-explorer/image"
"github.com/wagoodman/docker-image-explorer/ui"
)

const name = "die"
const version = "v0.0.0"
const author = "wagoodman"

func main() {
os.Exit(run(os.Args))
}


func run(args []string) int {
image.WriteImage()
manifest, refTrees := image.InitializeData()

ui.Run(manifest, refTrees)
return 0
}

14 changes: 7 additions & 7 deletions filechangeinfo.go → filetree/changeinfo.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main
package filetree

import (
"bytes"
"fmt"
)

type FileChangeInfo struct {
path string
typeflag byte
md5sum [16]byte
diffType DiffType
Path string
Typeflag byte
MD5sum [16]byte
DiffType DiffType
}

type DiffType int
Expand Down Expand Up @@ -51,8 +51,8 @@ func (a *FileChangeInfo) getDiffType(b *FileChangeInfo) DiffType {
if a == nil || b == nil {
return Changed
}
if a.typeflag == b.typeflag {
if bytes.Compare(a.md5sum[:], b.md5sum[:]) == 0 {
if a.Typeflag == b.Typeflag {
if bytes.Compare(a.MD5sum[:], b.MD5sum[:]) == 0 {
return Unchanged
}
}
Expand Down
32 changes: 16 additions & 16 deletions filechangeinfo_test.go → filetree/changeinfo_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main
package filetree

import (
"fmt"
"testing"
)

func TestAssignDiffType(t *testing.T) {
tree := NewTree()
tree := NewFileTree()
tree.AddPath("/usr", BlankFileChangeInfo("/usr", Changed))
if tree.root.children["usr"].data.diffType != Changed {
if tree.Root.Children["usr"].Data.DiffType != Changed {
t.Fail()
}
}
Expand All @@ -29,36 +29,36 @@ func TestMergeDiffTypes(t *testing.T) {
}

func TestDiffTypeFromChildren(t *testing.T) {
tree := NewTree()
tree := NewFileTree()
tree.AddPath("/usr", BlankFileChangeInfo("/usr", Unchanged))
info1 := BlankFileChangeInfo("/usr/bin", Added)
tree.AddPath("/usr/bin", info1)
info2 := BlankFileChangeInfo("/usr/bin2", Removed)
tree.AddPath("/usr/bin2", info2)
tree.root.children["usr"].deriveDiffType(Unchanged)
if tree.root.children["usr"].data.diffType != Changed {
t.Errorf("Expected Changed but got %v", tree.root.children["usr"].data.diffType)
tree.Root.Children["usr"].deriveDiffType(Unchanged)
if tree.Root.Children["usr"].Data.DiffType != Changed {
t.Errorf("Expected Changed but got %v", tree.Root.Children["usr"].Data.DiffType)
}
}

func AssertDiffType(node *FileNode, expectedDiffType DiffType, t *testing.T) error {
if node.data == nil {
t.Errorf("Expected *FileChangeInfo but got nil at path %s", node.Path())
return fmt.Errorf("expected *FileChangeInfo but got nil at path %s", node.Path())
if node.Data == nil {
t.Errorf("Expected *FileChangeInfo but got nil at Path %s", node.Path())
return fmt.Errorf("expected *FileChangeInfo but got nil at Path %s", node.Path())
}
if node.data.diffType != expectedDiffType {
t.Errorf("Expecting node at %s to have DiffType %v, but had %v", node.Path(), expectedDiffType, node.data.diffType)
if node.Data.DiffType != expectedDiffType {
t.Errorf("Expecting node at %s to have DiffType %v, but had %v", node.Path(), expectedDiffType, node.Data.DiffType)
return fmt.Errorf("Assertion failed")
}
return nil
}

func BlankFileChangeInfo(path string, diffType DiffType) (f *FileChangeInfo) {
result := FileChangeInfo{
path: path,
typeflag: 1,
md5sum: [16]byte{1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
diffType: diffType,
Path: path,
Typeflag: 1,
MD5sum: [16]byte{1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
DiffType: diffType,
}
return &result
}
Loading

0 comments on commit d78abce

Please sign in to comment.