Skip to content

Commit

Permalink
Increase test coverage and add integration tests against mount point …
Browse files Browse the repository at this point in the history
…not supporting quotas (#4)

Increase test coverage and add integration tests against mount point not supporting quotas
  • Loading branch information
speijnik committed Apr 3, 2018
1 parent 747d6be commit d20d6e5
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 67 deletions.
16 changes: 12 additions & 4 deletions .circleci/prepare_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ set -e
# Prepare environment for quota support
apt-get update
apt-get install -y quota
truncate -s1G /tmp/test.ext4
mkfs.ext4 -F /tmp/test.ext4
mkdir -p /mnt/quota_test
mount -o usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv1 /tmp/test.ext4 /mnt/quota_test
truncate -s1G /tmp/quotas_enabled.ext4
truncate -s1G /tmp/quotas_disabled.ext4
mkfs.ext4 -F /tmp/quotas_enabled.ext4
mkfs.ext4 -F /tmp/quotas_disabled.ext4
mkdir -p /mnt/quota_test /mnt/noquota_test
mount -o usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv1 /tmp/quotas_enabled.ext4 /mnt/quota_test
mount /tmp/quotas_disabled.ext4 /mnt/noquota_test
quotacheck -vucm /mnt/quota_test
quotacheck -vugm /mnt/quota_test
quotaon -v /mnt/quota_test
for i in {10000..10009}
do
addgroup --gid $i test$i
adduser --system --shell /bin/false --no-create-home --uid $i --gid $i --disabled-login --disabled-password test$i
done
4 changes: 3 additions & 1 deletion .circleci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ mkdir -p $GOPATH/src/github.com/anexia-it
cp -r /home/circleci/project/ $GOPATH/src/github.com/anexia-it/fsquota
cd $GOPATH/src/github.com/anexia-it/fsquota

TEST_MOUNTPOINT=/mnt/quota_test go test -v --covermode=atomic --coverprofile=/home/circleci/project/coverage.txt .
export TEST_MOUNTPOINT_QUOTAS_ENABLED=/mnt/quota_test
export TEST_MOUNTPOINT_QUOTAS_DISABLED=/mnt/noquota_test
go test -v --covermode=atomic --coverprofile=/home/circleci/project/coverage.txt .
chmod 0644 /home/circleci/project/coverage.txt
10 changes: 7 additions & 3 deletions fsquota_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (n nextdqblk) toDqblk() *dqblk {
}

func getReportByNextQuota(t quotaCtlType, device string) (report *Report, err error) {
report = &Report{
rep := &Report{
Infos: make(map[string]*Info),
}

Expand All @@ -232,10 +232,14 @@ func getReportByNextQuota(t quotaCtlType, device string) (report *Report, err er
break
}

report.Infos[fmt.Sprint(nextQuotaInfoStruct.dqbId)] = nextQuotaInfoStruct.toDqblk().toInfo()
rep.Infos[fmt.Sprint(nextQuotaInfoStruct.dqbId)] = nextQuotaInfoStruct.toDqblk().toInfo()
nextId += 1
}

if err == nil {
report = rep
}

return
}

Expand Down Expand Up @@ -274,7 +278,7 @@ func quotasSupported(t quotaCtlType, path string) (supported bool, err error) {
return
}

if _, err = internalGetQuota(groupQuota, device, 0); err == nil {
if _, err = internalGetQuota(t, device, 0); err == nil {
supported = true
}

Expand Down
76 changes: 76 additions & 0 deletions info_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package fsquota

import (
"testing"

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

func TestInfoIsEmpty(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
i := Info{}
assert.True(t, i.isEmpty())
})

t.Run("BytesSoftSet", func(t *testing.T) {
l := uint64(1)
i := Info{
Limits: Limits{
Bytes: Limit{
soft: &l,
},
},
}
assert.False(t, i.isEmpty())
})

t.Run("BytesHardSet", func(t *testing.T) {
l := uint64(1)
i := Info{
Limits: Limits{
Bytes: Limit{
hard: &l,
},
},
}
assert.False(t, i.isEmpty())
})

t.Run("BytesUsedSet", func(t *testing.T) {
i := Info{
BytesUsed: 1,
}
assert.False(t, i.isEmpty())
})

t.Run("FilesSoftSet", func(t *testing.T) {
l := uint64(1)
i := Info{
Limits: Limits{
Files: Limit{
soft: &l,
},
},
}
assert.False(t, i.isEmpty())
})

t.Run("FilesHardSet", func(t *testing.T) {
l := uint64(1)
i := Info{
Limits: Limits{
Files: Limit{
hard: &l,
},
},
}
assert.False(t, i.isEmpty())
})

t.Run("FilesUsedSet", func(t *testing.T) {
i := Info{
FilesUsed: 1,
}
assert.False(t, i.isEmpty())
})
}
Loading

0 comments on commit d20d6e5

Please sign in to comment.