mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-09 19:07:04 +00:00
* fix issue 1029 * add test case * fix check diff Co-authored-by: 王易可 <wangyike@B-V1QHML7L-1909.local>
38 lines
897 B
Go
38 lines
897 B
Go
package serverlib
|
|
|
|
import (
|
|
"encoding/json"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"github.com/oam-dev/kubevela/apis/types"
|
|
)
|
|
|
|
func TestAddSourceIntoDefinition(t *testing.T) {
|
|
caseJson := []byte(`{"template":""}`)
|
|
wantJson := []byte(`{"source":{"repoName":"foo"},"template":""}`)
|
|
source := types.Source{RepoName: "foo"}
|
|
testcase := runtime.RawExtension{Raw: caseJson}
|
|
err := addSourceIntoExtension(&testcase, &source)
|
|
if err != nil {
|
|
t.Error("meet an error ", err)
|
|
return
|
|
}
|
|
var result, want map[string]interface{}
|
|
err = json.Unmarshal(testcase.Raw, &result)
|
|
if err != nil {
|
|
t.Error("marshaling object meet an error ", err)
|
|
return
|
|
}
|
|
err = json.Unmarshal(wantJson, &want)
|
|
if err != nil {
|
|
t.Error("marshaling object meet an error ", err)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(result, want) {
|
|
t.Errorf("error result want %s, got %s", result, testcase)
|
|
}
|
|
}
|