unconvert: remove unnescessary conversions

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-08-07 02:38:51 +02:00
parent 3a16c7246a
commit 2c31edbbb6
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
9 changed files with 19 additions and 21 deletions

View File

@ -40,7 +40,7 @@ func initLoopbacks() error {
// only create new loopback files if they don't exist
if _, err := os.Stat(loopPath); err != nil {
if mkerr := syscall.Mknod(loopPath,
uint32(statT.Mode|syscall.S_IFBLK), int((7<<8)|(i&0xff)|((i&0xfff00)<<12))); mkerr != nil {
uint32(statT.Mode|syscall.S_IFBLK), int((7<<8)|(i&0xff)|((i&0xfff00)<<12))); mkerr != nil { // nolint: unconvert
return mkerr
}
os.Chown(loopPath, int(statT.Uid), int(statT.Gid))

View File

@ -39,7 +39,7 @@ func TestParseInitVersion(t *testing.T) {
}
for _, test := range tests {
version, commit, err := parseInitVersion(string(test.output))
version, commit, err := parseInitVersion(test.output)
if test.invalid {
assert.Check(t, is.ErrorContains(err, ""))
} else {
@ -91,7 +91,7 @@ spec: 1.0.0
}
for _, test := range tests {
version, commit, err := parseRuncVersion(string(test.output))
version, commit, err := parseRuncVersion(test.output)
if test.invalid {
assert.Check(t, is.ErrorContains(err, ""))
} else {

View File

@ -29,15 +29,13 @@ func TestFSGetInvalidData(t *testing.T) {
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
id, err := store.Set([]byte("foobar"))
dgst, err := store.Set([]byte("foobar"))
assert.Check(t, err)
dgst := digest.Digest(id)
err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, string(dgst.Algorithm()), dgst.Hex()), []byte("foobar2"), 0600)
assert.Check(t, err)
_, err = store.Get(id)
_, err = store.Get(dgst)
assert.Check(t, is.ErrorContains(err, "failed to verify"))
}
@ -172,7 +170,7 @@ func TestFSGetSet(t *testing.T) {
})
for _, tc := range tcases {
id, err := store.Set([]byte(tc.input))
id, err := store.Set(tc.input)
assert.Check(t, err)
assert.Check(t, is.Equal(tc.expected, id))
}

View File

@ -6,7 +6,6 @@ import (
"testing"
"github.com/docker/docker/layer"
digest "github.com/opencontainers/go-digest"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
)
@ -60,11 +59,11 @@ func TestRestore(t *testing.T) {
assert.NilError(t, err)
assert.Check(t, cmp.Equal(ID(id1), sid1))
sid1, err = is.Search(digest.Digest(id1).Hex()[:6])
sid1, err = is.Search(id1.Hex()[:6])
assert.NilError(t, err)
assert.Check(t, cmp.Equal(ID(id1), sid1))
invalidPattern := digest.Digest(id1).Hex()[1:6]
invalidPattern := id1.Hex()[1:6]
_, err = is.Search(invalidPattern)
assert.ErrorContains(t, err, "No such image")
}

View File

@ -166,6 +166,7 @@ func getNlink(path string) (uint64, error) {
return 0, fmt.Errorf("expected type *syscall.Stat_t, got %t", stat.Sys())
}
// We need this conversion on ARM64
// nolint: unconvert
return uint64(statT.Nlink), nil
}

View File

@ -323,7 +323,7 @@ func TestNewIDMappings(t *testing.T) {
gids, err := tempUser.GroupIds()
assert.Check(t, err)
group, err := user.LookupGroupId(string(gids[0]))
group, err := user.LookupGroupId(gids[0])
assert.Check(t, err)
idMapping, err := NewIdentityMapping(tempUser.Username, group.Name)

View File

@ -45,7 +45,7 @@ func TestAtomicWriteToFile(t *testing.T) {
if err != nil {
t.Fatalf("Error statting file: %v", err)
}
if expected := os.FileMode(testMode); st.Mode() != expected {
if expected := testMode; st.Mode() != expected {
t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode())
}
}
@ -93,7 +93,7 @@ func TestAtomicWriteSetCommit(t *testing.T) {
if err != nil {
t.Fatalf("Error statting file: %v", err)
}
if expected := os.FileMode(testMode); st.Mode() != expected {
if expected := testMode; st.Mode() != expected {
t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode())
}

View File

@ -28,7 +28,7 @@ func TestChtimesLinux(t *testing.T) {
}
stat := f.Sys().(*syscall.Stat_t)
aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
if aTime != unixEpochTime {
t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
}
@ -42,7 +42,7 @@ func TestChtimesLinux(t *testing.T) {
}
stat = f.Sys().(*syscall.Stat_t)
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
if aTime != unixEpochTime {
t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
}
@ -56,7 +56,7 @@ func TestChtimesLinux(t *testing.T) {
}
stat = f.Sys().(*syscall.Stat_t)
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
if aTime != unixEpochTime {
t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
}
@ -70,7 +70,7 @@ func TestChtimesLinux(t *testing.T) {
}
stat = f.Sys().(*syscall.Stat_t)
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
if aTime != afterUnixEpochTime {
t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime)
}
@ -84,7 +84,7 @@ func TestChtimesLinux(t *testing.T) {
}
stat = f.Sys().(*syscall.Stat_t)
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) {
t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second))
}

View File

@ -9,7 +9,7 @@ import (
func TestRestartManagerTimeout(t *testing.T) {
rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
var duration = time.Duration(1 * time.Second)
var duration = 1 * time.Second
should, _, err := rm.ShouldRestart(0, false, duration)
if err != nil {
t.Fatal(err)
@ -25,7 +25,7 @@ func TestRestartManagerTimeout(t *testing.T) {
func TestRestartManagerTimeoutReset(t *testing.T) {
rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
rm.timeout = 5 * time.Second
var duration = time.Duration(10 * time.Second)
var duration = 10 * time.Second
_, _, err := rm.ShouldRestart(0, false, duration)
if err != nil {
t.Fatal(err)