[lxc-devel] [lxd/master] Windows/MacOS test fixes
stgraber on Github
lxc-bot at linuxcontainers.org
Mon Oct 17 21:45:24 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161017/703b88fc/attachment.bin>
-------------- next part --------------
From 1055ac3d1e69276f315461c514c5ad332a490d98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 17 Oct 2016 17:22:20 -0400
Subject: [PATCH 1/3] travis: Run the client tests
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
.travis.yml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index 5380396..d78cf8a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -19,6 +19,9 @@ install:
script:
- "make client"
+ - "go test ./"
+ - "go test ./shared"
+ - "go test ./lxc"
notifications:
webhooks: https://linuxcontainers.org/webhook-lxcbot/
From 6d4a505a9568029812a55bb8434719bf58a556b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 17 Oct 2016 17:32:04 -0400
Subject: [PATCH 2/3] Fix tests of client on Windows
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #2449
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
client_test.go | 52 ---------------------------------------------------
client_unix_test.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 52 deletions(-)
delete mode 100644 client_test.go
create mode 100644 client_unix_test.go
diff --git a/client_test.go b/client_test.go
deleted file mode 100644
index e7b12a0..0000000
--- a/client_test.go
+++ /dev/null
@@ -1,52 +0,0 @@
-package lxd
-
-import (
- "fmt"
- "io/ioutil"
- "os"
- "syscall"
- "testing"
-)
-
-func assertNoError(t *testing.T, err error, msg string) {
- if err != nil {
- t.Fatalf("Error: %s, action: %s", err, msg)
- }
-}
-
-func TestLocalLXDError(t *testing.T) {
- f, err := ioutil.TempFile("", "lxd-test.socket")
- assertNoError(t, err, "ioutil.TempFile to create fake socket file")
- defer os.RemoveAll(f.Name())
-
- c := &Client{
- Name: "test",
- Config: DefaultConfig,
- Remote: &RemoteConfig{
- Addr: fmt.Sprintf("unix:%s", f.Name()),
- Static: true,
- Public: false,
- },
- }
- runTest := func(exp error) {
- lxdErr := GetLocalLXDErr(connectViaUnix(c, c.Remote))
- if lxdErr != exp {
- t.Fatalf("GetLocalLXDErr returned the wrong error, EXPECTED: %s, ACTUAL: %s", exp, lxdErr)
- }
- }
-
- // The fake socket file should mimic a socket with nobody listening.
- runTest(syscall.ECONNREFUSED)
-
- // Remove R/W permissions to mimic the user not having lxd group permissions.
- // Skip this test for root, as root ignores permissions and connect will fail
- // with ECONNREFUSED instead of EACCES.
- if os.Geteuid() != 0 {
- assertNoError(t, f.Chmod(0100), "f.Chmod on fake socket file")
- runTest(syscall.EACCES)
- }
-
- // Remove the fake socket to mimic LXD not being installed.
- assertNoError(t, os.RemoveAll(f.Name()), "osRemoveAll on fake socket file")
- runTest(syscall.ENOENT)
-}
diff --git a/client_unix_test.go b/client_unix_test.go
new file mode 100644
index 0000000..157d8c5
--- /dev/null
+++ b/client_unix_test.go
@@ -0,0 +1,54 @@
+// +build !windows
+
+package lxd
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "syscall"
+ "testing"
+)
+
+func assertNoError(t *testing.T, err error, msg string) {
+ if err != nil {
+ t.Fatalf("Error: %s, action: %s", err, msg)
+ }
+}
+
+func TestLocalLXDError(t *testing.T) {
+ f, err := ioutil.TempFile("", "lxd-test.socket")
+ assertNoError(t, err, "ioutil.TempFile to create fake socket file")
+ defer os.RemoveAll(f.Name())
+
+ c := &Client{
+ Name: "test",
+ Config: DefaultConfig,
+ Remote: &RemoteConfig{
+ Addr: fmt.Sprintf("unix:%s", f.Name()),
+ Static: true,
+ Public: false,
+ },
+ }
+ runTest := func(exp error) {
+ lxdErr := GetLocalLXDErr(connectViaUnix(c, c.Remote))
+ if lxdErr != exp {
+ t.Fatalf("GetLocalLXDErr returned the wrong error, EXPECTED: %s, ACTUAL: %s", exp, lxdErr)
+ }
+ }
+
+ // The fake socket file should mimic a socket with nobody listening.
+ runTest(syscall.ECONNREFUSED)
+
+ // Remove R/W permissions to mimic the user not having lxd group permissions.
+ // Skip this test for root, as root ignores permissions and connect will fail
+ // with ECONNREFUSED instead of EACCES.
+ if os.Geteuid() != 0 {
+ assertNoError(t, f.Chmod(0100), "f.Chmod on fake socket file")
+ runTest(syscall.EACCES)
+ }
+
+ // Remove the fake socket to mimic LXD not being installed.
+ assertNoError(t, os.RemoveAll(f.Name()), "osRemoveAll on fake socket file")
+ runTest(syscall.ENOENT)
+}
From d6087bda79e996282e6b14001f6f7bf5eba61d48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 17 Oct 2016 17:36:26 -0400
Subject: [PATCH 3/3] shared: Move Linux specific tests away
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #2449
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
shared/util_linux_test.go | 141 ++++++++++++++++++++++++++++++++++++++++++++++
shared/util_test.go | 133 -------------------------------------------
2 files changed, 141 insertions(+), 133 deletions(-)
create mode 100644 shared/util_linux_test.go
diff --git a/shared/util_linux_test.go b/shared/util_linux_test.go
new file mode 100644
index 0000000..11b1ebb
--- /dev/null
+++ b/shared/util_linux_test.go
@@ -0,0 +1,141 @@
+package shared
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "strings"
+ "syscall"
+ "testing"
+)
+
+func TestGetAllXattr(t *testing.T) {
+ var (
+ err error
+ testxattr = map[string]string{
+ "user.checksum": "asdfsf13434qwf1324",
+ "user.random": "This is a test",
+ }
+ )
+ xattrFile, err := ioutil.TempFile("", "")
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ defer os.Remove(xattrFile.Name())
+ xattrFile.Close()
+
+ xattrDir, err := ioutil.TempDir("", "")
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ defer os.Remove(xattrDir)
+
+ for k, v := range testxattr {
+ err = syscall.Setxattr(xattrFile.Name(), k, []byte(v), 0)
+ if err == syscall.ENOTSUP {
+ t.Log(err)
+ return
+ }
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ err = syscall.Setxattr(xattrDir, k, []byte(v), 0)
+ if err == syscall.ENOTSUP {
+ t.Log(err)
+ return
+ }
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ }
+
+ // Test retrieval of extended attributes for regular files.
+ h, err := GetAllXattr(xattrFile.Name())
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ if h == nil {
+ t.Errorf("Expected to find extended attributes but did not find any.")
+ return
+ }
+
+ for k, v := range h {
+ found, ok := h[k]
+ if !ok || found != testxattr[k] {
+ t.Errorf("Expected to find extended attribute %s with a value of %s on regular file but did not find it.", k, v)
+ return
+ }
+ }
+
+ // Test retrieval of extended attributes for directories.
+ h, err = GetAllXattr(xattrDir)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ if h == nil {
+ t.Errorf("Expected to find extended attributes but did not find any.")
+ return
+ }
+
+ for k, v := range h {
+ found, ok := h[k]
+ if !ok || found != testxattr[k] {
+ t.Errorf("Expected to find extended attribute %s with a value of %s on directory but did not find it.", k, v)
+ return
+ }
+ }
+}
+
+func TestReadLastNLines(t *testing.T) {
+ source, err := ioutil.TempFile("", "")
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ defer os.Remove(source.Name())
+
+ for i := 0; i < 50; i++ {
+ fmt.Fprintf(source, "%d\n", i)
+ }
+
+ lines, err := ReadLastNLines(source, 100)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ split := strings.Split(lines, "\n")
+ for i := 0; i < 50; i++ {
+ if fmt.Sprintf("%d", i) != split[i] {
+ t.Error(fmt.Sprintf("got %s expected %d", split[i], i))
+ return
+ }
+ }
+
+ source.Seek(0, 0)
+ for i := 0; i < 150; i++ {
+ fmt.Fprintf(source, "%d\n", i)
+ }
+
+ lines, err = ReadLastNLines(source, 100)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ split = strings.Split(lines, "\n")
+ for i := 0; i < 100; i++ {
+ if fmt.Sprintf("%d", i+50) != split[i] {
+ t.Error(fmt.Sprintf("got %s expected %d", split[i], i))
+ return
+ }
+ }
+}
diff --git a/shared/util_test.go b/shared/util_test.go
index c469846..458c8fc 100644
--- a/shared/util_test.go
+++ b/shared/util_test.go
@@ -6,96 +6,9 @@ import (
"fmt"
"io/ioutil"
"os"
- "strings"
- "syscall"
"testing"
)
-func TestGetAllXattr(t *testing.T) {
- var (
- err error
- testxattr = map[string]string{
- "user.checksum": "asdfsf13434qwf1324",
- "user.random": "This is a test",
- }
- )
- xattrFile, err := ioutil.TempFile("", "")
- if err != nil {
- t.Error(err)
- return
- }
- defer os.Remove(xattrFile.Name())
- xattrFile.Close()
-
- xattrDir, err := ioutil.TempDir("", "")
- if err != nil {
- t.Error(err)
- return
- }
- defer os.Remove(xattrDir)
-
- for k, v := range testxattr {
- err = syscall.Setxattr(xattrFile.Name(), k, []byte(v), 0)
- if err == syscall.ENOTSUP {
- t.Log(err)
- return
- }
- if err != nil {
- t.Error(err)
- return
- }
- err = syscall.Setxattr(xattrDir, k, []byte(v), 0)
- if err == syscall.ENOTSUP {
- t.Log(err)
- return
- }
- if err != nil {
- t.Error(err)
- return
- }
- }
-
- // Test retrieval of extended attributes for regular files.
- h, err := GetAllXattr(xattrFile.Name())
- if err != nil {
- t.Error(err)
- return
- }
-
- if h == nil {
- t.Errorf("Expected to find extended attributes but did not find any.")
- return
- }
-
- for k, v := range h {
- found, ok := h[k]
- if !ok || found != testxattr[k] {
- t.Errorf("Expected to find extended attribute %s with a value of %s on regular file but did not find it.", k, v)
- return
- }
- }
-
- // Test retrieval of extended attributes for directories.
- h, err = GetAllXattr(xattrDir)
- if err != nil {
- t.Error(err)
- return
- }
-
- if h == nil {
- t.Errorf("Expected to find extended attributes but did not find any.")
- return
- }
-
- for k, v := range h {
- found, ok := h[k]
- if !ok || found != testxattr[k] {
- t.Errorf("Expected to find extended attribute %s with a value of %s on directory but did not find it.", k, v)
- return
- }
- }
-}
-
func TestFileCopy(t *testing.T) {
helloWorld := []byte("hello world\n")
source, err := ioutil.TempFile("", "")
@@ -143,52 +56,6 @@ func TestFileCopy(t *testing.T) {
}
}
-func TestReadLastNLines(t *testing.T) {
- source, err := ioutil.TempFile("", "")
- if err != nil {
- t.Error(err)
- return
- }
- defer os.Remove(source.Name())
-
- for i := 0; i < 50; i++ {
- fmt.Fprintf(source, "%d\n", i)
- }
-
- lines, err := ReadLastNLines(source, 100)
- if err != nil {
- t.Error(err)
- return
- }
-
- split := strings.Split(lines, "\n")
- for i := 0; i < 50; i++ {
- if fmt.Sprintf("%d", i) != split[i] {
- t.Error(fmt.Sprintf("got %s expected %d", split[i], i))
- return
- }
- }
-
- source.Seek(0, 0)
- for i := 0; i < 150; i++ {
- fmt.Fprintf(source, "%d\n", i)
- }
-
- lines, err = ReadLastNLines(source, 100)
- if err != nil {
- t.Error(err)
- return
- }
-
- split = strings.Split(lines, "\n")
- for i := 0; i < 100; i++ {
- if fmt.Sprintf("%d", i+50) != split[i] {
- t.Error(fmt.Sprintf("got %s expected %d", split[i], i))
- return
- }
- }
-}
-
func TestReaderToChannel(t *testing.T) {
buf := make([]byte, 1*1024*1024)
rand.Read(buf)
More information about the lxc-devel
mailing list