Skip to content

Commit a987fcb

Browse files
authored
Remove YamlEqual method to remove duplicate work and bash commands (#134)
Description of changes: Remove yaml equality check from `util.go` as it is not necessary if we check the spec like we check the status. This will also remove the usage of bash commands such as `sed`, `diff`, and `cat`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent c47310a commit a987fcb

File tree

19 files changed

+87
-289
lines changed

19 files changed

+87
-289
lines changed

pkg/resource/data_quality_job_definition/manager_test_suite_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2124
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2225
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
2326
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2427
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2528
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
26-
"github.com/ghodss/yaml"
2729
"github.com/google/go-cmp/cmp"
2830
"github.com/google/go-cmp/cmp/cmpopts"
2931
"go.uber.org/zap/zapcore"
30-
"path/filepath"
3132
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
32-
"testing"
3333
)
3434

3535
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -128,12 +128,3 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
128128

129129
return statusMatch && specMatch
130130
}
131-
132-
// Checks to see if the given yaml file, with name stored as expectation,
133-
// matches the yaml marshal of the AWSResource stored as actual.
134-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
135-
// Build a tmp file for the actual yaml.
136-
actualResource := actual.(*resource)
137-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
138-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
139-
}

pkg/resource/endpoint/manager_test_suite_test.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2124
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2225
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
2326
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
2427
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2528
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2629
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
27-
"github.com/ghodss/yaml"
2830
"github.com/google/go-cmp/cmp"
2931
"github.com/google/go-cmp/cmp/cmpopts"
3032
"go.uber.org/zap/zapcore"
31-
"path/filepath"
3233
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
33-
"testing"
3434
)
3535

3636
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -117,20 +117,23 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
117117
cmpopts.IgnoreFields(svcapitypes.DeployedImage{}, "ResolutionTime"),
118118
}
119119

120+
var specMatch = false
121+
if cmp.Equal(ac.ko.Spec, bc.ko.Spec, opts...) {
122+
specMatch = true
123+
} else {
124+
fmt.Printf("Difference ko.Spec (-expected +actual):\n\n")
125+
fmt.Println(cmp.Diff(ac.ko.Spec, bc.ko.Spec, opts...))
126+
specMatch = false
127+
}
128+
129+
var statusMatch = false
120130
if cmp.Equal(ac.ko.Status, bc.ko.Status, opts...) {
121-
return true
131+
statusMatch = true
122132
} else {
123-
fmt.Printf("Difference (-expected +actual):\n\n")
133+
fmt.Printf("Difference ko.Status (-expected +actual):\n\n")
124134
fmt.Println(cmp.Diff(ac.ko.Status, bc.ko.Status, opts...))
125-
return false
135+
statusMatch = false
126136
}
127-
}
128137

129-
// Checks to see if the given yaml file, with name stored as expectation,
130-
// matches the yaml marshal of the AWSResource stored as actual.
131-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
132-
// Build a tmp file for the actual yaml.
133-
actualResource := actual.(*resource)
134-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
135-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
138+
return statusMatch && specMatch
136139
}

pkg/resource/endpoint_config/manager_test_suite_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2124
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2225
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
2326
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2427
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2528
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
26-
"github.com/ghodss/yaml"
2729
"github.com/google/go-cmp/cmp"
2830
"github.com/google/go-cmp/cmp/cmpopts"
2931
"go.uber.org/zap/zapcore"
30-
"path/filepath"
3132
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
32-
"testing"
3333
)
3434

3535
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -122,12 +122,3 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
122122

123123
return statusMatch && specMatch
124124
}
125-
126-
// Checks to see if the given yaml file, with name stored as expectation,
127-
// matches the yaml marshal of the AWSResource stored as actual.
128-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
129-
// Build a tmp file for the actual yaml.
130-
actualResource := actual.(*resource)
131-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
132-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
133-
}

pkg/resource/feature_group/manager_test_suite_test.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2124
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2225
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
2326
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2427
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2528
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
26-
"github.com/ghodss/yaml"
2729
"github.com/google/go-cmp/cmp"
2830
"github.com/google/go-cmp/cmp/cmpopts"
2931
"go.uber.org/zap/zapcore"
30-
"path/filepath"
3132
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
32-
"testing"
3333
)
3434

3535
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -108,20 +108,23 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
108108
// Ignore LastTransitionTime since it gets updated each run.
109109
opts := []cmp.Option{cmpopts.EquateEmpty(), cmpopts.IgnoreFields(ackv1alpha1.Condition{}, "LastTransitionTime")}
110110

111+
var specMatch = false
112+
if cmp.Equal(ac.ko.Spec, bc.ko.Spec, opts...) {
113+
specMatch = true
114+
} else {
115+
fmt.Printf("Difference ko.Spec (-expected +actual):\n\n")
116+
fmt.Println(cmp.Diff(ac.ko.Spec, bc.ko.Spec, opts...))
117+
specMatch = false
118+
}
119+
120+
var statusMatch = false
111121
if cmp.Equal(ac.ko.Status, bc.ko.Status, opts...) {
112-
return true
122+
statusMatch = true
113123
} else {
114-
fmt.Printf("Difference (-expected +actual):\n\n")
124+
fmt.Printf("Difference ko.Status (-expected +actual):\n\n")
115125
fmt.Println(cmp.Diff(ac.ko.Status, bc.ko.Status, opts...))
116-
return false
126+
statusMatch = false
117127
}
118-
}
119128

