-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaml_test.go
102 lines (70 loc) · 2.17 KB
/
yaml_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Copyright © 2023 Patrick Hermann [email protected]
*/
package cli
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
var config Profile
type Install struct {
Url string `mapstructure:"url"`
Bin string `mapstructure:"bin"`
}
type Script struct {
Script string `mapstructure:"script"`
}
type Profile struct {
BinaryProfile []map[string]Install `mapstructure:"binary"`
ScriptProfile []map[string]Script `mapstructure:"script"`
}
var expectedUrl = "https://github.com/argoproj/argo-cd/releases/download/v2.5.10/argocd-linux-amd64"
var expectedScript = "echo hello"
var yamlExample = []byte(`
binary:
- argocd:
url: https://github.com/argoproj/argo-cd/releases/download/v2.5.10/argocd-linux-amd64
bin: argocd-linux-amd64
script:
- argocd:
script: |
echo hello`)
func TestReadInlineYamlToObject(t *testing.T) {
assert := assert.New(t)
config := ReadInlineYamlToObject(yamlExample, config).(Profile)
// CHECK FOR ONE VALUE IN BINARY
assert.Equal(expectedUrl, config.BinaryProfile[0]["argocd"].Url)
// CHECK FOR ONE VALUE IN SCRIPT
assert.Equal(expectedScript, config.ScriptProfile[0]["argocd"].Script)
}
func TestConvertYAMLToJSON(t *testing.T) {
assert := assert.New(t)
testYaml := `apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: hello
namespace: ansible
`
wantedResult := `{"apiVersion":"tekton.dev/v1beta1","kind":"PipelineRun","metadata":{"name":"hello","namespace":"ansible"}}`
convertedJSON := ConvertYAMLToJSON(testYaml)
assert.Equal(convertedJSON, wantedResult)
}
func TestConvertJSONToYAML(t *testing.T) {
// assert := assert.New(t)
testJSON := `{"apiVersion":"tekton.dev/v1beta1", "kind":"PipelineRun", "metadata":{"name":"hello","namespace":"ansible"}}`
wantedResult := `apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: hello
namespace: ansible
`
// fmt.Println(wantedResult)
convertedYAML := ConvertJSONToYAML(testJSON)
fmt.Println(convertedYAML)
fmt.Println(strings.Replace(wantedResult, "\t", "\n", -1))
// assert.Equal(convertedYAML, strings.Replace(wantedResult, "\t", "\n", 5))
}
func TestReadYamlKeyValuesFromFile(t *testing.T) {
}