(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func TestAttributesRelativeAttrConditional(t *testing.T) { |
| 187 | reg := newTestRegistry(t) |
| 188 | attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg) |
| 189 | data := map[string]any{ |
| 190 | "a": map[int]any{ |
| 191 | -1: []int32{2, 42}, |
| 192 | }, |
| 193 | "b": []int{0, 1}, |
| 194 | "c": []any{1, 0}, |
| 195 | } |
| 196 | vars, _ := NewActivation(data) |
| 197 | |
| 198 | // The relative attribute under test is applied to a map literal: |
| 199 | // { |
| 200 | // a: {-1: [2, 42], b: 1} |
| 201 | // b: [0, 1], |
| 202 | // c: {1, 0}, |
| 203 | // } |
| 204 | // |
| 205 | // The expression being evaluated is: |
| 206 | // <map-literal>.a[-1][(false ? b : c)[0]] -> 42 |
| 207 | // |
| 208 | // Effectively the same as saying <map-literal>.a[-1][c[0]] |
| 209 | cond := NewConstValue(2, types.False) |
| 210 | condAttr := attrs.ConditionalAttribute(4, cond, |
| 211 | attrs.AbsoluteAttribute(5, "b"), |
| 212 | attrs.AbsoluteAttribute(6, "c")) |
| 213 | qual0 := makeQualifier(t, attrs, nil, 7, 0) |
| 214 | condAttr.AddQualifier(qual0) |
| 215 | |
| 216 | obj := NewConstValue(1, reg.NativeToValue(data)) |
| 217 | attr := attrs.RelativeAttribute(1, obj) |
| 218 | qualA := makeQualifier(t, attrs, nil, 2, "a") |
| 219 | qualNeg1 := makeQualifier(t, attrs, nil, 3, int64(-1)) |
| 220 | attr.AddQualifier(qualA) |
| 221 | attr.AddQualifier(qualNeg1) |
| 222 | attr.AddQualifier(condAttr) |
| 223 | out, err := attr.Resolve(vars) |
| 224 | if err != nil { |
| 225 | t.Fatal(err) |
| 226 | } |
| 227 | if out != types.Int(42) { |
| 228 | t.Errorf("Got %v (%T), wanted 42", out, out) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | func TestAttributesRelativeAttrRelativeQualifier(t *testing.T) { |
| 233 | cont, err := containers.NewContainer(containers.Name("acme.ns")) |
nothing calls this directly
no test coverage detected