Skip to content

Commit

Permalink
server: fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Moreno <[email protected]>
  • Loading branch information
amorenoz committed Nov 23, 2020
1 parent 1e342ff commit eefbb48
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/resources/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
. "github.com/stretchr/testify/mock"
)

var _ = Describe("Server", func() {
Expand Down Expand Up @@ -71,6 +72,8 @@ var _ = Describe("Server", func() {

if shouldRunServer {
if shouldEnablePluginWatch {
rp.On("StoreDeviceInfoFile", AnythingOfType("string")).Return(nil)
rp.On("CleanDeviceInfoFile", AnythingOfType("string")).Return(nil)
rs.Start()
} else {
os.MkdirAll(pluginapi.DevicePluginPath, 0755)
Expand Down Expand Up @@ -140,6 +143,8 @@ var _ = Describe("Server", func() {
On("GetDevices").Return(map[string]*pluginapi.Device{}).
On("Probe").Return(true)
fs = &utils.FakeFilesystem{}
rp.On("StoreDeviceInfoFile", AnythingOfType("string")).Return(nil)
rp.On("CleanDeviceInfoFile", AnythingOfType("string")).Return(nil)
})
Context("starting, restarting and stopping the resource server", func() {
It("should not fail and messages should be received on the channels", func(done Done) {
Expand All @@ -153,6 +158,7 @@ var _ = Describe("Server", func() {
registrationServer := createFakeRegistrationServer(fs.RootDir,
"fake_fake.com.fake", false, false)
os.MkdirAll(pluginapi.DevicePluginPath, 0755)

registrationServer.start()
defer registrationServer.stop()

Expand Down Expand Up @@ -180,6 +186,10 @@ var _ = Describe("Server", func() {
// Create ResourceServer with plugin watch mode enabled
rs := NewResourceServer("fake", "fake", true, &rp).(*resourceServer)

// Starting server should trigger a call to StoreDeviceInfoFile and CleanDeviceInfoFile
rp.On("StoreDeviceInfoFile", AnythingOfType("string")).Return(nil)
rp.On("CleanDeviceInfoFile", AnythingOfType("string")).Return(nil)

registrationServer := createFakeRegistrationServer(fs.RootDir,
"fake_fake.com.fake", false, true)
err := rs.Start()
Expand All @@ -189,6 +199,7 @@ var _ = Describe("Server", func() {
Expect(err).NotTo(HaveOccurred())

go func() {
rp.On("CleanDeviceInfoFile", AnythingOfType("string")).Return(nil)
err := rs.Stop()
Expect(err).NotTo(HaveOccurred())
}()
Expand All @@ -206,6 +217,10 @@ var _ = Describe("Server", func() {
// Create ResourceServer with plugin watch mode disabled
rs := NewResourceServer("fake.com", "fake", false, &rp).(*resourceServer)

// Starting server should trigger a call to StoreDeviceInfoFile and CleanDeviceInfoFile
rp.On("StoreDeviceInfoFile", AnythingOfType("string")).Return(nil)
rp.On("CleanDeviceInfoFile", AnythingOfType("string")).Return(nil)

registrationServer := createFakeRegistrationServer(fs.RootDir,
"fake_fake.com.fake", false, false)
os.MkdirAll(pluginapi.DevicePluginPath, 0755)
Expand Down

0 comments on commit eefbb48

Please sign in to comment.