Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Feb 16, 2019
1 parent e313ab6 commit 7368128
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
2 changes: 0 additions & 2 deletions netutil/netutil.go
Expand Up @@ -2,7 +2,6 @@ package netutil

import (
"errors"
"fmt"
"net"
"regexp"
"strconv"
Expand Down Expand Up @@ -86,7 +85,6 @@ func isPrivateIP(ip net.IP) bool {
func ExtractPort(host string) uint {
re := regexp.MustCompile(`(.*:)?(\d+)`)
matches := re.FindStringSubmatch(host)
fmt.Println(matches)
if len(matches) == 0 {
return 0
}
Expand Down
85 changes: 48 additions & 37 deletions registry/registry_test.go
@@ -1,7 +1,6 @@
package registry

import (
"fmt"
"os"
"testing"

Expand All @@ -13,36 +12,6 @@ var (
testImageTar = "hello-world.tar"
)

func init() {
createTestTar()
}

func createTestTar() {
client := createClient()
err := client.PullImage(testImage)
if err != nil {
panic(err)
}

err = client.SaveImageTar(testImage, testImageTar)
if err != nil {
panic(err)
}
}

func createClient() *docker.Client {
return docker.NewClient(nil)
}

func createRegistry() *Registry {
registry := NewRegistry(&Config{
DockerLocalRegistryHost: "docker.localhost:5000",
IPFSHost: "localhost:8080",
})

return registry
}

func TestNew(t *testing.T) {
registry := createRegistry()
if registry == nil {
Expand All @@ -51,7 +20,6 @@ func TestNew(t *testing.T) {
}

func TestPushImage(t *testing.T) {
t.Skip()
registry := createRegistry()
filepath := "hello-world.tar"
reader, err := os.Open(filepath)
Expand All @@ -68,7 +36,6 @@ func TestPushImage(t *testing.T) {
}

func TestPushImageByID(t *testing.T) {
t.Skip()
client := createClient()
err := client.LoadImageByFilePath(testImageTar)
if err != nil {
Expand All @@ -86,18 +53,22 @@ func TestPushImageByID(t *testing.T) {
}

func TestDownloadImage(t *testing.T) {
t.Skip()
registry := createRegistry()
location, err := registry.DownloadImage("QmQuKQ6nmUoFZGKJLHcnqahq2xgq3xbgVsQBG6YL5eF7kh")
ipfsHash, err := registry.PushImageByID(testImage)
if err != nil {
t.Error(err)
}
location, err := registry.DownloadImage(ipfsHash)
if err != nil {
t.Error(err)
}

fmt.Println(location)
if location == "" {
t.Error("expected location")
}
}

func TestPullImage(t *testing.T) {
t.Skip()
client := createClient()
err := client.PullImage(testImage)
if err != nil {
Expand All @@ -115,3 +86,43 @@ func TestPullImage(t *testing.T) {
t.Error(err)
}
}

// last function to run so it cleans up
// the generated test files
func TestCleanup(t *testing.T) {
cleanUp()
}

func cleanUp() {
os.Remove(testImageTar)
}

func createTestTar() {
client := createClient()
err := client.PullImage(testImage)
if err != nil {
panic(err)
}

err = client.SaveImageTar(testImage, testImageTar)
if err != nil {
panic(err)
}
}

func createClient() *docker.Client {
return docker.NewClient(nil)
}

func createRegistry() *Registry {
registry := NewRegistry(&Config{
DockerLocalRegistryHost: "docker.localhost:5000",
IPFSHost: "127.0.0.1:5001",
})

return registry
}

func init() {
createTestTar()
}

0 comments on commit 7368128

Please sign in to comment.