graphql-engine/cli/internal/metadataobject/metadataobject_test.go
Kali Vara Purushotham Santhati 8c41ff539a cli: enhance metadata diff command
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2581
Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com>
GitOrigin-RevId: 327c26868102ea1c277b795b9f508847faa2ae8b
2021-12-09 17:26:53 +00:00

105 lines
2.5 KiB
Go

package metadataobject
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"github.com/gonvenience/ytbx"
)
func Test_createEmptyYamlFileAccordingToContent(t *testing.T) {
type args struct {
file ytbx.InputFile
}
tests := []struct {
name string
args args
want yaml.Kind
}{
{
"can generate sequence node",
args{
file: func() ytbx.InputFile {
m := []map[string]string{{"test": "test"}, {"test2": "test2"}}
b, err := yaml.Marshal(m)
assert.NoError(t, err)
documents, err := ytbx.LoadYAMLDocuments(b)
assert.NoError(t, err)
return ytbx.InputFile{
Documents: documents,
}
}(),
},
yaml.SequenceNode,
},
{
"can generate mapping node",
args{
file: func() ytbx.InputFile {
m := map[string]string{"test": "test", "test2": "test2"}
b, err := yaml.Marshal(m)
assert.NoError(t, err)
documents, err := ytbx.LoadYAMLDocuments(b)
assert.NoError(t, err)
return ytbx.InputFile{
Documents: documents,
}
}(),
},
yaml.MappingNode,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := createEmptyYamlFileAccordingToContent(tt.args.file)
assert.Equal(t, tt.want, got.Documents[0].Content[0].Kind)
})
}
}
func Test_cleanExcludedPatterns(t *testing.T) {
type args struct {
files []string
patterns []string
}
tests := []struct {
name string
args args
want []string
wantErr assert.ErrorAssertionFunc
}{
{
"t1",
args{
[]string{"/home/someuser/hasura/metadata/databases/somesource/tables/tables.yaml", "/home/someuser/hasura/metadata/databases/somesource/functions/functions.yaml"},
[]string{"tables/tables.yaml", "functions/functions.yaml"},
},
[]string(nil),
assert.NoError,
},
{
"t2",
args{
[]string{"/home/someuser/hasura/metadata/remote_schemas/permissions/permissions.yaml", "/home/someuser/hasura/metadata/databases/databases.yaml"},
[]string{"permissions/permissions.yaml"},
},
[]string{"/home/someuser/hasura/metadata/databases/databases.yaml"},
assert.NoError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := cleanExcludedPatterns(tt.args.files, tt.args.patterns)
if !tt.wantErr(t, err, fmt.Sprintf("cleanExcludedPatterns(%v, %v)", tt.args.files, tt.args.patterns)) {
return
}
assert.Equalf(t, tt.want, got, "cleanExcludedPatterns(%v, %v)", tt.args.files, tt.args.patterns)
})
}
}