@@ -39,6 +39,8 @@ import (
3939 "github.com/enterprise-contract/ec-cli/internal/output"
4040 "github.com/enterprise-contract/ec-cli/internal/policy"
4141 "github.com/enterprise-contract/ec-cli/internal/utils"
42+ "github.com/enterprise-contract/ec-cli/internal/utils/oci"
43+ "github.com/enterprise-contract/ec-cli/internal/utils/oci/fake"
4244)
4345
4446type data struct {
@@ -229,9 +231,9 @@ func Test_determineInputSpec(t *testing.T) {
229231 },
230232 },
231233 }
232- mockRemoteClient := & MockRemoteClient {}
233- commonMockClient (mockRemoteClient )
234- ctx := context . WithValue (context .Background (), applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
234+ client := fake. FakeClient {}
235+ commonMockClient (& client )
236+ ctx := oci . WithClient (context .Background (), & client )
235237 for _ , c := range cases {
236238 t .Run (c .name , func (t * testing.T ) {
237239 s , err := applicationsnapshot .DetermineInputSpec (ctx , applicationsnapshot.Input {
@@ -287,10 +289,10 @@ func Test_ValidateImageCommand(t *testing.T) {
287289 validateImageCmd := validateImageCmd (validate )
288290 cmd := setUpCobra (validateImageCmd )
289291
290- mockRemoteClient := & MockRemoteClient {}
291- commonMockClient (mockRemoteClient )
292- ctx := utils .WithFS (context .TODO (), afero .NewMemMapFs ())
293- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
292+ client := fake. FakeClient {}
293+ commonMockClient (& client )
294+ ctx := utils .WithFS (context .Background (), afero .NewMemMapFs ())
295+ ctx = oci . WithClient (ctx , & client )
294296 cmd .SetContext (ctx )
295297
296298 effectiveTimeTest := time .Now ().UTC ().Format (time .RFC3339Nano )
@@ -367,10 +369,10 @@ func Test_ValidateImageCommandImages(t *testing.T) {
367369 validateImageCmd := validateImageCmd (validate )
368370 cmd := setUpCobra (validateImageCmd )
369371
370- mockRemoteClient := & MockRemoteClient {}
371- commonMockClient (mockRemoteClient )
372- ctx := utils .WithFS (context .TODO (), afero .NewMemMapFs ())
373- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
372+ client := fake. FakeClient {}
373+ commonMockClient (& client )
374+ ctx := utils .WithFS (context .Background (), afero .NewMemMapFs ())
375+ ctx = oci . WithClient (ctx , & client )
374376 cmd .SetContext (ctx )
375377
376378 effectiveTimeTest := time .Now ().UTC ().Format (time .RFC3339Nano )
@@ -467,10 +469,10 @@ func Test_ValidateImageCommandKeyless(t *testing.T) {
467469 })
468470 cmd := setUpCobra (validateImageCmd )
469471
470- mockRemoteClient := & MockRemoteClient {}
471- commonMockClient (mockRemoteClient )
472- ctx := utils .WithFS (context .TODO (), afero .NewMemMapFs ())
473- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
472+ client := fake. FakeClient {}
473+ commonMockClient (& client )
474+ ctx := utils .WithFS (context .Background (), afero .NewMemMapFs ())
475+ ctx = oci . WithClient (ctx , & client )
474476 cmd .SetContext (ctx )
475477
476478 cmd .SetArgs (append (rootArgs , []string {
@@ -533,11 +535,11 @@ func Test_ValidateImageCommandYAMLPolicyFile(t *testing.T) {
533535 validateImageCmd := validateImageCmd (validate )
534536 cmd := setUpCobra (validateImageCmd )
535537
536- mockRemoteClient := & MockRemoteClient {}
537- commonMockClient (mockRemoteClient )
538+ client := fake. FakeClient {}
539+ commonMockClient (& client )
538540 fs := afero .NewMemMapFs ()
539- ctx := utils .WithFS (context .TODO (), fs )
540- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
541+ ctx := utils .WithFS (context .Background (), fs )
542+ ctx = oci . WithClient (ctx , & client )
541543 cmd .SetContext (ctx )
542544
543545 cases := []struct {
@@ -650,11 +652,11 @@ func Test_ValidateImageCommandJSONPolicyFile(t *testing.T) {
650652 validateImageCmd := validateImageCmd (validate )
651653 cmd := setUpCobra (validateImageCmd )
652654
653- mockRemoteClient := & MockRemoteClient {}
654- commonMockClient (mockRemoteClient )
655+ client := fake. FakeClient {}
656+ commonMockClient (& client )
655657 fs := afero .NewMemMapFs ()
656- ctx := utils .WithFS (context .TODO (), fs )
657- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
658+ ctx := utils .WithFS (context .Background (), fs )
659+ ctx = oci . WithClient (ctx , & client )
658660 cmd .SetContext (ctx )
659661
660662 testPolicyJSON := `sources:
@@ -731,10 +733,10 @@ func Test_ValidateImageCommandExtraData(t *testing.T) {
731733
732734 fs := afero .NewMemMapFs ()
733735
734- ctx := utils .WithFS (context .TODO (), fs )
735- mockRemoteClient := & MockRemoteClient {}
736- commonMockClient (mockRemoteClient )
737- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
736+ ctx := utils .WithFS (context .Background (), fs )
737+ client := fake. FakeClient {}
738+ commonMockClient (& client )
739+ ctx = oci . WithClient (ctx , & client )
738740
739741 cmd .SetContext (ctx )
740742
@@ -832,11 +834,11 @@ func Test_ValidateImageCommandEmptyPolicyFile(t *testing.T) {
832834 validateImageCmd := validateImageCmd (validate )
833835 cmd := setUpCobra (validateImageCmd )
834836
835- mockRemoteClient := & MockRemoteClient {}
836- commonMockClient (mockRemoteClient )
837+ client := fake. FakeClient {}
838+ commonMockClient (& client )
837839 fs := afero .NewMemMapFs ()
838- ctx := utils .WithFS (context .TODO (), fs )
839- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
840+ ctx := utils .WithFS (context .Background (), fs )
841+ ctx = oci . WithClient (ctx , & client )
840842 cmd .SetContext (ctx )
841843
842844 err := afero .WriteFile (fs , "/policy.yaml" , []byte (nil ), 0644 )
@@ -930,10 +932,10 @@ func Test_ValidateErrorCommand(t *testing.T) {
930932 validateImageCmd := validateImageCmd (validate )
931933 cmd := setUpCobra (validateImageCmd )
932934
933- mockRemoteClient := & MockRemoteClient {}
934- commonMockClient (mockRemoteClient )
935- ctx := utils .WithFS (context .TODO (), afero .NewMemMapFs ())
936- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
935+ client := fake. FakeClient {}
936+ commonMockClient (& client )
937+ ctx := utils .WithFS (context .Background (), afero .NewMemMapFs ())
938+ ctx = oci . WithClient (ctx , & client )
937939 cmd .SetContext (ctx )
938940
939941 cmd .SetArgs (append ([]string {"validate" , "image" }, c .args ... ))
@@ -975,10 +977,10 @@ func Test_FailureImageAccessibility(t *testing.T) {
975977 cmd := setUpCobra (validateImageCmd )
976978 cmd .SilenceUsage = true // The root command is set to prevent usage printouts when running the CLI directly. This setup is temporary workaround.
977979
978- mockRemoteClient := & MockRemoteClient {}
979- commonMockClient (mockRemoteClient )
980- ctx := utils .WithFS (context .TODO (), afero .NewMemMapFs ())
981- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
980+ client := fake. FakeClient {}
981+ commonMockClient (& client )
982+ ctx := utils .WithFS (context .Background (), afero .NewMemMapFs ())
983+ ctx = oci . WithClient (ctx , & client )
982984 cmd .SetContext (ctx )
983985
984986 effectiveTimeTest := time .Now ().UTC ().Format (time .RFC3339Nano )
@@ -1045,10 +1047,10 @@ func Test_FailureOutput(t *testing.T) {
10451047 cmd := setUpCobra (validateImageCmd )
10461048 cmd .SilenceUsage = true // The root command is set to prevent usage printouts when running the CLI directly. This setup is temporary workaround.
10471049
1048- mockRemoteClient := & MockRemoteClient {}
1049- commonMockClient (mockRemoteClient )
1050- ctx := utils .WithFS (context .TODO (), afero .NewMemMapFs ())
1051- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
1050+ client := fake. FakeClient {}
1051+ commonMockClient (& client )
1052+ ctx := utils .WithFS (context .Background (), afero .NewMemMapFs ())
1053+ ctx = oci . WithClient (ctx , & client )
10521054 cmd .SetContext (ctx )
10531055
10541056 effectiveTimeTest := time .Now ().UTC ().Format (time .RFC3339Nano )
@@ -1119,10 +1121,10 @@ func Test_WarningOutput(t *testing.T) {
11191121 validateImageCmd := validateImageCmd (validate )
11201122 cmd := setUpCobra (validateImageCmd )
11211123
1122- mockRemoteClient := & MockRemoteClient {}
1123- commonMockClient (mockRemoteClient )
1124- ctx := utils .WithFS (context .TODO (), afero .NewMemMapFs ())
1125- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
1124+ client := fake. FakeClient {}
1125+ commonMockClient (& client )
1126+ ctx := utils .WithFS (context .Background (), afero .NewMemMapFs ())
1127+ ctx = oci . WithClient (ctx , & client )
11261128 cmd .SetContext (ctx )
11271129
11281130 effectiveTimeTest := time .Now ().UTC ().Format (time .RFC3339Nano )
@@ -1184,10 +1186,10 @@ func Test_FailureImageAccessibilityNonStrict(t *testing.T) {
11841186 cmd := setUpCobra (validateImageCmd )
11851187 cmd .SilenceUsage = true // The root command is set to prevent usage printouts when running the CLI directly. This setup is temporary workaround.
11861188
1187- mockRemoteClient := & MockRemoteClient {}
1188- commonMockClient (mockRemoteClient )
1189- ctx := utils .WithFS (context .TODO (), afero .NewMemMapFs ())
1190- ctx = context . WithValue (ctx , applicationsnapshot. RemoteClientKey {}, mockRemoteClient )
1189+ client := fake. FakeClient {}
1190+ commonMockClient (& client )
1191+ ctx := utils .WithFS (context .Background (), afero .NewMemMapFs ())
1192+ ctx = oci . WithClient (ctx , & client )
11911193 cmd .SetContext (ctx )
11921194
11931195 effectiveTimeTest := time .Now ().UTC ().Format (time .RFC3339Nano )
@@ -1272,10 +1274,9 @@ func TestValidateImageCommand_RunE(t *testing.T) {
12721274 cmd := setUpCobra (validateImageCmd )
12731275
12741276 ctx := utils .WithFS (context .Background (), afero .NewMemMapFs ())
1275- mockRemoteClient := & MockRemoteClient {}
1276- commonMockClient (mockRemoteClient )
1277- ctx = context .WithValue (ctx , applicationsnapshot.RemoteClientKey {}, mockRemoteClient )
1278-
1277+ client := fake.FakeClient {}
1278+ commonMockClient (& client )
1279+ ctx = oci .WithClient (ctx , & client )
12791280 cmd .SetContext (ctx )
12801281
12811282 effectiveTimeTest := time .Now ().UTC ().Format (time .RFC3339Nano )
0 commit comments