2018-05-22 19:43:36 +00:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2017-06-01 22:36:22 +00:00
|
|
|
|
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
2017-10-22 20:39:21 +00:00
|
|
|
"os"
|
2017-06-01 22:36:22 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-10-22 20:39:21 +00:00
|
|
|
|
Move assets and archives to their own package (#15157)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/archive"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/asset"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
|
2017-06-01 22:36:22 +00:00
|
|
|
)
|
|
|
|
|
2021-11-30 20:25:27 +00:00
|
|
|
func assertDeepEqualsIffEmptyDiff(t *testing.T, val1, val2 PropertyValue) {
|
|
|
|
diff := val1.Diff(val2)
|
|
|
|
equals := val1.DeepEquals(val2)
|
|
|
|
assert.Equal(t, diff == nil, equals, "DeepEquals <--> empty diff")
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:36:22 +00:00
|
|
|
func TestNullPropertyValueDiffs(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
d1 := NewNullProperty().Diff(NewNullProperty())
|
|
|
|
assert.Nil(t, d1)
|
2023-11-11 21:12:17 +00:00
|
|
|
d2 := NewNullProperty().Diff(NewProperty(true))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.NotNil(t, d2)
|
|
|
|
assert.Nil(t, d2.Array)
|
|
|
|
assert.Nil(t, d2.Object)
|
|
|
|
assert.True(t, d2.Old.IsNull())
|
|
|
|
assert.True(t, d2.New.IsBool())
|
|
|
|
assert.Equal(t, true, d2.New.BoolValue())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBoolPropertyValueDiffs(t *testing.T) {
|
|
|
|
t.Parallel()
|
2023-11-11 21:12:17 +00:00
|
|
|
d1 := NewProperty(true).Diff(NewProperty(true))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.Nil(t, d1)
|
2023-11-11 21:12:17 +00:00
|
|
|
d2 := NewProperty(true).Diff(NewProperty(false))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.NotNil(t, d2)
|
|
|
|
assert.Nil(t, d2.Array)
|
|
|
|
assert.Nil(t, d2.Object)
|
|
|
|
assert.True(t, d2.Old.IsBool())
|
|
|
|
assert.Equal(t, true, d2.Old.BoolValue())
|
|
|
|
assert.True(t, d2.New.IsBool())
|
|
|
|
assert.Equal(t, false, d2.New.BoolValue())
|
2023-11-11 21:12:17 +00:00
|
|
|
d3 := NewProperty(true).Diff(NewNullProperty())
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.NotNil(t, d3)
|
|
|
|
assert.Nil(t, d3.Array)
|
|
|
|
assert.Nil(t, d3.Object)
|
|
|
|
assert.True(t, d3.Old.IsBool())
|
|
|
|
assert.Equal(t, true, d3.Old.BoolValue())
|
|
|
|
assert.True(t, d3.New.IsNull())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNumberPropertyValueDiffs(t *testing.T) {
|
|
|
|
t.Parallel()
|
2023-11-11 21:12:17 +00:00
|
|
|
d1 := NewProperty(42.0).Diff(NewProperty(42.0))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.Nil(t, d1)
|
2023-11-11 21:12:17 +00:00
|
|
|
d2 := NewProperty(42.0).Diff(NewProperty(66.0))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.NotNil(t, d2)
|
|
|
|
assert.Nil(t, d2.Array)
|
|
|
|
assert.Nil(t, d2.Object)
|
|
|
|
assert.True(t, d2.Old.IsNumber())
|
|
|
|
assert.Equal(t, float64(42), d2.Old.NumberValue())
|
|
|
|
assert.True(t, d2.New.IsNumber())
|
|
|
|
assert.Equal(t, float64(66), d2.New.NumberValue())
|
2023-11-11 21:12:17 +00:00
|
|
|
d3 := NewProperty(88.0).Diff(NewProperty(true))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.NotNil(t, d3)
|
|
|
|
assert.Nil(t, d3.Array)
|
|
|
|
assert.Nil(t, d3.Object)
|
|
|
|
assert.True(t, d3.Old.IsNumber())
|
|
|
|
assert.Equal(t, float64(88), d3.Old.NumberValue())
|
|
|
|
assert.True(t, d3.New.IsBool())
|
|
|
|
assert.Equal(t, true, d3.New.BoolValue())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStringPropertyValueDiffs(t *testing.T) {
|
|
|
|
t.Parallel()
|
2023-11-11 21:12:17 +00:00
|
|
|
d1 := NewProperty("a string").Diff(NewProperty("a string"))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.Nil(t, d1)
|
2023-11-11 21:12:17 +00:00
|
|
|
d2 := NewProperty("a string").Diff(NewProperty("some other string"))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.NotNil(t, d2)
|
|
|
|
assert.True(t, d2.Old.IsString())
|
|
|
|
assert.Equal(t, "a string", d2.Old.StringValue())
|
|
|
|
assert.True(t, d2.New.IsString())
|
|
|
|
assert.Equal(t, "some other string", d2.New.StringValue())
|
2023-11-11 21:12:17 +00:00
|
|
|
d3 := NewProperty("what a string").Diff(NewProperty(973.0))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.NotNil(t, d3)
|
|
|
|
assert.Nil(t, d3.Array)
|
|
|
|
assert.Nil(t, d3.Object)
|
|
|
|
assert.True(t, d3.Old.IsString())
|
|
|
|
assert.Equal(t, "what a string", d3.Old.StringValue(), "what a string")
|
|
|
|
assert.True(t, d3.New.IsNumber())
|
|
|
|
assert.Equal(t, float64(973), d3.New.NumberValue())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestArrayPropertyValueDiffs(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
// no diffs:
|
2023-11-11 21:12:17 +00:00
|
|
|
d1 := NewProperty([]PropertyValue{}).Diff(NewProperty([]PropertyValue{}))
|
2017-06-01 22:36:22 +00:00
|
|
|
assert.Nil(t, d1)
|
2023-11-11 21:12:17 +00:00
|
|
|
d2 := NewProperty([]PropertyValue{
|
|
|
|
NewProperty("element one"), NewProperty(2.0), NewNullProperty(),
|
|
|
|
}).Diff(NewProperty([]PropertyValue{
|
|
|
|
NewProperty("element one"), NewProperty(2.0), NewNullProperty(),
|
2017-06-01 22:36:22 +00:00
|
|
|
}))
|
|
|
|
assert.Nil(t, d2)
|
|
|
|
// all updates:
|
2023-11-11 21:12:17 +00:00
|
|
|
d3a1 := NewProperty([]PropertyValue{
|
|
|
|
NewProperty("element one"), NewProperty(2.0), NewNullProperty(),
|
2023-03-03 16:36:39 +00:00
|
|
|
})
|
2023-11-11 21:12:17 +00:00
|
|
|
d3a2 := NewProperty([]PropertyValue{
|
|
|
|
NewProperty(1.0), NewNullProperty(), NewProperty("element three"),
|
2023-03-03 16:36:39 +00:00
|
|
|
})
|
2021-11-30 20:25:27 +00:00
|
|
|
assertDeepEqualsIffEmptyDiff(t, NewPropertyValue(d3a1), NewPropertyValue(d3a2))
|
2017-06-01 22:36:22 +00:00
|
|
|
d3 := d3a1.Diff(d3a2)
|
|
|
|
assert.NotNil(t, d3)
|
|
|
|
assert.NotNil(t, d3.Array)
|
|
|
|
assert.Nil(t, d3.Object)
|
|
|
|
assert.Equal(t, 0, len(d3.Array.Adds))
|
|
|
|
assert.Equal(t, 0, len(d3.Array.Deletes))
|
|
|
|
assert.Equal(t, 0, len(d3.Array.Sames))
|
|
|
|
assert.Equal(t, 3, len(d3.Array.Updates))
|
|
|
|
for i, update := range d3.Array.Updates {
|
|
|
|
assert.Equal(t, d3a1.ArrayValue()[i], update.Old)
|
|
|
|
assert.Equal(t, d3a2.ArrayValue()[i], update.New)
|
|
|
|
}
|
|
|
|
// update one, keep one, delete one:
|
2023-11-11 21:12:17 +00:00
|
|
|
d4a1 := NewProperty([]PropertyValue{
|
|
|
|
NewProperty("element one"), NewProperty(2.0), NewProperty(true),
|
2023-03-03 16:36:39 +00:00
|
|
|
})
|
2023-11-11 21:12:17 +00:00
|
|
|
d4a2 := NewProperty([]PropertyValue{
|
|
|
|
NewProperty("element 1"), NewProperty(2.0),
|
2023-03-03 16:36:39 +00:00
|
|
|
})
|
2021-11-30 20:25:27 +00:00
|
|
|
assertDeepEqualsIffEmptyDiff(t, NewPropertyValue(d4a1), NewPropertyValue(d4a2))
|
2017-06-01 22:36:22 +00:00
|
|
|
d4 := d4a1.Diff(d4a2)
|
|
|
|
assert.NotNil(t, d4)
|
|
|
|
assert.NotNil(t, d4.Array)
|
|
|
|
assert.Nil(t, d4.Object)
|
|
|
|
assert.Equal(t, 0, len(d4.Array.Adds))
|
|
|
|
assert.Equal(t, 1, len(d4.Array.Deletes))
|
|
|
|
for i, delete := range d4.Array.Deletes {
|
|
|
|
assert.Equal(t, 2, i)
|
|
|
|
assert.Equal(t, d4a1.ArrayValue()[i], delete)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 1, len(d4.Array.Sames))
|
|
|
|
for i, same := range d4.Array.Sames {
|
|
|
|
assert.Equal(t, 1, i)
|
|
|
|
assert.Equal(t, d4a1.ArrayValue()[i], same)
|
|
|
|
assert.Equal(t, d4a2.ArrayValue()[i], same)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 1, len(d4.Array.Updates))
|
|
|
|
for i, update := range d4.Array.Updates {
|
|
|
|
assert.Equal(t, 0, i)
|
|
|
|
assert.Equal(t, d4a1.ArrayValue()[i], update.Old)
|
|
|
|
assert.Equal(t, d4a2.ArrayValue()[i], update.New)
|
|
|
|
}
|
|
|
|
// keep one, update one, add one:
|
2023-11-11 21:12:17 +00:00
|
|
|
d5a1 := NewProperty([]PropertyValue{
|
|
|
|
NewProperty("element one"), NewProperty(2.0),
|
2023-03-03 16:36:39 +00:00
|
|
|
})
|
2023-11-11 21:12:17 +00:00
|
|
|
d5a2 := NewProperty([]PropertyValue{
|
|
|
|
NewProperty("element 1"), NewProperty(2.0), NewProperty(true),
|
2023-03-03 16:36:39 +00:00
|
|
|
})
|
2021-11-30 20:25:27 +00:00
|
|
|
assertDeepEqualsIffEmptyDiff(t, NewPropertyValue(d5a1), NewPropertyValue(d5a2))
|
2017-06-01 22:36:22 +00:00
|
|
|
d5 := d5a1.Diff(d5a2)
|
|
|
|
assert.NotNil(t, d5)
|
|
|
|
assert.NotNil(t, d5.Array)
|
|
|
|
assert.Nil(t, d5.Object)
|
|
|
|
assert.Equal(t, 1, len(d5.Array.Adds))
|
|
|
|
for i, add := range d5.Array.Adds {
|
|
|
|
assert.Equal(t, 2, i)
|
|
|
|
assert.Equal(t, d5a2.ArrayValue()[i], add)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 0, len(d5.Array.Deletes))
|
|
|
|
assert.Equal(t, 1, len(d5.Array.Sames))
|
|
|
|
for i, same := range d5.Array.Sames {
|
|
|
|
assert.Equal(t, 1, i)
|
|
|
|
assert.Equal(t, d5a1.ArrayValue()[i], same)
|
|
|
|
assert.Equal(t, d5a2.ArrayValue()[i], same)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 1, len(d5.Array.Updates))
|
|
|
|
for i, update := range d5.Array.Updates {
|
|
|
|
assert.Equal(t, 0, i)
|
|
|
|
assert.Equal(t, d5a1.ArrayValue()[i], update.Old)
|
|
|
|
assert.Equal(t, d5a2.ArrayValue()[i], update.New)
|
|
|
|
}
|
2017-06-06 23:42:14 +00:00
|
|
|
// from nil to empty array:
|
2023-11-11 21:12:17 +00:00
|
|
|
d6 := NewNullProperty().Diff(NewProperty([]PropertyValue{}))
|
2017-06-06 23:42:14 +00:00
|
|
|
assert.NotNil(t, d6)
|
2017-06-01 22:36:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestObjectPropertyValueDiffs(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
// no diffs:
|
|
|
|
d1 := PropertyMap{}.Diff(PropertyMap{})
|
|
|
|
assert.Nil(t, d1)
|
|
|
|
d2 := PropertyMap{
|
2023-11-11 21:12:17 +00:00
|
|
|
PropertyKey("a"): NewProperty(true),
|
2017-06-01 22:36:22 +00:00
|
|
|
}.Diff(PropertyMap{
|
2023-11-11 21:12:17 +00:00
|
|
|
PropertyKey("a"): NewProperty(true),
|
2017-06-01 22:36:22 +00:00
|
|
|
})
|
|
|
|
assert.Nil(t, d2)
|
|
|
|
// all updates:
|
|
|
|
{
|
|
|
|
obj1 := PropertyMap{
|
2023-11-11 21:12:17 +00:00
|
|
|
PropertyKey("prop-a"): NewProperty(true),
|
|
|
|
PropertyKey("prop-b"): NewProperty("bbb"),
|
|
|
|
PropertyKey("prop-c"): NewProperty(PropertyMap{
|
|
|
|
PropertyKey("inner-prop-a"): NewProperty(673.0),
|
2017-06-01 22:36:22 +00:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
obj2 := PropertyMap{
|
2023-11-11 21:12:17 +00:00
|
|
|
PropertyKey("prop-a"): NewProperty(false),
|
|
|
|
PropertyKey("prop-b"): NewProperty(89.0),
|
|
|
|
PropertyKey("prop-c"): NewProperty(PropertyMap{
|
|
|
|
PropertyKey("inner-prop-a"): NewProperty(672.0),
|
2017-06-01 22:36:22 +00:00
|
|
|
}),
|
|
|
|
}
|
2021-11-30 20:25:27 +00:00
|
|
|
assertDeepEqualsIffEmptyDiff(t, NewPropertyValue(obj1), NewPropertyValue(obj2))
|
2017-06-01 22:36:22 +00:00
|
|
|
d3 := obj1.Diff(obj2)
|
|
|
|
assert.NotNil(t, d3)
|
|
|
|
assert.Equal(t, 0, len(d3.Adds))
|
|
|
|
assert.Equal(t, 0, len(d3.Deletes))
|
|
|
|
assert.Equal(t, 0, len(d3.Sames))
|
|
|
|
assert.Equal(t, 3, len(d3.Updates))
|
|
|
|
d3pa := d3.Updates[PropertyKey("prop-a")]
|
|
|
|
assert.Nil(t, d3pa.Array)
|
|
|
|
assert.Nil(t, d3pa.Object)
|
|
|
|
assert.True(t, d3pa.Old.IsBool())
|
|
|
|
assert.Equal(t, true, d3pa.Old.BoolValue())
|
|
|
|
assert.True(t, d3pa.Old.IsBool())
|
|
|
|
assert.Equal(t, false, d3pa.New.BoolValue())
|
|
|
|
d3pb := d3.Updates[PropertyKey("prop-b")]
|
|
|
|
assert.Nil(t, d3pb.Array)
|
|
|
|
assert.Nil(t, d3pb.Object)
|
|
|
|
assert.True(t, d3pb.Old.IsString())
|
|
|
|
assert.Equal(t, "bbb", d3pb.Old.StringValue())
|
|
|
|
assert.True(t, d3pb.New.IsNumber())
|
|
|
|
assert.Equal(t, float64(89), d3pb.New.NumberValue())
|
|
|
|
d3pc := d3.Updates[PropertyKey("prop-c")]
|
|
|
|
assert.Nil(t, d3pc.Array)
|
|
|
|
assert.NotNil(t, d3pc.Object)
|
|
|
|
assert.Equal(t, 0, len(d3pc.Object.Adds))
|
|
|
|
assert.Equal(t, 0, len(d3pc.Object.Deletes))
|
|
|
|
assert.Equal(t, 0, len(d3pc.Object.Sames))
|
|
|
|
assert.Equal(t, 1, len(d3pc.Object.Updates))
|
|
|
|
d3pcu := d3pc.Object.Updates[PropertyKey("inner-prop-a")]
|
|
|
|
assert.True(t, d3pcu.Old.IsNumber())
|
|
|
|
assert.Equal(t, float64(673), d3pcu.Old.NumberValue())
|
|
|
|
assert.True(t, d3pcu.New.IsNumber())
|
|
|
|
assert.Equal(t, float64(672), d3pcu.New.NumberValue())
|
|
|
|
}
|
|
|
|
// add two (1 missing key, 1 null), update one, keep two, delete two (1 missing key, 1 null).
|
|
|
|
{
|
|
|
|
obj1 := PropertyMap{
|
|
|
|
PropertyKey("prop-a-2"): NewNullProperty(),
|
2023-11-11 21:12:17 +00:00
|
|
|
PropertyKey("prop-b"): NewProperty("bbb"),
|
|
|
|
PropertyKey("prop-c-1"): NewProperty(6767.0),
|
2017-06-01 22:36:22 +00:00
|
|
|
PropertyKey("prop-c-2"): NewNullProperty(),
|
2023-11-11 21:12:17 +00:00
|
|
|
PropertyKey("prop-d-1"): NewProperty(true),
|
|
|
|
PropertyKey("prop-d-2"): NewProperty(false),
|
2017-06-01 22:36:22 +00:00
|
|
|
}
|
|
|
|
obj2 := PropertyMap{
|
2023-11-11 21:12:17 +00:00
|
|
|
PropertyKey("prop-a-1"): NewProperty("a fresh value"),
|
|
|
|
PropertyKey("prop-a-2"): NewProperty("a non-nil value"),
|
|
|
|
PropertyKey("prop-b"): NewProperty(89.0),
|
|
|
|
PropertyKey("prop-c-1"): NewProperty(6767.0),
|
2017-06-01 22:36:22 +00:00
|
|
|
PropertyKey("prop-c-2"): NewNullProperty(),
|
|
|
|
PropertyKey("prop-d-2"): NewNullProperty(),
|
|
|
|
}
|
2021-11-30 20:25:27 +00:00
|
|
|
assertDeepEqualsIffEmptyDiff(t, NewPropertyValue(obj1), NewPropertyValue(obj2))
|
2017-06-01 22:36:22 +00:00
|
|
|
d4 := obj1.Diff(obj2)
|
|
|
|
assert.NotNil(t, d4)
|
|
|
|
assert.Equal(t, 2, len(d4.Adds))
|
|
|
|
assert.Equal(t, obj2[PropertyKey("prop-a-1")], d4.Adds[PropertyKey("prop-a-1")])
|
|
|
|
assert.Equal(t, obj2[PropertyKey("prop-a-2")], d4.Adds[PropertyKey("prop-a-2")])
|
|
|
|
assert.Equal(t, 2, len(d4.Deletes))
|
|
|
|
assert.Equal(t, obj1[PropertyKey("prop-d-1")], d4.Deletes[PropertyKey("prop-d-1")])
|
|
|
|
assert.Equal(t, obj1[PropertyKey("prop-d-2")], d4.Deletes[PropertyKey("prop-d-2")])
|
|
|
|
assert.Equal(t, 2, len(d4.Sames))
|
|
|
|
assert.Equal(t, obj1[PropertyKey("prop-c-1")], d4.Sames[PropertyKey("prop-c-1")])
|
|
|
|
assert.Equal(t, obj1[PropertyKey("prop-c-2")], d4.Sames[PropertyKey("prop-c-2")])
|
|
|
|
assert.Equal(t, obj2[PropertyKey("prop-c-1")], d4.Sames[PropertyKey("prop-c-1")])
|
|
|
|
assert.Equal(t, obj2[PropertyKey("prop-c-2")], d4.Sames[PropertyKey("prop-c-2")])
|
|
|
|
assert.Equal(t, 1, len(d4.Updates))
|
|
|
|
assert.Equal(t, obj1[PropertyKey("prop-b")], d4.Updates[PropertyKey("prop-b")].Old)
|
|
|
|
assert.Equal(t, obj2[PropertyKey("prop-b")], d4.Updates[PropertyKey("prop-b")].New)
|
|
|
|
}
|
|
|
|
}
|
2017-07-17 19:11:15 +00:00
|
|
|
|
|
|
|
func TestAssetPropertyValueDiffs(t *testing.T) {
|
|
|
|
t.Parallel()
|
Move assets and archives to their own package (#15157)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
a1, err := asset.FromText("test")
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2023-11-11 21:12:17 +00:00
|
|
|
d1 := NewProperty(a1).Diff(NewProperty(a1))
|
2017-07-17 19:11:15 +00:00
|
|
|
assert.Nil(t, d1)
|
Move assets and archives to their own package (#15157)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
a2, err := asset.FromText("test2")
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2023-11-11 21:12:17 +00:00
|
|
|
d2 := NewProperty(a1).Diff(NewProperty(a2))
|
2017-07-17 19:11:15 +00:00
|
|
|
assert.NotNil(t, d2)
|
|
|
|
assert.Nil(t, d2.Array)
|
|
|
|
assert.Nil(t, d2.Object)
|
|
|
|
assert.True(t, d2.Old.IsAsset())
|
|
|
|
assert.Equal(t, "test", d2.Old.AssetValue().Text)
|
|
|
|
assert.True(t, d2.New.IsAsset())
|
|
|
|
assert.Equal(t, "test2", d2.New.AssetValue().Text)
|
2023-11-11 21:12:17 +00:00
|
|
|
d3 := NewProperty(a1).Diff(NewNullProperty())
|
2017-07-17 19:11:15 +00:00
|
|
|
assert.NotNil(t, d3)
|
|
|
|
assert.Nil(t, d3.Array)
|
|
|
|
assert.Nil(t, d3.Object)
|
|
|
|
assert.True(t, d3.Old.IsAsset())
|
|
|
|
assert.Equal(t, "test", d3.Old.AssetValue().Text)
|
|
|
|
assert.True(t, d3.New.IsNull())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestArchivePropertyValueDiffs(t *testing.T) {
|
|
|
|
t.Parallel()
|
2017-11-12 19:45:13 +00:00
|
|
|
path, err := tempArchive("test", false)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2017-10-22 20:39:21 +00:00
|
|
|
defer func() { contract.IgnoreError(os.Remove(path)) }()
|
Move assets and archives to their own package (#15157)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
a1, err := archive.FromPath(path)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2023-11-11 21:12:17 +00:00
|
|
|
d1 := NewProperty(a1).Diff(NewProperty(a1))
|
2017-07-17 19:11:15 +00:00
|
|
|
assert.Nil(t, d1)
|
2017-11-12 19:45:13 +00:00
|
|
|
path2, err := tempArchive("test2", true)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2017-10-22 20:39:21 +00:00
|
|
|
defer func() { contract.IgnoreError(os.Remove(path)) }()
|
Move assets and archives to their own package (#15157)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
This PR is motivated by https://github.com/pulumi/pulumi/pull/15145.
`resource.*` should be built on top of `property.Value`,[^1] which means
that `resource`
needs to be able to import `property.Value`, and so `property` cannot
import
`resource`. Since Assets and Archives are both types of properties, they
must be moved out
of `resource`.
[^1]: For example:
https://github.com/pulumi/pulumi/blob/a1d686227cd7e3c70c51bd772450cb0cd57c1479/sdk/go/common/resource/resource_state.go#L35-L36
## Open Question
This PR moves them to their own sub-folders in `resource`. Should
`asset` and `archive`
live somewhere more high level, like `sdk/go/property/{asset,archive}`?
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-25 20:39:31 +00:00
|
|
|
a2, err := archive.FromPath(path2)
|
2023-10-13 09:46:07 +00:00
|
|
|
assert.NoError(t, err)
|
2023-11-11 21:12:17 +00:00
|
|
|
d2 := NewProperty(a1).Diff(NewProperty(a2))
|
2017-07-17 19:11:15 +00:00
|
|
|
assert.NotNil(t, d2)
|
|
|
|
assert.Nil(t, d2.Array)
|
|
|
|
assert.Nil(t, d2.Object)
|
|
|
|
assert.True(t, d2.Old.IsArchive())
|
2017-10-22 20:39:21 +00:00
|
|
|
assert.Equal(t, path, d2.Old.ArchiveValue().Path)
|
2017-07-17 19:11:15 +00:00
|
|
|
assert.True(t, d2.New.IsArchive())
|
2017-10-22 20:39:21 +00:00
|
|
|
assert.Equal(t, path2, d2.New.ArchiveValue().Path)
|
2023-11-11 21:12:17 +00:00
|
|
|
d3 := NewProperty(a1).Diff(NewNullProperty())
|
2017-07-17 19:11:15 +00:00
|
|
|
assert.NotNil(t, d3)
|
|
|
|
assert.Nil(t, d3.Array)
|
|
|
|
assert.Nil(t, d3.Object)
|
|
|
|
assert.True(t, d3.Old.IsArchive())
|
2017-10-22 20:39:21 +00:00
|
|
|
assert.Equal(t, path, d3.Old.ArchiveValue().Path)
|
2017-07-17 19:11:15 +00:00
|
|
|
assert.True(t, d3.New.IsNull())
|
|
|
|
}
|
2019-05-15 21:41:28 +00:00
|
|
|
|
|
|
|
func TestMismatchedPropertyValueDiff(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
a1 := NewPropertyValue([]string{"a", "b", "c"})
|
|
|
|
a2 := NewPropertyValue([]string{"a", "b", "c"})
|
|
|
|
|
|
|
|
s1 := MakeSecret(a1)
|
|
|
|
s2 := MakeSecret(a2)
|
|
|
|
|
|
|
|
assert.True(t, s2.DeepEquals(s1))
|
|
|
|
assert.True(t, s1.DeepEquals(s2))
|
|
|
|
}
|