2019-02-10 19:00:16 +00:00
|
|
|
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
2019-02-21 20:48:45 +00:00
|
|
|
// 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 transform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/drone/drone-runtime/engine"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWithLabels(t *testing.T) {
|
|
|
|
volume := &engine.Volume{
|
|
|
|
Metadata: engine.Metadata{
|
|
|
|
Labels: map[string]string{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
step := &engine.Step{
|
|
|
|
Metadata: engine.Metadata{
|
|
|
|
Labels: map[string]string{},
|
|
|
|
},
|
|
|
|
Envs: map[string]string{},
|
|
|
|
}
|
|
|
|
spec := &engine.Spec{
|
|
|
|
Metadata: engine.Metadata{
|
|
|
|
Labels: map[string]string{},
|
|
|
|
},
|
|
|
|
Steps: []*engine.Step{step},
|
|
|
|
Docker: &engine.DockerConfig{
|
|
|
|
Volumes: []*engine.Volume{volume},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
labels := map[string]string{
|
|
|
|
"io.drone.build.number": "1",
|
|
|
|
"io.drone.build.event": "push",
|
|
|
|
}
|
|
|
|
WithLables(labels)(spec)
|
|
|
|
if diff := cmp.Diff(labels, spec.Metadata.Labels); diff != "" {
|
|
|
|
t.Errorf("Unexpected spec labels")
|
|
|
|
t.Log(diff)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(labels, step.Metadata.Labels); diff != "" {
|
|
|
|
t.Errorf("Unexpected step labels")
|
|
|
|
t.Log(diff)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(labels, volume.Metadata.Labels); diff != "" {
|
|
|
|
t.Errorf("Unexpected volume labels")
|
|
|
|
t.Log(diff)
|
|
|
|
}
|
|
|
|
}
|