Skip to content

Commit

Permalink
tests: add tests for migration of application schema to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
onematchfox committed Oct 7, 2022
1 parent 670b4c2 commit 71895f2
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions argocd/schema_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package argocd
import (
"context"
"reflect"
"strings"
"testing"
)

Expand Down Expand Up @@ -72,3 +73,62 @@ func TestUpgradeSchemaApplication_V0V1_Default_SkipCrds_NoChange(t *testing.T) {
t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", v0, actual)
}
}

func TestUpgradeSchemaApplication_V1V2_Default_NoChange(t *testing.T) {
v1 := map[string]interface{}{
"spec": []interface{}{
map[string]interface{}{
"source": []interface{}{map[string]interface{}{
"repo_url": "https://charts.bitnami.com/bitnami",
"chart": "redis",
"target_revision": "16.9.11",

"helm": []interface{}{map[string]interface{}{
"release_name": "testing",
"skip_crds": false,
}},
}},
"destination": []interface{}{map[string]interface{}{
"server": "https://kubernetes.default.svc",
"namespace": "default",
}},
},
},
}

actual, _ := resourceArgoCDApplicationStateUpgradeV1(context.TODO(), v1, nil)

if !reflect.DeepEqual(v1, actual) {
t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", v1, actual)
}
}

func TestUpgradeSchemaApplication_V1V2_WithKsonnet(t *testing.T) {
v1 := map[string]interface{}{
"spec": []interface{}{
map[string]interface{}{
"source": []interface{}{map[string]interface{}{
"repo_url": "https://charts.bitnami.com/bitnami",
"chart": "redis",
"target_revision": "16.9.11",

"ksonnet": []interface{}{map[string]interface{}{
"destination": []interface{}{map[string]interface{}{
"namespace": "foo",
}},
}},
}},
"destination": []interface{}{map[string]interface{}{
"server": "https://kubernetes.default.svc",
"namespace": "default",
}},
},
},
}

_, err := resourceArgoCDApplicationStateUpgradeV1(context.TODO(), v1, nil)

if err == nil || !strings.Contains(err.Error(), "'ksonnet' support has been removed") {
t.Fatalf("\n\nexpected error during state migration was not found - err returned was: %v", err)
}
}

0 comments on commit 71895f2

Please sign in to comment.