-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Luis Gustavo S. Barreto <gustavo@ossystems.com.br>
- Loading branch information
1 parent
9f213b7
commit 18f06bd
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* UpdateHub | ||
* Copyright (C) 2018 | ||
* O.S. Systems Sofware LTDA: contato@ossystems.com.br | ||
* | ||
* SPDX-License-Identifier: GPL-2.0 | ||
*/ | ||
|
||
package mender | ||
|
||
import ( | ||
"github.com/spf13/afero" | ||
|
||
"github.com/updatehub/updatehub/installmodes" | ||
"github.com/updatehub/updatehub/metadata" | ||
) | ||
|
||
func init() { | ||
installmodes.RegisterInstallMode(installmodes.InstallMode{ | ||
Name: "mender", | ||
CheckRequirements: func() error { return nil }, | ||
GetObject: func() interface{} { | ||
return &MenderObject{} | ||
}, | ||
}) | ||
} | ||
|
||
// MenderObject encapsulates the "mender" handler data and functions | ||
type MenderObject struct { | ||
metadata.ObjectMetadata | ||
// FileSystemBackend afero.Fs | ||
} | ||
|
||
// Setup implementation for the "mender" handler | ||
func (m *MenderObject) Setup() error { | ||
return nil | ||
} | ||
|
||
// Install implementation for the "mender" handler | ||
func (m *MenderObject) Install(downloadDir string) error { | ||
return nil | ||
} | ||
|
||
// Cleanup implementation for the "mender" handler | ||
func (m *MenderObject) Cleanup() error { | ||
return nil | ||
} | ||
|
||
// GetTarget implementation for the "mender" handler | ||
func (m *MenderObject) GetTarget() string { | ||
return "" | ||
} | ||
|
||
// SetupTarget implementation for the "mender" handler | ||
func (m *MenderObject) SetupTarget(target afero.File) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* UpdateHub | ||
* Copyright (C) 2017 | ||
* O.S. Systems Sofware LTDA: contato@ossystems.com.br | ||
* | ||
* SPDX-License-Identifier: GPL-2.0 | ||
*/ | ||
|
||
package mender | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/updatehub/updatehub/installmodes" | ||
"github.com/updatehub/updatehub/testsmocks/filemock" | ||
"github.com/updatehub/updatehub/testsmocks/filesystemmock" | ||
) | ||
|
||
func TestMenderInit(t *testing.T) { | ||
val, err := installmodes.GetObject("mender") | ||
assert.NoError(t, err) | ||
|
||
r1, ok := val.(*MenderObject) | ||
if !ok { | ||
t.Error("Failed to cast return value of \"installmodes.GetObject()\" to MenderObject") | ||
} | ||
|
||
r2 := &MenderObject{} | ||
|
||
assert.Equal(t, r2, r1) | ||
} | ||
|
||
func TestMenderSetupWithSuccess(t *testing.T) { | ||
r := MenderObject{} | ||
err := r.Setup() | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestMenderInstallWithSuccess(t *testing.T) { | ||
r := MenderObject{} | ||
|
||
err := r.Install("") | ||
|
||
assert.NoError(t, err) | ||
} | ||
|
||
func TestMenderSetupTarget(t *testing.T) { | ||
r := MenderObject{} | ||
|
||
targetMock := &filemock.FileMock{} | ||
fsbm := &filesystemmock.FileSystemBackendMock{} | ||
fsbm.On("OpenFile", "/target", os.O_RDONLY, os.FileMode(0)).Return(targetMock, nil) | ||
|
||
target, err := fsbm.OpenFile("/target", os.O_RDONLY, 0) | ||
assert.NoError(t, err) | ||
|
||
r.SetupTarget(target) | ||
} | ||
|
||
func TestMenderCleanupNil(t *testing.T) { | ||
r := MenderObject{} | ||
assert.Nil(t, r.Cleanup()) | ||
} |