@@ -6,12 +6,16 @@ import (
6
6
"context"
7
7
"crypto/tls"
8
8
"crypto/x509"
9
+ "encoding/json"
9
10
"errors"
10
11
"fmt"
12
+ "io"
11
13
"net/http"
14
+ "os"
12
15
"testing"
13
16
"time"
14
17
18
+ "github.com/fatih/color"
15
19
"github.com/google/go-cmp/cmp"
16
20
"github.com/google/go-cmp/cmp/cmpopts"
17
21
deckDump "github.com/kong/go-database-reconciler/pkg/dump"
@@ -7441,6 +7445,44 @@ func Test_Sync_ConsumerGroupPlugin_Policy_Overrides_34x(t *testing.T) {
7441
7445
require .Error (t , err )
7442
7446
assert .ErrorContains (t , err , errorConsumerGroupPolicies )
7443
7447
})
7448
+
7449
+ t .Run ("checking for valid json output while using --consumer-group-policy-overrides = true" , func (t * testing.T ) {
7450
+ // overwrite default standard output
7451
+ r , w , err := os .Pipe ()
7452
+ require .NoError (t , err )
7453
+ color .Output = w
7454
+
7455
+ require .NoError (t , sync (ctx , "testdata/sync/037-consumer-group-policy-overrides/kong34x-no-info.yaml" ,
7456
+ "--consumer-group-policy-overrides" , "--json-output" ))
7457
+
7458
+ // read command output
7459
+ w .Close ()
7460
+ out , err := io .ReadAll (r )
7461
+ require .NoError (t , err )
7462
+ require .NotNil (t , out )
7463
+
7464
+ var js interface {}
7465
+ assert .NoError (t , json .Unmarshal (out , & js ), "JSON validation failed" )
7466
+ })
7467
+
7468
+ t .Run ("checking for valid json output while using consumer-group-policy-overrides in info block" , func (t * testing.T ) {
7469
+ // overwrite default standard output
7470
+ r , w , err := os .Pipe ()
7471
+ require .NoError (t , err )
7472
+ color .Output = w
7473
+
7474
+ require .NoError (t , sync (ctx , "testdata/sync/037-consumer-group-policy-overrides/kong34x.yaml" ,
7475
+ "--json-output" ))
7476
+
7477
+ // read command output
7478
+ w .Close ()
7479
+ out , err := io .ReadAll (r )
7480
+ require .NoError (t , err )
7481
+ require .NotNil (t , out )
7482
+
7483
+ var js interface {}
7484
+ assert .NoError (t , json .Unmarshal (out , & js ), "JSON validation failed" )
7485
+ })
7444
7486
}
7445
7487
7446
7488
// test scope:
@@ -7563,6 +7605,44 @@ func Test_Sync_ConsumerGroupPlugin_Policy_Overrides_38x(t *testing.T) {
7563
7605
require .Error (t , err )
7564
7606
assert .ErrorContains (t , err , errorConsumerGroupPolicies )
7565
7607
})
7608
+
7609
+ t .Run ("checking for valid json output while using --consumer-group-policy-overrides = true" , func (t * testing.T ) {
7610
+ // overwrite default standard output
7611
+ r , w , err := os .Pipe ()
7612
+ require .NoError (t , err )
7613
+ color .Output = w
7614
+
7615
+ require .NoError (t , sync (ctx , "testdata/sync/037-consumer-group-policy-overrides/kong38x-no-info.yaml" ,
7616
+ "--consumer-group-policy-overrides" , "--json-output" ))
7617
+
7618
+ // read command output
7619
+ w .Close ()
7620
+ out , err := io .ReadAll (r )
7621
+ require .NoError (t , err )
7622
+ require .NotNil (t , out )
7623
+
7624
+ var js interface {}
7625
+ assert .NoError (t , json .Unmarshal (out , & js ), "JSON validation failed" )
7626
+ })
7627
+
7628
+ t .Run ("checking for valid json output while using consumer-group-policy-overrides in info block" , func (t * testing.T ) {
7629
+ // overwrite default standard output
7630
+ r , w , err := os .Pipe ()
7631
+ require .NoError (t , err )
7632
+ color .Output = w
7633
+
7634
+ require .NoError (t , sync (ctx , "testdata/sync/037-consumer-group-policy-overrides/kong38x.yaml" ,
7635
+ "--json-output" ))
7636
+
7637
+ // read command output
7638
+ w .Close ()
7639
+ out , err := io .ReadAll (r )
7640
+ require .NoError (t , err )
7641
+ require .NotNil (t , out )
7642
+
7643
+ var js interface {}
7644
+ assert .NoError (t , json .Unmarshal (out , & js ), "JSON validation failed" )
7645
+ })
7566
7646
}
7567
7647
7568
7648
// test scope:
@@ -7688,6 +7768,44 @@ func Test_Sync_ConsumerGroupPlugin_Policy_Overrides_39x(t *testing.T) {
7688
7768
require .Error (t , err )
7689
7769
assert .ErrorContains (t , err , errorConsumerGroupPolicies )
7690
7770
})
7771
+
7772
+ t .Run ("checking for valid json output while using --consumer-group-policy-overrides = true" , func (t * testing.T ) {
7773
+ // overwrite default standard output
7774
+ r , w , err := os .Pipe ()
7775
+ require .NoError (t , err )
7776
+ color .Output = w
7777
+
7778
+ require .NoError (t , sync (ctx , "testdata/sync/037-consumer-group-policy-overrides/kong39x-no-info.yaml" ,
7779
+ "--consumer-group-policy-overrides" , "--json-output" ))
7780
+
7781
+ // read command output
7782
+ w .Close ()
7783
+ out , err := io .ReadAll (r )
7784
+ require .NoError (t , err )
7785
+ require .NotNil (t , out )
7786
+
7787
+ var js interface {}
7788
+ assert .NoError (t , json .Unmarshal (out , & js ), "JSON validation failed" )
7789
+ })
7790
+
7791
+ t .Run ("checking for valid json output while using consumer-group-policy-overrides in info block" , func (t * testing.T ) {
7792
+ // overwrite default standard output
7793
+ r , w , err := os .Pipe ()
7794
+ require .NoError (t , err )
7795
+ color .Output = w
7796
+
7797
+ require .NoError (t , sync (ctx , "testdata/sync/037-consumer-group-policy-overrides/kong39x.yaml" ,
7798
+ "--json-output" ))
7799
+
7800
+ // read command output
7801
+ w .Close ()
7802
+ out , err := io .ReadAll (r )
7803
+ require .NoError (t , err )
7804
+ require .NotNil (t , out )
7805
+
7806
+ var js interface {}
7807
+ assert .NoError (t , json .Unmarshal (out , & js ), "JSON validation failed" )
7808
+ })
7691
7809
}
7692
7810
7693
7811
func Test_Sync_SkipConsumersWithConsumerGroups (t * testing.T ) {
0 commit comments