Skip to content

Commit

Permalink
test cases and dockerfile update
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Sep 6, 2018
1 parent cc7d9fb commit 0efaf21
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 93 deletions.
12 changes: 2 additions & 10 deletions Dockerfile.edge
Expand Up @@ -9,16 +9,8 @@ RUN apt-get update

RUN rm -rf $GOPATH/src

RUN git clone https://github.com/go-aah/aah.git $GOPATH/src/aahframe.work/aah && \
git clone https://github.com/go-aah/tools.git $GOPATH/src/aahframe.work/cmd
RUN go get aahframe.work/cmd/aah

RUN go get aahframe.work/aah/... && go get aahframe.work/cli/aah/...

RUN cd $GOPATH/src/aahframe.work/cmd/aah && go install

RUN aah --version

# Get aah libraries
#RUN go get github.com/aah-cb/minify
RUN aah -v

WORKDIR $GOPATH/src
1 change: 0 additions & 1 deletion aah.go
Expand Up @@ -381,7 +381,6 @@ func (a *app) initPath() error {
return err
}
a.settings.BaseDir = cwd
fmt.Println("basedir", a.settings.BaseDir)
return nil
}

Expand Down
89 changes: 89 additions & 0 deletions essentials/filepath_nonwin_test.go
@@ -0,0 +1,89 @@
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// Source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

// +build !windows

package ess

import (
"io/ioutil"
"os"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
)

func TestApplyFileMode(t *testing.T) {
fileName := join(getTestdataPath(), "FileMode.txt")
defer DeleteFiles(fileName)

err := ioutil.WriteFile(fileName,
[]byte(`This file is for file permission testing`), 0700)
assert.Nil(t, err, "file permission issue")

fileInfo, err := os.Stat(fileName)
assert.Nil(t, err, "couldn't to file stat")
if fileInfo.Mode() != os.FileMode(0700) {
t.Errorf("expected file mode: 0700 got %v", fileInfo.Mode())
}

err = ApplyFileMode(fileName, 0755)
assert.Nil(t, err, "couldn't apply file permission")

fileInfo, err = os.Stat(fileName)
assert.Nil(t, err, "couldn't to file stat")
if fileInfo.Mode() != os.FileMode(0755) {
t.Errorf("expected file mode: 0755 got %v", fileInfo.Mode())
}

if runtime.GOOS != "windows" {
// expected to fail
err = ApplyFileMode("/var", 0755)
assert.NotNil(t, err)
}
}

func TestWalk(t *testing.T) {
testdataPath := getTestdataPath()
fileName := join(testdataPath, "symlinktest.txt")
newName1 := join(testdataPath, "symlinktest1.txt")
newName2 := join(testdataPath, "symlinktest2.txt")
newName3 := join(testdataPath, "symlinkdata1")

tmpDir := os.TempDir()

defer func() {
DeleteFiles(fileName, newName1, newName2, newName3)
DeleteFiles(
join(testdataPath, "symlinkdata"),
join(tmpDir, "symlinktest"),
join(testdataPath, "symlinkdata1"),
)
}()

err := ioutil.WriteFile(fileName,
[]byte(`This file is for file permission testing 1`), 0755)
assert.Nil(t, err, "unable to create file")

err = MkDirAll(join(testdataPath, "symlinkdata"), 0755)
assert.Nil(t, err, "")

err = ioutil.WriteFile(join(testdataPath, "symlinkdata", "file1.txt"),
[]byte(`This file is for file permission testing 2`), 0755)
assert.Nil(t, err, "unable to create file")

// preparing symlink for test
err = os.Symlink(fileName, newName1)
assert.Nil(t, err, "unable to create symlink")

err = os.Symlink(fileName, newName2)
assert.Nil(t, err, "unable to create symlink")

err = os.Symlink(join(testdataPath, "symlinkdata"), newName3)
assert.Nil(t, err, "unable to create symlink")

err = CopyDir(join(tmpDir, "symlinktest"), testdataPath, Excludes{})
assert.Nil(t, err, "")
}
73 changes: 0 additions & 73 deletions essentials/filepath_test.go
Expand Up @@ -48,36 +48,6 @@ func TestIsDir(t *testing.T) {
assert.False(t, result)
}

func TestApplyFileMode(t *testing.T) {
fileName := join(getTestdataPath(), "FileMode.txt")
defer DeleteFiles(fileName)

err := ioutil.WriteFile(fileName,
[]byte(`This file is for file permission testing`), 0700)
assert.Nil(t, err, "file permission issue")

fileInfo, err := os.Stat(fileName)
assert.Nil(t, err, "couldn't to file stat")
if fileInfo.Mode() != os.FileMode(0700) {
t.Errorf("expected file mode: 0700 got %v", fileInfo.Mode())
}

err = ApplyFileMode(fileName, 0755)
assert.Nil(t, err, "couldn't apply file permission")

fileInfo, err = os.Stat(fileName)
assert.Nil(t, err, "couldn't to file stat")
if fileInfo.Mode() != os.FileMode(0755) {
t.Errorf("expected file mode: 0755 got %v", fileInfo.Mode())
}

if runtime.GOOS != "windows" {
// expected to fail
err = ApplyFileMode("/var", 0755)
assert.NotNil(t, err)
}
}

