Skip to content

Commit

Permalink
Fix unit test & comment out default settings in deployment.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa authored and tekton-robot committed May 12, 2021
1 parent 1b1a4a8 commit ac7b57a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
17 changes: 9 additions & 8 deletions config/100-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ metadata:
app.kubernetes.io/part-of: tekton-pipelines
pipeline.tekton.dev/release: "devel"
version: "devel"
# The data can be tweaked at install time.
data:
artifacts.taskrun.format: tekton
artifacts.taskrun.storage: tekton
artifacts.taskrun.signer: x509
artifacts.oci.storage: oci
artifacts.oci.format: simplesigning
artifacts.oci.signer: x509
# The data can be tweaked at install time, it is commented out
# because these are the default settings.
# data:
# artifacts.taskrun.format: tekton
# artifacts.taskrun.storage: tekton
# artifacts.taskrun.signer: x509
# artifacts.oci.storage: oci
# artifacts.oci.format: simplesigning
# artifacts.oci.signer: x509
---
apiVersion: apps/v1
kind: Deployment
Expand Down
45 changes: 33 additions & 12 deletions pkg/config/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestNewConfigStore(t *testing.T) {

// Setup some config
cm.Data = map[string]string{}
cm.Data[taskrunFormatKey] = "foo"
cm.Data[taskrunSignerKey] = "pgp"

if cm, err = fakekubeclient.CoreV1().ConfigMaps(ns).Update(ctx, cm, metav1.UpdateOptions{}); err != nil {
t.Errorf("error updating configmap: %v", err)
Expand All @@ -45,24 +45,24 @@ func TestNewConfigStore(t *testing.T) {
// It should be updated by then...
time.Sleep(100 * time.Millisecond)
// Test that the values are set!
if diff := cmp.Diff("foo", cs.Config().Artifacts.TaskRuns.Format); diff != "" {
if diff := cmp.Diff("pgp", cs.Config().Artifacts.TaskRuns.Signer); diff != "" {
t.Error(diff)
}

// Change it again
cm.Data[taskrunFormatKey] = "bar"
cm.Data[taskrunSignerKey] = "kms"

if _, err := fakekubeclient.CoreV1().ConfigMaps(ns).Update(ctx, cm, metav1.UpdateOptions{}); err != nil {
t.Errorf("error updating configmap: %v", err)
}
time.Sleep(100 * time.Millisecond)
// Test that the values are set!
if diff := cmp.Diff("bar", cs.Config().Artifacts.TaskRuns.Format); diff != "" {
if diff := cmp.Diff("kms", cs.Config().Artifacts.TaskRuns.Signer); diff != "" {
t.Error(diff)
}
}

func Test_parse(t *testing.T) {
func TestParse(t *testing.T) {
tests := []struct {
name string
data map[string]string
Expand All @@ -73,30 +73,51 @@ func Test_parse(t *testing.T) {
data: map[string]string{},
want: Config{
Artifacts: ArtifactConfigs{
TaskRuns: Artifact{},
TaskRuns: Artifact{
Format: "tekton",
StorageBackend: "tekton",
Signer: "x509",
},
OCI: Artifact{
Format: "simplesigning",
StorageBackend: "oci",
Signer: "x509",
},
},
},
},
{
name: "single",
data: map[string]string{taskrunFormatKey: "foo"},
data: map[string]string{taskrunSignerKey: "pgp"},
want: Config{
Artifacts: ArtifactConfigs{
TaskRuns: Artifact{
Format: "foo",
StorageBackend: "",
Format: "tekton",
Signer: "pgp",
StorageBackend: "tekton",
},
OCI: Artifact{
Format: "simplesigning",
StorageBackend: "oci",
Signer: "x509",
},
},
},
},
{
name: "extra",
data: map[string]string{taskrunFormatKey: "foo", "other-key": "foo"},
data: map[string]string{taskrunSignerKey: "pgp", "other-key": "foo"},
want: Config{
Artifacts: ArtifactConfigs{
TaskRuns: Artifact{
Format: "foo",
StorageBackend: "",
Format: "tekton",
Signer: "pgp",
StorageBackend: "tekton",
},
OCI: Artifact{
Format: "simplesigning",
StorageBackend: "oci",
Signer: "x509",
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions test/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ func setConfigMap(ctx context.Context, t *testing.T, c *clients, data map[string
oldData[k] = v
}

if cm.Data == nil {
cm.Data = map[string]string{}
}

for k, v := range data {
cm.Data[k] = v
}
Expand Down

0 comments on commit ac7b57a

Please sign in to comment.