Skip to content
This repository was archived by the owner on Mar 24, 2023. It is now read-only.

Commit a93009f

Browse files
authored
Merge pull request #969 from laverya/preserve-license-info-in-ship-edit
Preserve license info in ship edit
2 parents 579f400 + 9660636 commit a93009f

File tree

9 files changed

+337
-26
lines changed

9 files changed

+337
-26
lines changed

integration/init_app/integration_test.go

+29-25
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ import (
2121
)
2222

2323
type TestMetadata struct {
24-
LicenseID string `yaml:"license_id"`
25-
AppSlug string `yaml:"app_slug"`
26-
InstallationID string `yaml:"installation_id"`
27-
CustomerID string `yaml:"customer_id"`
28-
ReleaseVersion string `yaml:"release_version"`
29-
SetChannelName string `yaml:"set_channel_name"`
30-
Flavor string `yaml:"flavor"`
31-
Args []string `yaml:"args"`
24+
LicenseID string `yaml:"license_id"`
25+
AppSlug string `yaml:"app_slug"`
26+
InstallationID string `yaml:"installation_id"`
27+
CustomerID string `yaml:"customer_id"`
28+
ReleaseVersion string `yaml:"release_version"`
29+
SetChannelName string `yaml:"set_channel_name"`
30+
Flavor string `yaml:"flavor"`
31+
Args []string `yaml:"args"`
32+
Replacements map[string]string `yaml:"replacements"`
3233

3334
// debugging
3435
SkipCleanup bool `yaml:"skip_cleanup"`
@@ -76,6 +77,10 @@ var _ = Describe("ship init replicated.app/...", func() {
7677
// read the test metadata
7778
testMetadata = readMetadata(testPath)
7879

80+
if testMetadata.Replacements == nil {
81+
testMetadata.Replacements = make(map[string]string)
82+
}
83+
7984
// TODO - instead of getting installation ID, etc from test metadata create a release with the vendor api
8085
// TODO customer ID and vendor token will need to be read from environment variables
8186
// TODO so will the desired environment - staging vs prod
@@ -129,13 +134,11 @@ var _ = Describe("ship init replicated.app/...", func() {
129134
Expect(err).NotTo(HaveOccurred())
130135

131136
// these strings will be replaced in the "expected" yaml before comparison
132-
replacements := map[string]string{
133-
"__upstream__": strings.Replace(upstream, "&", "\\u0026", -1), // this string is encoded within the output
134-
"__installationID__": testMetadata.InstallationID,
135-
"__customerID__": testMetadata.CustomerID,
136-
"__appSlug__": testMetadata.AppSlug,
137-
"__licenseID__": testMetadata.LicenseID,
138-
}
137+
testMetadata.Replacements["__upstream__"] = strings.Replace(upstream, "&", "\\u0026", -1) // this string is encoded within the output
138+
testMetadata.Replacements["__installationID__"] = testMetadata.InstallationID
139+
testMetadata.Replacements["__customerID__"] = testMetadata.CustomerID
140+
testMetadata.Replacements["__appSlug__"] = testMetadata.AppSlug
141+
testMetadata.Replacements["__licenseID__"] = testMetadata.LicenseID
139142

140143
ignoreEntitlementSig := map[string][]string{
141144
".ship/state.json": {
@@ -146,7 +149,7 @@ var _ = Describe("ship init replicated.app/...", func() {
146149
}
147150

148151
// compare the files in the temporary directory with those in the "expected" directory
149-
result, err := integration.CompareDir(path.Join(testPath, "expected"), testOutputPath, replacements, []string{}, ignoreEntitlementSig)
152+
result, err := integration.CompareDir(path.Join(testPath, "expected"), testOutputPath, testMetadata.Replacements, []string{}, ignoreEntitlementSig)
150153
Expect(err).NotTo(HaveOccurred())
151154
Expect(result).To(BeTrue())
152155

@@ -180,6 +183,10 @@ var _ = Describe("ship init replicated.app/...", func() {
180183
// read the test metadata
181184
testMetadata = readMetadata(testPath)
182185

186+
if testMetadata.Replacements == nil {
187+
testMetadata.Replacements = make(map[string]string)
188+
}
189+
183190
close(done)
184191
}, 20)
185192

@@ -202,19 +209,16 @@ var _ = Describe("ship init replicated.app/...", func() {
202209
// copy the expected ship state to the output
203210
// and run any replacements needed
204211

205-
replacements := map[string]string{
206-
// "__upstream__": strings.Replace(upstream, "&", "\\u0026", -1), // this string is encoded within the output
207-
"__installationID__": testMetadata.InstallationID,
208-
"__customerID__": testMetadata.CustomerID,
209-
"__appSlug__": testMetadata.AppSlug,
210-
"__licenseID__": testMetadata.LicenseID,
211-
}
212+
testMetadata.Replacements["__installationID__"] = testMetadata.InstallationID
213+
testMetadata.Replacements["__customerID__"] = testMetadata.CustomerID
214+
testMetadata.Replacements["__appSlug__"] = testMetadata.AppSlug
215+
testMetadata.Replacements["__licenseID__"] = testMetadata.LicenseID
212216

213217
readPath := filepath.Join(testPath, "expected", ".ship", "state.json")
214218
stateFile, err := ioutil.ReadFile(readPath)
215219
Expect(err).NotTo(HaveOccurred())
216220

217-
for k, v := range replacements {
221+
for k, v := range testMetadata.Replacements {
218222
stateFile = []byte(strings.Replace(string(stateFile), k, v, -1))
219223
}
220224

@@ -244,7 +248,7 @@ var _ = Describe("ship init replicated.app/...", func() {
244248
}
245249

246250
// compare the files in the temporary directory with those in the "expected" directory
247-
result, err := integration.CompareDir(path.Join(testPath, "expected"), testOutputPath, replacements, []string{}, ignoreEntitlementSig)
251+
result, err := integration.CompareDir(path.Join(testPath, "expected"), testOutputPath, testMetadata.Replacements, []string{}, ignoreEntitlementSig)
248252
Expect(err).NotTo(HaveOccurred())
249253
Expect(result).To(BeTrue())
250254
}, 60)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
assets:
3+
v1:
4+
- inline:
5+
contents: |
6+
{{repl ShipCustomerRelease }}
7+
dest: ./license-info.yaml
8+
mode: 0777
9+
10+
config:
11+
v1: []
12+
13+
lifecycle:
14+
v1:
15+
- render: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"v1": {
3+
"config": {},
4+
"releaseName": "nightly",
5+
"upstream": "staging.replicated.app/ship-integration-testing/?license_id=hLHawMDiyQIeFS7kqVFtD2f44LNh8u5Z\u0026semver=0.0.1",
6+
"metadata": {
7+
"applicationType": "replicated.app",
8+
"sequence": 0,
9+
"releaseNotes": "",
10+
"version": "0.0.1",
11+
"licenseID": "hLHawMDiyQIeFS7kqVFtD2f44LNh8u5Z",
12+
"appSlug": "ship-integration-testing",
13+
"license": {
14+
"id": "hLHawMDiyQIeFS7kqVFtD2f44LNh8u5Z",
15+
"assignee": "customer info test",
16+
"createdAt": "2019-06-11T21:24:30Z",
17+
"expiresAt": "0001-01-01T00:00:00Z",
18+
"type": "dev"
19+
}
20+
},
21+
"upstreamContents": {
22+
"appRelease": {
23+
"id": "TncM-Wu2g4OxW2exEFKTaYoXNZGGDE4H",
24+
"sequence": 1,
25+
"channelId": "1TzgBWDvp4PW3xUfdJ7FqyCsoztmDxiv",
26+
"channelName": "Nightly",
27+
"channelIcon": "",
28+
"semver": "0.0.1",
29+
"releaseNotes": "",
30+
"spec": "---\nassets:\n v1:\n - inline:\n contents: |\n {{repl ShipCustomerRelease }}\n dest: ./license-info.yaml\n mode: 0777\n\nconfig:\n v1: []\n\nlifecycle:\n v1:\n - render: {}",
31+
"images": [],
32+
"githubContents": [],
33+
"created": "Tue Jun 11 2019 21:24:11 GMT+0000 (UTC)",
34+
"registrySecret": "3bfd99a69b5748fab756a593c7dcc852",
35+
"entitlements": {
36+
"meta": {
37+
"last_updated": "0001-01-01T00:00:00Z",
38+
"customer_id": ""
39+
},
40+
"signature": "eVlVacoh3aPSx+EvhmD+B8vG3QicsaWkJ+9vcFReB2xRgPtNgedfQkS7bmJxNwCHZlcOXX/m1io5IkFFXPdW4mXvIRO/5p6xJWFj/icU1iHOBPYf6Q2pEC9+ylXAj8upyPPGGJc+MN5X83Sxk/JumRJPMCNoykwgixkai7NtiZgEjvyfMLPZhYwZ5MBNEv6CJ5NCCw7JO1Ga8G6CDa6E3NLsFJLLLcYUQO+7+hDb9IMxkynHJCoazJ1587fVUgeZ1QLt+mWdJoILn+ioDH4TJ0XZMWvLdRDoV6JTugs1O3O9qh3sMu5C2fow0i3Cnr+K8DsWDpazXTBQzd2ZIuUFf02CgCEF+0M/o9DMbpocePjmHufxZXcEl3jv8rMv5wa6civwRA9W8dbv+eepMf4ngcUP/hxz4WkCSTWT5Zf6+JngXYylDZta+/HnzRMczhG9Laaa+TRhm+fsxApQ4wORvdms3xwcxg35FTzUy4gMoSCLFiNjN7e/GZWsb9NYlFoI/sfhqVsNljFJlN4+XgqEGyU1tn4ggdBeQ9J4/E6NUkvu8+lWqfvNrapGNm2+3J7hAIvfpNo/sOXLGfbHjXu+hM3RWkxgvVKecqMeEAO0MSNZouIRMKmT/qHz15Ds7vww0lkRKQG2xcXFitLVCglcAe2ApriNTAY19MWBVVMUKfY=",
41+
"values": [
42+
{
43+
"key": "my_field",
44+
"value": "The default",
45+
"labels": [
46+
{
47+
"key": "replicated.default",
48+
"value": "true"
49+
},
50+
{
51+
"key": "entitlements.replicated.com/type",
52+
"value": "string"
53+
}
54+
]
55+
},
56+
{
57+
"key": "my_other_field",
58+
"value": "1",
59+
"labels": [
60+
{
61+
"key": "replicated.default",
62+
"value": "true"
63+
},
64+
{
65+
"key": "entitlements.replicated.com/type",
66+
"value": "number"
67+
}
68+
]
69+
}
70+
]
71+
}
72+
}
73+
},
74+
"shipVersion": {
75+
"buildTime": "0001-01-01T00:00:00Z",
76+
"dependencies": {}
77+
},
78+
"contentSHA": "a086cc2c22a907a2d6cc7b5bbc2eb8fe3530799f41e1c5add0ce8aac380e4042"
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
releaseId: TncM-Wu2g4OxW2exEFKTaYoXNZGGDE4H
2+
sequence: 1
3+
customerId: ""
4+
installation: ""
5+
channelId: 1TzgBWDvp4PW3xUfdJ7FqyCsoztmDxiv
6+
appSlug: ship-integration-testing
7+
licenseId: hLHawMDiyQIeFS7kqVFtD2f44LNh8u5Z
8+
channelName: Nightly
9+
channelIcon: ""
10+
semver: 0.0.1
11+
releaseNotes: ""
12+
created: Tue Jun 11 2019 21:24:11 GMT+0000 (UTC)
13+
installed: replaced datetime
14+
registrySecret: 3bfd99a69b5748fab756a593c7dcc852
15+
images: []
16+
githubContents: []
17+
shipAppMetadata:
18+
description: ""
19+
version: ""
20+
icon: ""
21+
name: ""
22+
readme: ""
23+
url: ""
24+
contentSHA: ""
25+
releaseNotes: ""
26+
entitlements:
27+
meta:
28+
lastupdated: 0001-01-01T00:00:00Z
29+
customerid: ""
30+
signature: replaced signature
31+
values:
32+
- key: my_field
33+
value: The default
34+
labels:
35+
- key: replicated.default
36+
value: "true"
37+
- key: entitlements.replicated.com/type
38+
value: string
39+
- key: my_other_field
40+
value: "1"
41+
labels:
42+
- key: replicated.default
43+
value: "true"
44+
- key: entitlements.replicated.com/type
45+
value: number
46+
utilizations: []
47+
type: replicated.app
48+
license:
49+
id: hLHawMDiyQIeFS7kqVFtD2f44LNh8u5Z
50+
assignee: customer info test
51+
createdAt: 2019-06-11T21:24:30Z
52+
expiresAt: 0001-01-01T00:00:00Z
53+
type: dev
54+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
assets:
3+
v1:
4+
- inline:
5+
contents: |
6+
{{repl ShipCustomerRelease }}
7+
dest: ./license-info.yaml
8+
mode: 0777
9+
10+
config:
11+
v1: []
12+
13+
lifecycle:
14+
v1:
15+
- render: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
license_id: "hLHawMDiyQIeFS7kqVFtD2f44LNh8u5Z"
2+
app_slug: "ship-integration-testing"
3+
release_version: "0.0.1"
4+
replacements:
5+
"installed.*" : "installed: replaced datetime"
6+
"signature.*" : "signature: replaced signature"
7+
skip_cleanup: false
8+
skip_edit: false

integration/lib.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"os"
88
"path/filepath"
9+
"regexp"
910
"strings"
1011

1112
. "github.com/onsi/gomega"
@@ -113,7 +114,14 @@ func CompareDir(expected, actual string, replacements map[string]string, ignored
113114

114115
// find and replace strings from the expected contents (customerID, installationID, etc)
115116
for k, v := range replacements {
116-
expectedContents = strings.Replace(expectedContents, k, v, -1)
117+
re := regexp.MustCompile(k)
118+
expectedContents = re.ReplaceAllString(expectedContents, v)
119+
}
120+
121+
// find and replace strings from the actual contents (datetime, signature, etc)
122+
for k, v := range replacements {
123+
re := regexp.MustCompile(k)
124+
actualContents = re.ReplaceAllString(actualContents, v)
117125
}
118126

119127
diff := difflib.UnifiedDiff{

pkg/state/models.go

+6
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ func (v State) ReleaseMetadata() *api.ReleaseMetadata {
357357
baseMeta.CustomerID = v.V1.Metadata.CustomerID
358358
baseMeta.InstallationID = v.V1.Metadata.InstallationID
359359
baseMeta.LicenseID = v.V1.Metadata.LicenseID
360+
baseMeta.AppSlug = v.V1.Metadata.AppSlug
361+
baseMeta.License.ID = v.V1.Metadata.License.ID
362+
baseMeta.License.Assignee = v.V1.Metadata.License.Assignee
363+
baseMeta.License.CreatedAt = v.V1.Metadata.License.CreatedAt
364+
baseMeta.License.ExpiresAt = v.V1.Metadata.License.ExpiresAt
365+
baseMeta.License.Type = v.V1.Metadata.License.Type
360366
}
361367
return &baseMeta
362368
}

0 commit comments

Comments
 (0)