(t *testing.T)
| 139 | } |
| 140 | |
| 141 | func TestAttributesRelativeAttrOneOf(t *testing.T) { |
| 142 | reg := newTestRegistry(t) |
| 143 | cont, err := containers.NewContainer(containers.Name("acme.ns")) |
| 144 | if err != nil { |
| 145 | t.Fatal(err) |
| 146 | } |
| 147 | attrs := NewAttributeFactory(cont, reg, reg) |
| 148 | data := map[string]any{ |
| 149 | "a": map[int]any{ |
| 150 | -1: []int32{2, 42}, |
| 151 | }, |
| 152 | "acme.b": 1, |
| 153 | } |
| 154 | vars, _ := NewActivation(data) |
| 155 | |
| 156 | // The relative attribute under test is applied to a map literal: |
| 157 | // { |
| 158 | // a: {-1: [2, 42], b: 1} |
| 159 | // b: 1 |
| 160 | // } |
| 161 | // |
| 162 | // The expression being evaluated is: <map-literal>.a[-1][b] -> 42 |
| 163 | // |
| 164 | // However, since the test is validating what happens with maybe attributes |
| 165 | // the attribute resolution must also consider the following variations: |
| 166 | // - <map-literal>.a[-1][acme.ns.b] |
| 167 | // - <map-literal>.a[-1][acme.b] |
| 168 | // |
| 169 | // The correct behavior should yield the value of the last alternative. |
| 170 | op := NewConstValue(1, reg.NativeToValue(data)) |
| 171 | attr := attrs.RelativeAttribute(1, op) |
| 172 | qualA := makeQualifier(t, attrs, nil, 2, "a") |
| 173 | qualNeg1 := makeQualifier(t, attrs, nil, 3, int64(-1)) |
| 174 | attr.AddQualifier(qualA) |
| 175 | attr.AddQualifier(qualNeg1) |
| 176 | attr.AddQualifier(attrs.MaybeAttribute(4, "b")) |
| 177 | out, err := attr.Resolve(vars) |
| 178 | if err != nil { |
| 179 | t.Fatal(err) |
| 180 | } |
| 181 | if out != types.Int(42) { |
| 182 | t.Errorf("Got %v (%T), wanted 42", out, out) |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | func TestAttributesRelativeAttrConditional(t *testing.T) { |
| 187 | reg := newTestRegistry(t) |
nothing calls this directly
no test coverage detected