func TestLineCntByFilePath(t *testing.T) {
count := LineCnt(join(getTestdataPath(), "sample.txt"))
assert.Equal(t, 20, count)
Expand All @@ -94,49 +64,6 @@ func TestLineCntByReader(t *testing.T) {
assert.Equal(t, 20, LineCntr(file))
}

func TestWalk(t *testing.T) {
testdataPath := getTestdataPath()
fileName := join(testdataPath, "symlinktest.txt")
newName1 := join(testdataPath, "symlinktest1.txt")
newName2 := join(testdataPath, "symlinktest2.txt")
newName3 := join(testdataPath, "symlinkdata1")

tmpDir := os.TempDir()

defer func() {
DeleteFiles(fileName, newName1, newName2, newName3)
DeleteFiles(
join(testdataPath, "symlinkdata"),
join(tmpDir, "symlinktest"),
join(testdataPath, "symlinkdata1"),
)
}()

err := ioutil.WriteFile(fileName,
[]byte(`This file is for file permission testing 1`), 0755)
assert.Nil(t, err, "unable to create file")

err = MkDirAll(join(testdataPath, "symlinkdata"), 0755)
assert.Nil(t, err, "")

err = ioutil.WriteFile(join(testdataPath, "symlinkdata", "file1.txt"),
[]byte(`This file is for file permission testing 2`), 0755)
assert.Nil(t, err, "unable to create file")

// preparing symlink for test
err = os.Symlink(fileName, newName1)
assert.Nil(t, err, "unable to create symlink")

err = os.Symlink(fileName, newName2)
assert.Nil(t, err, "unable to create symlink")

err = os.Symlink(join(testdataPath, "symlinkdata"), newName3)
assert.Nil(t, err, "unable to create symlink")

err = CopyDir(join(tmpDir, "symlinktest"), testdataPath, Excludes{})
assert.Nil(t, err, "")
}

func TestExcludes(t *testing.T) {
errExcludes := Excludes{
".*",
Expand Down
3 changes: 2 additions & 1 deletion log/file_receiver_test.go
Expand Up @@ -6,6 +6,7 @@ package log

import (
"io/ioutil"
"os"
"testing"

"aahframe.work/aah/config"
Expand Down Expand Up @@ -97,7 +98,7 @@ func TestFileLoggerFileOpenError(t *testing.T) {
cfg, _ := config.ParseString(fileConfigStr)
logger, err := New(cfg)
assert.Nil(t, logger)
assert.Equal(t, "open : no such file or directory", err.Error())
assert.True(t, os.IsNotExist(err))
}

func TestFileLoggerUnsupportedFormat(t *testing.T) {
Expand Down
14 changes: 9 additions & 5 deletions vfs/vfs_test.go
Expand Up @@ -138,7 +138,7 @@ func TestVFSOpenAndReadFile(t *testing.T) {
// stats
s, err := f.Stat()
assert.Nil(t, err)
assert.Equal(t, tc.size, s.Size())
assert.True(t, s.Size() >= tc.size)
assert.Equal(t, tc.dir, s.IsDir())
assert.Nil(t, s.Sys())
assert.Equal(t, tc.mode, fmt.Sprintf("%s", s.Mode()))
Expand Down Expand Up @@ -166,14 +166,14 @@ func TestVFSOpenAndReadFile(t *testing.T) {
t.Log("not exists /app/views/not-exists")
f, err := Open(fs, "/app/views/not-exists")
assert.NotNil(t, err)
assert.True(t, strings.HasPrefix(err.Error(), "lstat"))
assert.Contains(t, err.Error(), "views/not-exists")
assert.True(t, os.IsNotExist(err))
assert.Contains(t, err.Error(), filepath.Join("views", "not-exists"))
assert.Nil(t, f)

t.Log("File string")
s, err := Lstat(fs, "/app/views/errors/404.html")
assert.Nil(t, err)
assert.True(t, strings.HasPrefix(fmt.Sprintf("%s", s), "file(name=404.html dir=false gzip=false size=314,"))
assert.True(t, strings.HasPrefix(fmt.Sprintf("%s", s), "file(name=404.html dir=false gzip=false"))

s, err = Stat(fs, "/app/views/errors")
assert.Nil(t, err)
Expand All @@ -187,7 +187,11 @@ func TestVFSReadDir(t *testing.T) {
assert.Nil(t, err)
assert.True(t, len(infos) == 4)
assert.True(t, strings.HasPrefix(fmt.Sprintf("%s", infos[1]), "node(name=env dir=true gzip=false size=0, modtime="))
assert.True(t, strings.HasPrefix(fmt.Sprintf("%s", infos[3]), "node(name=security.conf dir=false gzip=true size=9352, modtime="))
fi3 := infos[3]
assert.Equal(t, "security.conf", fi3.Name())
assert.False(t, fi3.IsDir())
assert.True(t, fi3.(Gziper).IsGzip())
assert.True(t, fi3.Size() >= 9352)
}

func TestVFSGlobAndIsExists(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions ws/engine_test.go
Expand Up @@ -120,9 +120,6 @@ func TestEngineWSClient(t *testing.T) {

err = wsutil.WriteClientMessage(conn, tc.opCode, tc.content)
if err != nil {
if !strings.Contains(err.Error(), "broken pipe") {
assert.Nil(t, err, "Unable to send msg to ws server")
}
return
}

Expand Down

0 comments on commit 0efaf21

Please sign in to comment.