2020-04-01 09:55:42 -05:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2019-10-02 11:05:59 -05:00
|
|
|
package util_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-10-16 16:42:01 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-10-02 11:05:59 -05:00
|
|
|
"opendev.org/airship/airshipctl/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReadYAMLFile(t *testing.T) {
|
2019-10-16 16:42:01 -05:00
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
2019-10-02 11:05:59 -05:00
|
|
|
var actual map[string]interface{}
|
2019-10-16 16:42:01 -05:00
|
|
|
err := util.ReadYAMLFile("testdata/test.yaml", &actual)
|
|
|
|
require.NoError(err, "Error while reading YAML")
|
|
|
|
|
|
|
|
actualString := actual["testString"]
|
2019-10-02 11:05:59 -05:00
|
|
|
expectedString := "test"
|
2019-10-16 16:42:01 -05:00
|
|
|
assert.Equal(expectedString, actualString)
|
2020-03-14 21:02:55 -05:00
|
|
|
|
|
|
|
// test using an incorrect yaml
|
|
|
|
err = util.ReadYAMLFile("testdata/incorrect.yaml", &actual)
|
|
|
|
expectedString = "error converting YAML to JSON"
|
|
|
|
require.Contains(err.Error(), expectedString)
|
2019-10-02 11:05:59 -05:00
|
|
|
}
|