Skip to content

Commit 4b0595e

Browse files
author
Kristian
authored
Merge pull request #122 from gnuvince/individual-metadata-files
Explode metadata.json into individual files
2 parents 7f5c11c + cd40d38 commit 4b0595e

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

e2e/e2e_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,22 @@ func TestGetAndPutE2E(t *testing.T) {
325325
metadata := readTestFile(t, filepath.Join(dir, ".git", "resource", "metadata.json"))
326326
assert.Equal(t, tc.metadataString, metadata)
327327

328+
individual_files := map[string]string {
329+
"pr": "4",
330+
"url": "https://github.com/itsdalmo/test-repository/pull/4",
331+
"head_name": "my_second_pull",
332+
"head_sha": "a5114f6ab89f4b736655642a11e8d15ce363d882",
333+
"base_name": "master",
334+
"base_sha": "93eeeedb8a16e6662062d1eca5655108977cc59a",
335+
"message": "Push 2.",
336+
"author": "itsdalmo",
337+
}
338+
for filename, expected_content := range individual_files {
339+
actual_content := readTestFile(t, filepath.Join(dir, ".git", "resource", filename))
340+
assert.Equal(t, actual_content, expected_content)
341+
}
342+
343+
328344
// Check commit history
329345
history := gitHistory(t, dir)
330346
assert.Equal(t, tc.expectedCommitCount, len(history))

in.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp
9393
return nil, fmt.Errorf("failed to write metadata: %s", err)
9494
}
9595

96+
for _, d := range metadata {
97+
filename := d.Name
98+
content := []byte(d.Value)
99+
if err := ioutil.WriteFile(filepath.Join(path, filename), content, 0644); err != nil {
100+
return nil, fmt.Errorf("failed to write metadata file %s: %s", filename, err)
101+
}
102+
}
103+
96104
return &GetResponse{
97105
Version: request.Version,
98106
Metadata: metadata,

in_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ func TestGet(t *testing.T) {
137137

138138
metadata := readTestFile(t, filepath.Join(dir, ".git", "resource", "metadata.json"))
139139
assert.Equal(t, tc.metadataString, metadata)
140+
141+
// Verify individual files
142+
individual_files := map[string]string {
143+
"pr": "1",
144+
"url": "pr1 url",
145+
"head_name": "pr1",
146+
"head_sha": "oid1",
147+
"base_name": "master",
148+
"base_sha": "sha",
149+
"message": "commit message1",
150+
"author": "login1",
151+
}
152+
for filename, expected_content := range individual_files {
153+
actual_content := readTestFile(t, filepath.Join(dir, ".git", "resource", filename))
154+
assert.Equal(t, actual_content, expected_content)
155+
}
140156
}
141157

142158
// Validate Github calls

0 commit comments

Comments
 (0)