drone-yaml/yaml/converter/legacy/internal/config_test.go

101 lines
2.0 KiB
Go
Raw Normal View History

2019-02-10 19:00:16 +00:00
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
2019-02-10 19:00:16 +00:00
2019-01-22 23:44:17 +00:00
package yaml
import (
"bytes"
"io/ioutil"
"testing"
2019-03-14 17:51:31 +00:00
"github.com/sergi/go-diff/diffmatchpatch"
2019-01-22 23:44:17 +00:00
)
func TestConvert(t *testing.T) {
tests := []struct {
before, after, url string
2019-01-22 23:44:17 +00:00
}{
{
before: "testdata/simple.yml",
after: "testdata/simple.yml.golden",
},
{
before: "testdata/branches.yml",
after: "testdata/branches.yml.golden",
},
2019-01-22 23:44:17 +00:00
{
before: "testdata/vault_1.yml",
after: "testdata/vault_1.yml.golden",
},
{
before: "testdata/vault_2.yml",
after: "testdata/vault_2.yml.golden",
},
{
before: "testdata/vault_3.yml",
after: "testdata/vault_3.yml.golden",
},
2019-01-28 15:34:05 +00:00
{
before: "testdata/matrix_1.yml",
after: "testdata/matrix_1.yml.golden",
},
{
before: "testdata/matrix_2.yml",
after: "testdata/matrix_2.yml.golden",
},
2019-01-22 23:44:17 +00:00
}
for _, test := range tests {
a, err := ioutil.ReadFile(test.before)
if err != nil {
t.Error(err)
return
}
b, err := ioutil.ReadFile(test.after)
if err != nil {
t.Error(err)
return
}
c, err := Convert(a, test.url)
2019-01-22 23:44:17 +00:00
if err != nil {
t.Error(err)
return
}
if bytes.Equal(b, c) == false {
t.Errorf("Unexpected yaml conversion of %s", test.before)
2019-03-14 17:51:31 +00:00
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(string(b), string(c), false)
t.Log(dmp.DiffCleanupSemantic(diffs))
2019-01-22 23:44:17 +00:00
}
}
}
func TestWorkspacePath(t *testing.T) {
tests := []struct{
a string
b string
}{
{
a: "",
b: "src",
},
{
a: "https://github.com/octocat/hello-world",
b: "src/github.com/octocat/hello-world",
},
{
a: "https://github.com:80/octocat/hello-world",
b: "src/github.com/octocat/hello-world",
},
{
a: "github.com:80/octocat/hello-world",
b: "src",
},
}
for _, test := range tests {
if got, want := toWorkspacePath(test.a), test.b; got != want {
t.Errorf("Want workspace path %s, got %s", want, got)
}
}
}