drone-yaml/yaml/param_test.go

44 lines
840 B
Go
Raw Normal View History

2019-02-10 20:00:16 +01: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 20:00:16 +01:00
2019-01-23 00:44:17 +01:00
package yaml
import (
"testing"
2019-05-30 03:21:23 +02:00
"github.com/buildkite/yaml"
2019-01-23 00:44:17 +01:00
)
func TestParam(t *testing.T) {
tests := []struct {
yaml string
value interface{}
2019-02-22 01:59:17 +01:00
from string
2019-01-23 00:44:17 +01:00
}{
{
yaml: "bar",
value: "bar",
},
{
2019-02-22 01:59:17 +01:00
yaml: "from_secret: username",
from: "username",
2019-01-23 00:44:17 +01:00
},
}
for _, test := range tests {
in := []byte(test.yaml)
out := new(Parameter)
err := yaml.Unmarshal(in, out)
if err != nil {
t.Error(err)
return
}
2019-02-22 01:59:17 +01:00
if got, want := out.Value, test.value; got != want {
t.Errorf("Want value %q, got %q", want, got)
2019-01-23 00:44:17 +01:00
}
2019-02-22 01:59:17 +01:00
if got, want := out.Secret, test.from; got != want {
t.Errorf("Want from_secret %q, got %q", want, got)
2019-01-23 00:44:17 +01:00
}
}
}