120-
// Checks to see if the given yaml file, with name stored as expectation,
121-
// matches the yaml marshal of the AWSResource stored as actual.
122-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
123-
// Build a tmp file for the actual yaml.
124-
actualResource := actual.(*resource)
125-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
126-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
129+
return statusMatch && specMatch
127130
}

pkg/resource/hyper_parameter_tuning_job/manager_test_suite_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"path/filepath"
2929
"testing"
3030

31-
"github.com/ghodss/yaml"
3231
"github.com/google/go-cmp/cmp"
3332
"github.com/google/go-cmp/cmp/cmpopts"
3433
"go.uber.org/zap/zapcore"
@@ -129,12 +128,3 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
129128

130129
return statusMatch && specMatch
131130
}
132-
133-
// Checks to see if the given yaml file, with name stored as expectation,
134-
// matches the yaml marshal of the AWSResource stored as actual.
135-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
136-
// Build a tmp file for the actual yaml.
137-
actualResource := actual.(*resource)
138-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
139-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
140-
}

pkg/resource/model/manager_test_suite_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2124
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2225
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
2326
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2427
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2528
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
26-
"github.com/ghodss/yaml"
2729
"github.com/google/go-cmp/cmp"
2830
"github.com/google/go-cmp/cmp/cmpopts"
2931
"go.uber.org/zap/zapcore"
30-
"path/filepath"
3132
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
32-
"testing"
3333
)
3434

3535
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -122,12 +122,3 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
122122

123123
return statusMatch && specMatch
124124
}
125-
126-
// Checks to see if the given yaml file, with name stored as expectation,
127-
// matches the yaml marshal of the AWSResource stored as actual.
128-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
129-
// Build a tmp file for the actual yaml.
130-
actualResource := actual.(*resource)
131-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
132-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
133-
}

pkg/resource/model_bias_job_definition/manager_test_suite_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2124
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2225
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
2326
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2427
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2528
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
26-
"github.com/ghodss/yaml"
2729
"github.com/google/go-cmp/cmp"
2830
"github.com/google/go-cmp/cmp/cmpopts"
2931
"go.uber.org/zap/zapcore"
30-
"path/filepath"
3132
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
32-
"testing"
3333
)
3434

3535
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -122,12 +122,3 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
122122

123123
return statusMatch && specMatch
124124
}
125-
126-
// Checks to see if the given yaml file, with name stored as expectation,
127-
// matches the yaml marshal of the AWSResource stored as actual.
128-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
129-
// Build a tmp file for the actual yaml.
130-
actualResource := actual.(*resource)
131-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
132-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
133-
}

pkg/resource/model_explainability_job_definition/manager_test_suite_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2124
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2225
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
2326
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2427
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2528
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
26-
"github.com/ghodss/yaml"
2729
"github.com/google/go-cmp/cmp"
2830
"github.com/google/go-cmp/cmp/cmpopts"
2931
"go.uber.org/zap/zapcore"
30-
"path/filepath"
3132
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
32-
"testing"
3333
)
3434

3535
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -122,12 +122,3 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
122122

123123
return statusMatch && specMatch
124124
}
125-
126-
// Checks to see if the given yaml file, with name stored as expectation,
127-
// matches the yaml marshal of the AWSResource stored as actual.
128-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
129-
// Build a tmp file for the actual yaml.
130-
actualResource := actual.(*resource)
131-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
132-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
133-
}

pkg/resource/model_package/manager_test_suite_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2124
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2225
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
2326
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
2427
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2528
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2629
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
27-
"github.com/ghodss/yaml"
2830
"github.com/google/go-cmp/cmp"
2931
"github.com/google/go-cmp/cmp/cmpopts"
3032
"go.uber.org/zap/zapcore"
31-
"path/filepath"
3233
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
33-
"testing"
3434
)
3535

3636
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -129,12 +129,3 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
129129

130130
return statusMatch && specMatch
131131
}
132-
133-
// Checks to see if the given yaml file, with name stored as expectation,
134-
// matches the yaml marshal of the AWSResource stored as actual.
135-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
136-
// Build a tmp file for the actual yaml.
137-
actualResource := actual.(*resource)
138-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
139-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
140-
}

pkg/resource/model_package_group/manager_test_suite_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2124
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2225
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
2326
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2427
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2528
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
26-
"github.com/ghodss/yaml"
2729
"github.com/google/go-cmp/cmp"
2830
"github.com/google/go-cmp/cmp/cmpopts"
2931
"go.uber.org/zap/zapcore"
30-
"path/filepath"
3132
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
32-
"testing"
3333
)
3434

3535
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -122,12 +122,3 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
122122

123123
return statusMatch && specMatch
124124
}
125-
126-
// Checks to see if the given yaml file, with name stored as expectation,
127-
// matches the yaml marshal of the AWSResource stored as actual.
128-
func (d *testRunnerDelegate) YamlEqual(expectation string, actual acktypes.AWSResource) bool {
129-
// Build a tmp file for the actual yaml.
130-
actualResource := actual.(*resource)
131-
actualYamlByteArray, _ := yaml.Marshal(actualResource.ko)
132-
return testutil.IsYamlEqual(&expectation, &actualYamlByteArray)
133-
}

0 commit comments

Comments
 (0)