Skip to content

Commit

Permalink
use sub tests (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Nov 26, 2018
1 parent b86b3b0 commit 91c114b
Showing 1 changed file with 61 additions and 76 deletions.
137 changes: 61 additions & 76 deletions gluster/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package integration
import (
"bytes"
"fmt"
"math/rand"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -131,97 +133,80 @@ func TestIntegration(t *testing.T) {
//Startplugin with empty config
go setupPlugin()
time.Sleep(3 * timeInterval)

IPs := getGlusterClusterContainersIPs()

logrus.Print(cmd("docker", "volume", "create", "--driver", gluster.PluginAlias, "--opt", "voluri=\""+IPs[0]+":test-replica\"", "replica"))
time.Sleep(timeInterval)
logrus.Print(cmd("docker", "volume", "create", "--driver", gluster.PluginAlias, "--opt", "voluri=\""+IPs[0]+":test-distributed\"", "distributed"))
time.Sleep(timeInterval)
logrus.Print(cmd("docker", "volume", "create", "--driver", gluster.PluginAlias, "--opt", "voluri=\""+IPs[0]+","+IPs[1]+":test-replica\"", "replica-double-server"))
time.Sleep(timeInterval)
logrus.Print(cmd("docker", "volume", "create", "--driver", gluster.PluginAlias, "--opt", "voluri=\""+IPs[0]+","+IPs[1]+":test-distributed\"", "distributed-double-server"))
time.Sleep(timeInterval)
logrus.Print(cmd("docker", "volume", "ls"))
time.Sleep(3 * timeInterval)
//TODO docker volume create --driver sapk/plugin-gluster --opt voluri="<volumeserver>:<volumename>" --name test

out, err := cmd("docker", "run", "--rm", "-t", "-v", "replica:/mnt", "alpine", "/bin/ls", "/mnt")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to list mounted volume : %v", err)
}
out, err = cmd("docker", "run", "--rm", "-t", "-v", "replica:/mnt", "alpine", "/bin/cp", "/etc/hostname", "/mnt/container")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to write inside mounted volume : %v", err)
testCases := []struct {
id string
name string
volume string
servers []string
hostname string
}{
{strconv.Itoa(rand.Int()), "replica", "test-replica", IPs[:1], ""},
{strconv.Itoa(rand.Int()), "distributed", "test-distributed", IPs[:1], ""},
{strconv.Itoa(rand.Int()), "replica-double-server", "test-replica", IPs[:2], ""},
{strconv.Itoa(rand.Int()), "distributed-double-server", "test-distributed", IPs[:2], ""},
}
outReplicaContainer, err := cmd("docker", "run", "--rm", "-t", "-v", "replica:/mnt", "alpine", "/bin/cat", "/mnt/container")
logrus.Println(outReplicaContainer)
if err != nil {
t.Errorf("Failed to read from mounted volume : %v", err)
}
time.Sleep(3 * timeInterval)

out, err = cmd("docker", "run", "--rm", "-t", "-v", "distributed:/mnt", "alpine", "/bin/ls", "/mnt")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to list mounted volume : %v", err)
for _, tc := range testCases {
t.Run("Create volume for "+tc.name, func(t *testing.T) {
logrus.Print(cmd("docker", "volume", "create", "--driver", gluster.PluginAlias, "--opt", "voluri=\""+strings.Join(tc.servers, ",")+":"+tc.volume+"\"", tc.id))
time.Sleep(timeInterval)
})
time.Sleep(3 * timeInterval)
//TODO test volume exist
}
out, err = cmd("docker", "run", "--rm", "-t", "-v", "distributed:/mnt", "alpine", "/bin/cp", "/etc/hostname", "/mnt/container")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to write inside mounted volume : %v", err)
}
outDistributedContainer, err := cmd("docker", "run", "--rm", "-t", "-v", "distributed:/mnt", "alpine", "/bin/cat", "/mnt/container")
logrus.Println(outDistributedContainer)
if err != nil {
t.Errorf("Failed to read from mounted volume : %v", err)
}
time.Sleep(3 * timeInterval)

out, err = cmd("docker", "run", "--rm", "-t", "-v", "replica-double-server:/mnt", "alpine", "/bin/ls", "/mnt")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to list mounted volume (with fallback) : %v", err)
}
out, err = cmd("docker", "run", "--rm", "-t", "-v", "replica-double-server:/mnt", "alpine", "/bin/cat", "/mnt/container")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to read from mounted volume (with fallback) : %v", err)
}
if outReplicaContainer != out {
t.Errorf("Content inside gluster replica volume in not the same : %s != %s", outReplicaContainer, out)
}
logrus.Print(cmd("docker", "volume", "ls"))

