Skip to content

Commit

Permalink
The buildConfigSource takes the first value in the digest for the ref.
Browse files Browse the repository at this point in the history
This test checks to make sure the value it takes is contained in the
supplied digest.
  • Loading branch information
joejstuart committed Sep 18, 2023
1 parent 659b32b commit fda42ee
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package externalparameters

import (
"strings"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -26,26 +27,41 @@ import (
)

func TestBuildConfigSource(t *testing.T) {
digest := map[string]string{"alg1": "hex1", "alg2": "hex2"}
provenance := &v1beta1.Provenance{
RefSource: &v1beta1.RefSource{
Digest: map[string]string{"alg1": "hex1", "alg2": "hex2"},
Digest: digest,
URI: "https://tekton.com",
EntryPoint: "/path/to/entry",
},
}

want := map[string]string{
"ref": "alg1:hex1",
"repository": "https://tekton.com",
"path": "/path/to/entry",
}

got := buildConfigSource(provenance)

if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("buildConfigSource(): -want +got: %s", diff)
gotRef := strings.Split(got["ref"], ":")
refValue, ok := digest[gotRef[0]]
if !ok {
t.Errorf("buildSource does not contain correct ref: want: %s got: %s:%s", want["ref"], gotRef[0], gotRef[1])
}

if refValue != gotRef[1] {
t.Errorf("buildSource does not contain correct ref: want: %s got: %s:%s", want["ref"], gotRef[0], gotRef[1])
}

if got["repository"] != want["repository"] {
t.Errorf("buildSource does not contain correct repository: want: %s got: %s", want["repository"], want["repository"])
}

if got["path"] != want["path"] {
t.Errorf("buildSource does not contain correct path: want: %s got: %s", want["path"], got["path"])
}
}

func createPro(path string) *objects.PipelineRunObject {
pr, err := objectloader.PipelineRunFromFile(path)
if err != nil {
Expand Down

0 comments on commit fda42ee

Please sign in to comment.