(t *testing.T)
| 17 | } |
| 18 | |
| 19 | func TestFindInstance(t *testing.T) { |
| 20 | instances := sampleInstances() |
| 21 | |
| 22 | tests := []struct { |
| 23 | name string |
| 24 | identifier string |
| 25 | wantID string |
| 26 | wantNil bool |
| 27 | }{ |
| 28 | {name: "by ID", identifier: "1", wantID: "1"}, |
| 29 | {name: "by UUID", identifier: "uuid-bbb", wantID: "2"}, |
| 30 | {name: "by name", identifier: "alpha", wantID: "1"}, |
| 31 | {name: "not found", identifier: "nonexistent", wantNil: true}, |
| 32 | {name: "empty identifier", identifier: "", wantNil: true}, |
| 33 | {name: "partial ID no match", identifier: "uu", wantNil: true}, |
| 34 | } |
| 35 | |
| 36 | for _, tt := range tests { |
| 37 | t.Run(tt.name, func(t *testing.T) { |
| 38 | result := findInstance(instances, tt.identifier) |
| 39 | if tt.wantNil { |
| 40 | assert.Nil(t, result) |
| 41 | } else { |
| 42 | assert.NotNil(t, result) |
| 43 | assert.Equal(t, tt.wantID, result.ID) |
| 44 | } |
| 45 | }) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func TestFindInstance_EmptyList(t *testing.T) { |
| 50 | result := findInstance([]api.Instance{}, "anything") |
nothing calls this directly
no test coverage detected