out, err = cmd("docker", "run", "--rm", "-t", "-v", "distributed-double-server:/mnt", "alpine", "/bin/ls", "/mnt")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to list mounted volume (with fallback) : %v", err)
}
out, err = cmd("docker", "run", "--rm", "-t", "-v", "distributed-double-server:/mnt", "alpine", "/bin/cat", "/mnt/container")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to read from mounted volume (with fallback) : %v", err)
}
if outDistributedContainer != out {
t.Errorf("Content inside gluster distributed volume in not the same : %s != %s", outDistributedContainer, out)
for i, tc := range testCases {
t.Run("Test volume "+tc.name, func(t *testing.T) {
out, err := cmd("docker", "run", "--rm", "-t", "-v", tc.id+":/mnt", "alpine", "/bin/ls", "/mnt")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to list mounted volume : %v", err)
}
out, err = cmd("docker", "run", "--rm", "-t", "-v", tc.id+":/mnt", "alpine", "/bin/cp", "/etc/hostname", "/mnt/container")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to write inside mounted volume : %v", err)
}
testCases[i].hostname, err = cmd("docker", "run", "--rm", "-t", "-v", tc.id+":/mnt", "alpine", "/bin/cat", "/mnt/container")
logrus.Println(out)
if err != nil {
t.Errorf("Failed to read from mounted volume : %v", err)
}
time.Sleep(3 * timeInterval)
//TODO check content is same
})
}

for _, tc := range testCases {
for _, td := range testCases {
if tc.volume == td.volume {
t.Run(fmt.Sprintf("Test same volume data between %s and %s", tc.name, td.name), func(t *testing.T) {
if tc.hostname != td.hostname {
t.Errorf("Content inside gluster %s volume in not the same : %s != %s", tc.volume, tc.hostname, td.hostname)
}
})
}
}
}
//TODO check persistence

//TODO sub tests
for _, vol := range []string{"distributed-double-server", "replica-double-server", "distributed", "replica"} {
out, err = cmd("docker", "volume", "rm", vol)
for _, tc := range testCases {
out, err := cmd("docker", "volume", "rm", tc.id)
if err != nil {
t.Errorf("Failed to remove mounted volume %s : %v", vol, err)
t.Errorf("Failed to remove mounted volume %s (%s) : %v", tc.name, tc.id, err)
}
if !strings.Contains(out, vol) { //TODO should be only "vol\n"
t.Errorf("Failed to remove mounted volume %s", vol)
if !strings.Contains(out, tc.id) { //TODO should be only "vol\n"
t.Errorf("Failed to remove mounted volume %s (%s)", tc.name, tc.id)
}
out, err = cmd("docker", "volume", "ls", "-q")
if strings.Contains(out, vol) { //TODO should be "vol\n" to limit confussion ith other volume existing or generate name
t.Errorf("Failed to remove volume %s from volume list", vol)
if strings.Contains(out, tc.id) { //TODO should be "vol\n" to limit confussion ith other volume existing or generate name
t.Errorf("Failed to remove volume %s (%s) from volume list", tc.name, tc.id)
}
time.Sleep(3 * timeInterval)
}

}

0 comments on commit 91c114b

Please sign in to comment.