@@ -4,12 +4,13 @@ import (
44 "context"
55 "encoding/base64"
66 "errors"
7- "github.com/temporalio/tcld/protogen/api/auth/v1"
8- "github.com/temporalio/tcld/protogen/api/authservice/v1"
97 "os"
108 "strings"
119 "testing"
1210
11+ "github.com/temporalio/tcld/protogen/api/auth/v1"
12+ "github.com/temporalio/tcld/protogen/api/authservice/v1"
13+
1314 "github.com/golang/mock/gomock"
1415 "github.com/stretchr/testify/suite"
1516 "github.com/temporalio/tcld/protogen/api/namespace/v1"
@@ -1063,6 +1064,108 @@ func (s *NamespaceTestSuite) TestClearCertificateFilters() {
10631064 }
10641065}
10651066
1067+ func (s * NamespaceTestSuite ) TestUpdateCodecServer () {
1068+ ns := "ns1"
1069+ type morphGetResp func (* namespaceservice.GetNamespaceResponse )
1070+ type morphUpdateReq func (* namespaceservice.UpdateNamespaceRequest )
1071+
1072+ tests := []struct {
1073+ args []string
1074+ expectGet morphGetResp
1075+ expectErr bool
1076+ expectUpdate morphUpdateReq
1077+ }{
1078+ {
1079+
1080+ args : []string {"namespace" , "update-codec-server" },
1081+ expectErr : true ,
1082+ },
1083+ {
1084+ args : []string {"namespace" , "update-codec-server" , "--namespace" , ns },
1085+ expectErr : true ,
1086+ },
1087+ {
1088+ args : []string {"n" , "ucs" , "-n" , ns , "-endpoint" , "fakehost:9999" },
1089+ expectGet : func (g * namespaceservice.GetNamespaceResponse ) {},
1090+ expectUpdate : func (r * namespaceservice.UpdateNamespaceRequest ) {
1091+ r .Spec .CodecSpec = & namespace.CodecServerPropertySpec {Endpoint : "fakehost:9999" }
1092+ },
1093+ },
1094+ {
1095+ args : []string {"n" , "ucs" , "-n" , ns , "-e" , "fakehost:9999" , "--pass-access-token" },
1096+ expectGet : func (g * namespaceservice.GetNamespaceResponse ) {},
1097+ expectUpdate : func (r * namespaceservice.UpdateNamespaceRequest ) {
1098+ r .Spec .CodecSpec = & namespace.CodecServerPropertySpec {
1099+ Endpoint : "fakehost:9999" ,
1100+ PassAccessToken : true ,
1101+ }
1102+ },
1103+ },
1104+ {
1105+ args : []string {"n" , "ucs" , "-n" , ns , "-e" , "fakehost:9999" , "--pat" , "--include-credentials" },
1106+ expectGet : func (g * namespaceservice.GetNamespaceResponse ) {},
1107+ expectUpdate : func (r * namespaceservice.UpdateNamespaceRequest ) {
1108+ r .Spec .CodecSpec = & namespace.CodecServerPropertySpec {
1109+ Endpoint : "fakehost:9999" ,
1110+ PassAccessToken : true ,
1111+ IncludeCredentials : true ,
1112+ }
1113+ },
1114+ },
1115+ }
1116+
1117+ for _ , tc := range tests {
1118+ s .Run (strings .Join (tc .args , " " ), func () {
1119+ getResp := namespaceservice.GetNamespaceResponse {
1120+ Namespace : & namespace.Namespace {
1121+ Namespace : ns ,
1122+ Spec : & namespace.NamespaceSpec {
1123+ AcceptedClientCa : "cert1" ,
1124+ SearchAttributes : map [string ]namespace.SearchAttributeType {
1125+ "attr1" : namespace .SEARCH_ATTRIBUTE_TYPE_BOOL ,
1126+ },
1127+ RetentionDays : 7 ,
1128+ CertificateFilters : []* namespace.CertificateFilterSpec {
1129+ {
1130+ CommonName : "test0" ,
1131+ },
1132+ },
1133+ },
1134+ State : namespace .STATE_ACTIVE ,
1135+ ResourceVersion : "ver1" ,
1136+ },
1137+ }
1138+ if tc .expectGet != nil {
1139+ tc .expectGet (& getResp )
1140+ s .mockService .EXPECT ().GetNamespace (gomock .Any (), & namespaceservice.GetNamespaceRequest {
1141+ Namespace : ns ,
1142+ }).Return (& getResp , nil ).Times (1 )
1143+ }
1144+
1145+ if tc .expectUpdate != nil {
1146+ spec := * (getResp .Namespace .Spec )
1147+ req := namespaceservice.UpdateNamespaceRequest {
1148+ Namespace : ns ,
1149+ Spec : & spec ,
1150+ ResourceVersion : getResp .Namespace .ResourceVersion ,
1151+ }
1152+ tc .expectUpdate (& req )
1153+ s .mockService .EXPECT ().UpdateNamespace (gomock .Any (), & req ).
1154+ Return (& namespaceservice.UpdateNamespaceResponse {
1155+ RequestStatus : & request.RequestStatus {},
1156+ }, nil ).Times (1 )
1157+ }
1158+
1159+ err := s .RunCmd (tc .args ... )
1160+ if tc .expectErr {
1161+ s .Error (err )
1162+ } else {
1163+ s .NoError (err )
1164+ }
1165+ })
1166+ }
1167+ }
1168+
10661169func (s * NamespaceTestSuite ) TestUpdateNamespaceRetention () {
10671170
10681171 ns := "ns1"
0 commit comments