|
1 | 1 | package claim
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "encoding/json" |
| 5 | + "io/ioutil" |
4 | 6 | "sort"
|
5 | 7 | "testing"
|
6 | 8 |
|
@@ -99,16 +101,6 @@ func TestResultOutputs_SetMetadata(t *testing.T) {
|
99 | 101 | require.NoError(t, err, "SetMetadata failed")
|
100 | 102 | assert.Equal(t, wantoutputs, outputs, "SetMetadata did not produce the expected structure")
|
101 | 103 | })
|
102 |
| - |
103 |
| - t.Run("existing invalid structure", func(t *testing.T) { |
104 |
| - outputs := OutputMetadata{ |
105 |
| - outputName: map[string]interface{}{ |
106 |
| - metadataKey: struct{}{}, |
107 |
| - }, |
108 |
| - } |
109 |
| - err := outputs.SetMetadata(outputName, metadataKey, metadataValue) |
110 |
| - require.EqualError(t, err, "cannot set the claim result's OutputMetadata[test1][so-meta] because it is not type map[string]string but map[string]interface {}") |
111 |
| - }) |
112 | 104 | }
|
113 | 105 |
|
114 | 106 | func TestResultOutputs_GetMetadata(t *testing.T) {
|
@@ -144,19 +136,6 @@ func TestResultOutputs_GetMetadata(t *testing.T) {
|
144 | 136 | require.False(t, ok, "GetMetadata should report that it did not find the value")
|
145 | 137 | assert.Empty(t, gotValue, "GetMetadata should return an empty value when one isn't found")
|
146 | 138 | })
|
147 |
| - |
148 |
| - t.Run("output has different structure", func(t *testing.T) { |
149 |
| - outputs := OutputMetadata{ |
150 |
| - outputName: map[string]interface{}{ |
151 |
| - "other": struct{}{}, |
152 |
| - }, |
153 |
| - } |
154 |
| - |
155 |
| - gotValue, ok := outputs.GetMetadata(outputName, metadataKey) |
156 |
| - require.False(t, ok, "GetMetadata should report that it did not find the value") |
157 |
| - assert.Empty(t, gotValue, "GetMetadata should return an empty value when one isn't found") |
158 |
| - }) |
159 |
| - |
160 | 139 | }
|
161 | 140 |
|
162 | 141 | func TestResultOutputs_SetContentDigest(t *testing.T) {
|
@@ -265,3 +244,19 @@ func TestResult_HasLogs(t *testing.T) {
|
265 | 244 | r.OutputMetadata.SetGeneratedByBundle(OutputInvocationImageLogs, true)
|
266 | 245 | assert.True(t, r.HasLogs(), "expected HasLogs to return true")
|
267 | 246 | }
|
| 247 | + |
| 248 | +// Verify that when we unmarshal a result, the output metadata can be read back |
| 249 | +func TestResult_UnmarshalOutputMetadata(t *testing.T) { |
| 250 | + data, err := ioutil.ReadFile("testdata/result.json") |
| 251 | + require.NoError(t, err, "error reading testdata result") |
| 252 | + |
| 253 | + var result Result |
| 254 | + err = json.Unmarshal(data, &result) |
| 255 | + require.NoError(t, err, "error unmarshaling result") |
| 256 | + |
| 257 | + contentDigest, _ := result.OutputMetadata.GetContentDigest(OutputInvocationImageLogs) |
| 258 | + assert.Equal(t, "sha256:28ccd0529aa1edefb0e771a28c31c0193f656718af985fed197235ba98fc5696", contentDigest, "the content digest output metadata could not be read") |
| 259 | + |
| 260 | + generatedFlag, _ := result.OutputMetadata.GetGeneratedByBundle("output1") |
| 261 | + assert.True(t, generatedFlag, "the generatedByBundle output metadata could not be read") |
| 262 | +} |
0 commit comments