Revert " helm packaging, add chart_builder"
[aiml-fw/aihp/ips/kserve-adapter.git] / pkg / helm / chart_builder_test.go
1 /*
2 ==================================================================================
3   Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.
4
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
8
9          http://www.apache.org/licenses/LICENSE-2.0
10
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 ==================================================================================
17 */
18
19 package helm
20
21 import (
22         "io/ioutil"
23         "os"
24         "testing"
25
26         "github.com/stretchr/testify/assert"
27 )
28
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")
32
33         assert.Nil(t, err)
34         assert.NotEmpty(t, config)
35 }
36
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")
40
41         assert.Nil(t, err)
42         assert.NotEmpty(t, schema)
43 }
44
45 func TestHelmLint(t *testing.T) {
46         chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
47         err := chartBuilder.helmLint()
48
49         assert.Nil(t, err)
50 }
51
52 func TestAppendConfigToValuesYaml(t *testing.T) {
53         chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
54
55         err := chartBuilder.appendConfigToValuesYaml()
56
57         assert.Nil(t, err)
58 }
59
60 func TestChangeChartNameVersion(t *testing.T) {
61         chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
62         err := chartBuilder.changeChartNameVersion()
63
64         assert.Nil(t, err)
65 }
66
67 func TestPackageChart(t *testing.T) {
68         chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
69         err := chartBuilder.PackageChart()
70
71         assert.Nil(t, err)
72 }
73
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)
80
81         assert.Nil(t, err)
82
83         srcBytes, _ := ioutil.ReadFile(SRC_FILE)
84         destBytes, _ := ioutil.ReadFile(DEST_FILE)
85
86         assert.Equal(t, srcBytes, destBytes)
87 }
88
89 func TestCopyDirectory(t *testing.T) {
90         chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json")
91
92         SRC_DIR := "data/resources/std"
93         DEST_DIR := "data/resources/std-copy"
94
95         err := chartBuilder.copyDirectory(SRC_DIR, DEST_DIR)
96         defer os.RemoveAll(DEST_DIR)
97         assert.Nil(t, err)
98
99         srcFiles, _ := ioutil.ReadDir(SRC_DIR)
100         destFiles, _ := ioutil.ReadDir(DEST_DIR)
101
102         assert.Equal(t, len(srcFiles), len(destFiles))
103
104         for i, srcFile := range srcFiles {
105                 for j, destFile := range destFiles {
106                         if i == j {
107                                 srcFileInfo, _ := ioutil.ReadFile(srcFile.Name())
108                                 destFileInfo, _ := ioutil.ReadFile(destFile.Name())
109                                 assert.Equal(t, srcFileInfo, destFileInfo)
110                         }
111                 }
112         }
113 }