airshipui/internal/integrations/ctl/baremetal_test.go
Sirajudeen eadf3ae4ee [airshipui] - create temporary test configs
* Create temporary test configs for testing and
  clean it after the test case executed
* This will allow user to add/modify/delete from the temporary configs,
  instead of working on the original files.

Change-Id: I98e07ee8f6697e5fbcfeaa2223bf0282d7abb0c2
2020-06-26 13:51:52 +00:00

66 lines
1.7 KiB
Go

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ctl
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"opendev.org/airship/airshipui/internal/configs"
)
func TestHandleDefaultBaremetalRequest(t *testing.T) {
initCTL(t)
html, err := GetBaremetalHTML()
require.NoError(t, err)
request := configs.WsMessage{
Type: configs.AirshipCTL,
Component: configs.Baremetal,
SubComponent: configs.GetDefaults,
}
response := HandleBaremetalRequest(request)
expected := configs.WsMessage{
Type: configs.AirshipCTL,
Component: configs.Baremetal,
SubComponent: configs.GetDefaults,
HTML: html,
}
assert.Equal(t, expected, response)
}
func TestHandleUnknownBaremetalSubComponent(t *testing.T) {
request := configs.WsMessage{
Type: configs.AirshipCTL,
Component: configs.Baremetal,
SubComponent: "fake_subcomponent",
}
response := HandleBaremetalRequest(request)
expected := configs.WsMessage{
Type: configs.AirshipCTL,
Component: configs.Baremetal,
SubComponent: "fake_subcomponent",
Error: "Subcomponent fake_subcomponent not found",
}
assert.Equal(t, expected, response)
}