(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestGetComposition(t *testing.T) { |
| 16 | tests := []struct { |
| 17 | name string |
| 18 | cli string |
| 19 | mock string |
| 20 | wantOut string |
| 21 | }{ |
| 22 | { |
| 23 | name: "composition with injection behavior", |
| 24 | cli: "my-comp", |
| 25 | mock: `{"objectID":"my-comp","name":"My Comp","behavior":{"injection":{"main":{}}}}`, |
| 26 | wantOut: `{"behavior":{"injection":{"main":{}}},"name":"My Comp","objectID":"my-comp"}`, |
| 27 | }, |
| 28 | } |
| 29 | |
| 30 | for _, tt := range tests { |
| 31 | t.Run(tt.name, func(t *testing.T) { |
| 32 | r := &httpmock.Registry{} |
| 33 | r.Register( |
| 34 | httpmock.REST("GET", "1/compositions/my-comp"), |
| 35 | httpmock.StringResponse(tt.mock), |
| 36 | ) |
| 37 | |
| 38 | f, out := test.NewFactory(false, r, nil, "") |
| 39 | cmd := get.NewGetCmd(f) |
| 40 | _, err := test.Execute(cmd, tt.cli, out) |
| 41 | require.NoError(t, err) |
| 42 | |
| 43 | assert.JSONEq(t, tt.wantOut, strings.TrimSpace(out.String())) |
| 44 | r.Verify(t) |
| 45 | }) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func TestGetComposition_MissingArg(t *testing.T) { |
| 50 | r := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected