2 ==================================================================================
3 Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 ==================================================================================
26 "github.com/stretchr/testify/assert"
29 func TestParseConfigFile(t *testing.T) {
30 chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
31 config, err := chartBuilder.parseConfigFile("data/sample_config.json")
34 assert.NotEmpty(t, config)
37 func TestParseSchemaFile(t *testing.T) {
38 chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
39 schema, err := chartBuilder.parseSchemaFile("data/sample_schema.json")
42 assert.NotEmpty(t, schema)
45 func TestHelmLint(t *testing.T) {
46 chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
47 err := chartBuilder.helmLint()
52 func TestAppendConfigToValuesYaml(t *testing.T) {
53 chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
55 err := chartBuilder.appendConfigToValuesYaml()
60 func TestChangeChartNameVersion(t *testing.T) {
61 chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
62 err := chartBuilder.changeChartNameVersion()
67 func TestPackageChart(t *testing.T) {
68 chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
69 err := chartBuilder.PackageChart()
74 func TestCopyFile(t *testing.T) {
75 chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
76 SRC_FILE := "data/sample_config.json"
77 DEST_FILE := "data/sample_config_copy.json"
78 err := chartBuilder.copyFile(SRC_FILE, DEST_FILE)
79 defer os.RemoveAll(DEST_FILE)
83 srcBytes, _ := ioutil.ReadFile(SRC_FILE)
84 destBytes, _ := ioutil.ReadFile(DEST_FILE)
86 assert.Equal(t, srcBytes, destBytes)
89 func TestCopyDirectory(t *testing.T) {
90 chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
92 SRC_DIR := "data/resources/std"
93 DEST_DIR := "data/resources/std-copy"
95 err := chartBuilder.copyDirectory(SRC_DIR, DEST_DIR)
96 defer os.RemoveAll(DEST_DIR)
99 srcFiles, _ := ioutil.ReadDir(SRC_DIR)
100 destFiles, _ := ioutil.ReadDir(DEST_DIR)
102 assert.Equal(t, len(srcFiles), len(destFiles))
104 for i, srcFile := range srcFiles {
105 for j, destFile := range destFiles {
107 srcFileInfo, _ := ioutil.ReadFile(srcFile.Name())
108 destFileInfo, _ := ioutil.ReadFile(destFile.Name())
109 assert.Equal(t, srcFileInfo, destFileInfo)