|
| 1 | +package state |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/require" |
| 7 | + |
| 8 | + "github.com/replicatedhq/ship/pkg/api" |
| 9 | +) |
| 10 | + |
| 11 | +func TestState_ReleaseMetadata(t *testing.T) { |
| 12 | + tests := []struct { |
| 13 | + name string |
| 14 | + V1 *V1 |
| 15 | + want *api.ReleaseMetadata |
| 16 | + }{ |
| 17 | + { |
| 18 | + name: "all nil", |
| 19 | + V1: nil, |
| 20 | + want: nil, |
| 21 | + }, |
| 22 | + { |
| 23 | + name: "no upstream contents", |
| 24 | + V1: &V1{ReleaseName: "no upstream contents"}, |
| 25 | + want: nil, |
| 26 | + }, |
| 27 | + { |
| 28 | + name: "basic upstream contents", |
| 29 | + V1: &V1{ |
| 30 | + UpstreamContents: &UpstreamContents{ |
| 31 | + AppRelease: &ShipRelease{ID: "abc"}, |
| 32 | + }, |
| 33 | + }, |
| 34 | + want: &api.ReleaseMetadata{ |
| 35 | + ReleaseID: "abc", |
| 36 | + Images: []api.Image{}, |
| 37 | + GithubContents: []api.GithubContent{}, |
| 38 | + }, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "upstream contents with metadata", |
| 42 | + V1: &V1{ |
| 43 | + UpstreamContents: &UpstreamContents{ |
| 44 | + AppRelease: &ShipRelease{ID: "abc"}, |
| 45 | + }, |
| 46 | + Metadata: &Metadata{ |
| 47 | + CustomerID: "xyz", |
| 48 | + License: License{ |
| 49 | + ID: "licenseID", |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + want: &api.ReleaseMetadata{ |
| 54 | + ReleaseID: "abc", |
| 55 | + Images: []api.Image{}, |
| 56 | + GithubContents: []api.GithubContent{}, |
| 57 | + CustomerID: "xyz", |
| 58 | + License: api.License{ |
| 59 | + ID: "licenseID", |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + { |
| 64 | + name: "upstream contents with actual contents", |
| 65 | + V1: &V1{ |
| 66 | + UpstreamContents: &UpstreamContents{ |
| 67 | + AppRelease: &ShipRelease{ |
| 68 | + ID: "abc", |
| 69 | + GithubContents: []GithubContent{ |
| 70 | + { |
| 71 | + Repo: "testRepo", |
| 72 | + Path: "testPath", |
| 73 | + Ref: "testRef", |
| 74 | + Files: []GithubFile{ |
| 75 | + { |
| 76 | + Name: "testFileName", |
| 77 | + Path: "testFilePath", |
| 78 | + Sha: "testFileSha", |
| 79 | + Size: 1234, |
| 80 | + Data: "testFileData", |
| 81 | + }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + }, |
| 87 | + }, |
| 88 | + want: &api.ReleaseMetadata{ |
| 89 | + ReleaseID: "abc", |
| 90 | + Images: []api.Image{}, |
| 91 | + GithubContents: []api.GithubContent{ |
| 92 | + { |
| 93 | + Repo: "testRepo", |
| 94 | + Path: "testPath", |
| 95 | + Ref: "testRef", |
| 96 | + Files: []api.GithubFile{ |
| 97 | + { |
| 98 | + Name: "testFileName", |
| 99 | + Path: "testFilePath", |
| 100 | + Sha: "testFileSha", |
| 101 | + Size: 1234, |
| 102 | + Data: "testFileData", |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + }, |
| 107 | + }, |
| 108 | + }, |
| 109 | + } |
| 110 | + for _, tt := range tests { |
| 111 | + t.Run(tt.name, func(t *testing.T) { |
| 112 | + req := require.New(t) |
| 113 | + v := State{ |
| 114 | + V1: tt.V1, |
| 115 | + } |
| 116 | + got := v.ReleaseMetadata() |
| 117 | + |
| 118 | + req.Equal(tt.want, got) |
| 119 | + }) |
| 120 | + } |
| 121 | +} |
0 commit comments