How to use Update method of config Package

Best Gauge code snippet using config.Update

systemchannel_test.go

Source:systemchannel_test.go Github

copy

Full Screen

...26 NewChannelConfigErr error27}28func newMockConfigTXValidator(err error) *mocks.ConfigTXValidator {29 mockValidator := &mocks.ConfigTXValidator{}30 mockValidator.ProposeConfigUpdateReturns(&cb.ConfigEnvelope{}, err)31 return mockValidator32}33func (mscs *mockSystemChannelSupport) NewChannelConfig(env *cb.Envelope) (channelconfig.Resources, error) {34 mockResources := &mocks.Resources{}35 mockResources.ConfigtxValidatorReturns(mscs.NewChannelConfigVal)36 return mockResources, mscs.NewChannelConfigErr37}38func TestProcessSystemChannelNormalMsg(t *testing.T) {39 t.Run("Missing header", func(t *testing.T) {40 mscs := &mockSystemChannelSupport{}41 ms := &mockSystemChannelFilterSupport{42 OrdererConfigVal: &mocks.OrdererConfig{},43 }44 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())45 require.NoError(t, err)46 _, err = NewSystemChannel(ms, mscs, nil, cryptoProvider).ProcessNormalMsg(&cb.Envelope{})47 require.NotNil(t, err)48 require.Regexp(t, "header not set", err.Error())49 })50 t.Run("Mismatched channel ID", func(t *testing.T) {51 mscs := &mockSystemChannelSupport{}52 ms := &mockSystemChannelFilterSupport{53 OrdererConfigVal: &mocks.OrdererConfig{},54 }55 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())56 require.NoError(t, err)57 _, err = NewSystemChannel(ms, mscs, nil, cryptoProvider).ProcessNormalMsg(&cb.Envelope{58 Payload: protoutil.MarshalOrPanic(&cb.Payload{59 Header: &cb.Header{60 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{61 ChannelId: testChannelID + ".different",62 }),63 },64 }),65 })66 require.Equal(t, ErrChannelDoesNotExist, err)67 })68 t.Run("Good", func(t *testing.T) {69 mscs := &mockSystemChannelSupport{}70 ms := &mockSystemChannelFilterSupport{71 SequenceVal: 7,72 OrdererConfigVal: newMockOrdererConfig(true, orderer.ConsensusType_STATE_NORMAL),73 }74 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())75 require.NoError(t, err)76 cs, err := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessNormalMsg(&cb.Envelope{77 Payload: protoutil.MarshalOrPanic(&cb.Payload{78 Header: &cb.Header{79 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{80 ChannelId: testChannelID,81 }),82 },83 }),84 })85 require.Nil(t, err)86 require.Equal(t, ms.SequenceVal, cs)87 })88}89func TestSystemChannelConfigUpdateMsg(t *testing.T) {90 t.Run("Missing header", func(t *testing.T) {91 mscs := &mockSystemChannelSupport{}92 ms := &mockSystemChannelFilterSupport{93 OrdererConfigVal: &mocks.OrdererConfig{},94 }95 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())96 require.NoError(t, err)97 _, _, err = NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigUpdateMsg(&cb.Envelope{})98 require.NotNil(t, err)99 require.Regexp(t, "header not set", err.Error())100 })101 t.Run("NormalUpdate", func(t *testing.T) {102 mscs := &mockSystemChannelSupport{}103 ms := &mockSystemChannelFilterSupport{104 SequenceVal: 7,105 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},106 OrdererConfigVal: newMockOrdererConfig(true, orderer.ConsensusType_STATE_NORMAL),107 }108 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())109 require.NoError(t, err)110 sysChan := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider)111 sysChan.maintenanceFilter = AcceptRule112 config, cs, err := sysChan.ProcessConfigUpdateMsg(&cb.Envelope{113 Payload: protoutil.MarshalOrPanic(&cb.Payload{114 Header: &cb.Header{115 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{116 ChannelId: testChannelID,117 }),118 },119 }),120 })121 require.NotNil(t, config)122 require.Equal(t, cs, ms.SequenceVal)123 require.Nil(t, err)124 })125 t.Run("BadNewChannelConfig", func(t *testing.T) {126 mscs := &mockSystemChannelSupport{127 NewChannelConfigErr: fmt.Errorf("An error"),128 }129 ms := &mockSystemChannelFilterSupport{130 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},131 OrdererConfigVal: &mocks.OrdererConfig{},132 }133 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())134 require.NoError(t, err)135 _, _, err = NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigUpdateMsg(&cb.Envelope{136 Payload: protoutil.MarshalOrPanic(&cb.Payload{137 Header: &cb.Header{138 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{139 ChannelId: testChannelID + "different",140 }),141 },142 }),143 })144 require.Equal(t, mscs.NewChannelConfigErr, err)145 })146 t.Run("BadProposedUpdate", func(t *testing.T) {147 mscs := &mockSystemChannelSupport{148 NewChannelConfigVal: newMockConfigTXValidator(fmt.Errorf("An error")),149 }150 ms := &mockSystemChannelFilterSupport{151 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},152 OrdererConfigVal: &mocks.OrdererConfig{},153 }154 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())155 require.NoError(t, err)156 _, _, err = NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigUpdateMsg(&cb.Envelope{157 Payload: protoutil.MarshalOrPanic(&cb.Payload{158 Header: &cb.Header{159 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{160 ChannelId: testChannelID + "different",161 }),162 },163 }),164 })165 require.EqualError(t, err, "error validating channel creation transaction for new channel 'foodifferent', could not successfully apply update to template configuration: An error")166 })167 t.Run("BadSignEnvelope", func(t *testing.T) {168 mscs := &mockSystemChannelSupport{169 NewChannelConfigVal: &mocks.ConfigTXValidator{},170 }171 ms := &mockSystemChannelFilterSupport{172 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},173 OrdererConfigVal: &mocks.OrdererConfig{},174 }175 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())176 require.NoError(t, err)177 _, _, err = NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigUpdateMsg(&cb.Envelope{178 Payload: protoutil.MarshalOrPanic(&cb.Payload{179 Header: &cb.Header{180 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{181 ChannelId: testChannelID + "different",182 }),183 },184 }),185 })186 require.Regexp(t, "Marshal called with nil", err)187 })188 t.Run("BadByFilter", func(t *testing.T) {189 mscs := &mockSystemChannelSupport{190 NewChannelConfigVal: newMockConfigTXValidator(nil),191 }192 ms := &mockSystemChannelFilterSupport{193 SequenceVal: 7,194 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},195 OrdererConfigVal: &mocks.OrdererConfig{},196 }197 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())198 require.NoError(t, err)199 _, _, err = NewSystemChannel(ms, mscs, NewRuleSet([]Rule{RejectRule}), cryptoProvider).ProcessConfigUpdateMsg(&cb.Envelope{200 Payload: protoutil.MarshalOrPanic(&cb.Payload{201 Header: &cb.Header{202 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{203 ChannelId: testChannelID + "different",204 }),205 },206 }),207 })208 require.Equal(t, RejectRule.Apply(nil), err)209 })210 t.Run("RejectByMaintenance", func(t *testing.T) {211 mscs := &mockSystemChannelSupport{212 NewChannelConfigVal: newMockConfigTXValidator(nil),213 }214 ms := &mockSystemChannelFilterSupport{215 SequenceVal: 7,216 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},217 OrdererConfigVal: &mocks.OrdererConfig{},218 }219 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())220 require.NoError(t, err)221 sysChan := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider)222 sysChan.maintenanceFilter = RejectRule223 _, _, err = sysChan.ProcessConfigUpdateMsg(&cb.Envelope{224 Payload: protoutil.MarshalOrPanic(&cb.Payload{225 Header: &cb.Header{226 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{227 ChannelId: testChannelID,228 }),229 },230 }),231 })232 require.Equal(t, RejectRule.Apply(nil), errors.Cause(err))233 })234 t.Run("Good", func(t *testing.T) {235 mscs := &mockSystemChannelSupport{236 NewChannelConfigVal: newMockConfigTXValidator(nil),237 }238 ms := &mockSystemChannelFilterSupport{239 SequenceVal: 7,240 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},241 OrdererConfigVal: &mocks.OrdererConfig{},242 }243 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())244 require.NoError(t, err)245 config, cs, err := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigUpdateMsg(&cb.Envelope{246 Payload: protoutil.MarshalOrPanic(&cb.Payload{247 Header: &cb.Header{248 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{249 ChannelId: testChannelID + "different",250 }),251 },252 }),253 })254 require.Equal(t, cs, ms.SequenceVal)255 require.NotNil(t, config)256 require.Nil(t, err)257 })258}259func TestSystemChannelConfigMsg(t *testing.T) {260 t.Run("ConfigMsg", func(t *testing.T) {261 t.Run("BadPayloadData", func(t *testing.T) {262 mscs := &mockSystemChannelSupport{263 NewChannelConfigVal: newMockConfigTXValidator(nil),264 }265 ms := &mockSystemChannelFilterSupport{266 SequenceVal: 7,267 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},268 OrdererConfigVal: &mocks.OrdererConfig{},269 }270 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())271 require.NoError(t, err)272 _, _, err = NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigMsg(&cb.Envelope{273 Payload: protoutil.MarshalOrPanic(&cb.Payload{274 Header: &cb.Header{275 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{276 ChannelId: testChannelID,277 Type: int32(cb.HeaderType_CONFIG),278 }),279 },280 Data: []byte("hello"),281 }),282 })283 require.Error(t, err)284 })285 t.Run("Good", func(t *testing.T) {286 mscs := &mockSystemChannelSupport{287 NewChannelConfigVal: newMockConfigTXValidator(nil),288 }289 ms := &mockSystemChannelFilterSupport{290 SequenceVal: 7,291 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},292 OrdererConfigVal: newMockOrdererConfig(false, orderer.ConsensusType_STATE_NORMAL),293 }294 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())295 require.NoError(t, err)296 sysChan := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider)297 sysChan.maintenanceFilter = AcceptRule298 config, seq, err := sysChan.ProcessConfigMsg(&cb.Envelope{299 Payload: protoutil.MarshalOrPanic(&cb.Payload{300 Header: &cb.Header{301 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{302 ChannelId: testChannelID,303 Type: int32(cb.HeaderType_CONFIG),304 }),305 },306 }),307 })308 require.Equal(t, seq, ms.SequenceVal)309 require.NotNil(t, config)310 require.Nil(t, err)311 hdr, err := protoutil.ChannelHeader(config)312 require.NoError(t, err)313 require.Equal(314 t,315 int32(cb.HeaderType_CONFIG),316 hdr.Type,317 "Expect type of returned envelope to be %d, but got %d", cb.HeaderType_CONFIG, hdr.Type)318 })319 })320 t.Run("OrdererTxMsg", func(t *testing.T) {321 t.Run("BadPayloadData", func(t *testing.T) {322 mscs := &mockSystemChannelSupport{323 NewChannelConfigVal: newMockConfigTXValidator(nil),324 }325 ms := &mockSystemChannelFilterSupport{326 SequenceVal: 7,327 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},328 OrdererConfigVal: &mocks.OrdererConfig{},329 }330 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())331 require.NoError(t, err)332 _, _, err = NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigMsg(&cb.Envelope{333 Payload: protoutil.MarshalOrPanic(&cb.Payload{334 Header: &cb.Header{335 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{336 ChannelId: testChannelID,337 Type: int32(cb.HeaderType_ORDERER_TRANSACTION),338 }),339 },340 Data: []byte("hello"),341 }),342 })343 require.Error(t, err)344 })345 t.Run("WrongEnvelopeType", func(t *testing.T) {346 mscs := &mockSystemChannelSupport{347 NewChannelConfigVal: newMockConfigTXValidator(nil),348 }349 ms := &mockSystemChannelFilterSupport{350 SequenceVal: 7,351 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},352 OrdererConfigVal: &mocks.OrdererConfig{},353 }354 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())355 require.NoError(t, err)356 _, _, err = NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigMsg(&cb.Envelope{357 Payload: protoutil.MarshalOrPanic(&cb.Payload{358 Header: &cb.Header{359 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{360 ChannelId: testChannelID,361 Type: int32(cb.HeaderType_ORDERER_TRANSACTION),362 }),363 },364 Data: protoutil.MarshalOrPanic(&cb.Envelope{365 Payload: protoutil.MarshalOrPanic(&cb.Payload{366 Header: &cb.Header{367 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{368 ChannelId: testChannelID,369 Type: int32(cb.HeaderType_MESSAGE),370 }),371 },372 }),373 }),374 }),375 })376 require.Error(t, err)377 })378 t.Run("GoodConfigMsg", func(t *testing.T) {379 mscs := &mockSystemChannelSupport{380 NewChannelConfigVal: newMockConfigTXValidator(nil),381 }382 ms := &mockSystemChannelFilterSupport{383 SequenceVal: 7,384 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},385 OrdererConfigVal: &mocks.OrdererConfig{},386 }387 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())388 require.NoError(t, err)389 config, seq, err := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigMsg(&cb.Envelope{390 Payload: protoutil.MarshalOrPanic(&cb.Payload{391 Header: &cb.Header{392 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{393 ChannelId: testChannelID,394 Type: int32(cb.HeaderType_ORDERER_TRANSACTION),395 }),396 },397 Data: protoutil.MarshalOrPanic(&cb.Envelope{398 Payload: protoutil.MarshalOrPanic(&cb.Payload{399 Header: &cb.Header{400 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{401 ChannelId: testChannelID,402 Type: int32(cb.HeaderType_CONFIG),403 }),404 },405 Data: protoutil.MarshalOrPanic(&cb.ConfigEnvelope{406 LastUpdate: &cb.Envelope{407 Payload: protoutil.MarshalOrPanic(&cb.Payload{408 Header: &cb.Header{409 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{410 ChannelId: testChannelID + "different",411 Type: int32(cb.HeaderType_CONFIG_UPDATE),412 }),413 },414 }),415 },416 }),417 }),418 }),419 }),420 })421 require.Equal(t, seq, ms.SequenceVal)422 require.NotNil(t, config)423 require.Nil(t, err)424 hdr, err := protoutil.ChannelHeader(config)425 require.NoError(t, err)426 require.Equal(427 t,428 int32(cb.HeaderType_ORDERER_TRANSACTION),429 hdr.Type,430 "Expect type of returned envelope to be %d, but got %d", cb.HeaderType_ORDERER_TRANSACTION, hdr.Type)431 })432 })433 t.Run("OtherMsgType", func(t *testing.T) {434 mscs := &mockSystemChannelSupport{435 NewChannelConfigVal: newMockConfigTXValidator(nil),436 }437 ms := &mockSystemChannelFilterSupport{438 SequenceVal: 7,439 ProposeConfigUpdateVal: &cb.ConfigEnvelope{},440 OrdererConfigVal: &mocks.OrdererConfig{},441 }442 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())443 require.NoError(t, err)444 _, _, err = NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule}), cryptoProvider).ProcessConfigMsg(&cb.Envelope{445 Payload: protoutil.MarshalOrPanic(&cb.Payload{446 Header: &cb.Header{447 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{448 ChannelId: testChannelID,449 Type: int32(cb.HeaderType_MESSAGE),450 }),451 },452 }),453 })454 require.Error(t, err)455 })456}457type mockDefaultTemplatorSupport struct {458 channelconfig.Resources459}460func (mdts *mockDefaultTemplatorSupport) Signer() identity.SignerSerializer {461 return nil462}463func TestNewChannelConfig(t *testing.T) {464 channelID := "foo"465 gConf := genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile, configtest.GetDevConfigDir())466 gConf.Orderer.Capabilities = map[string]bool{467 capabilities.OrdererV2_0: true,468 }469 channelGroup, err := encoder.NewChannelGroup(gConf)470 require.NoError(t, err)471 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())472 require.NoError(t, err)473 ctxm, err := channelconfig.NewBundle(channelID, &cb.Config{ChannelGroup: channelGroup}, cryptoProvider)474 require.NoError(t, err)475 originalCG := proto.Clone(ctxm.ConfigtxValidator().ConfigProto().ChannelGroup).(*cb.ConfigGroup)476 templator := NewDefaultTemplator(&mockDefaultTemplatorSupport{477 Resources: ctxm,478 }, cryptoProvider)479 t.Run("BadPayload", func(t *testing.T) {480 _, err := templator.NewChannelConfig(&cb.Envelope{Payload: []byte("bad payload")})481 require.Error(t, err, "Should not be able to create new channel config from bad payload.")482 })483 for _, tc := range []struct {484 name string485 payload *cb.Payload486 regex string487 }{488 {489 "BadPayloadData",490 &cb.Payload{491 Data: []byte("bad payload data"),492 },493 "^Failing initial channel config creation because of config update envelope unmarshaling error:",494 },495 {496 "BadConfigUpdate",497 &cb.Payload{498 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},499 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{500 ConfigUpdate: []byte("bad config update envelope data"),501 }),502 },503 "^Failing initial channel config creation because of config update unmarshaling error:",504 },505 {506 "MismatchedChannelID",507 &cb.Payload{508 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},509 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{510 ConfigUpdate: protoutil.MarshalOrPanic(511 &cb.ConfigUpdate{512 ChannelId: "foo",513 },514 ),515 }),516 },517 "mismatched channel IDs",518 },519 {520 "EmptyConfigUpdateWriteSet",521 &cb.Payload{522 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},523 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{524 ConfigUpdate: protoutil.MarshalOrPanic(525 &cb.ConfigUpdate{},526 ),527 }),528 },529 "^Config update has an empty writeset$",530 },531 {532 "WriteSetNoGroups",533 &cb.Payload{534 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},535 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{536 ConfigUpdate: protoutil.MarshalOrPanic(537 &cb.ConfigUpdate{538 WriteSet: &cb.ConfigGroup{},539 },540 ),541 }),542 },543 "^Config update has missing application group$",544 },545 {546 "WriteSetNoApplicationGroup",547 &cb.Payload{548 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},549 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{550 ConfigUpdate: protoutil.MarshalOrPanic(551 &cb.ConfigUpdate{552 WriteSet: &cb.ConfigGroup{553 Groups: map[string]*cb.ConfigGroup{},554 },555 },556 ),557 }),558 },559 "^Config update has missing application group$",560 },561 {562 "BadWriteSetApplicationGroupVersion",563 &cb.Payload{564 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},565 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{566 ConfigUpdate: protoutil.MarshalOrPanic(567 &cb.ConfigUpdate{568 WriteSet: &cb.ConfigGroup{569 Groups: map[string]*cb.ConfigGroup{570 channelconfig.ApplicationGroupKey: {571 Version: 100,572 },573 },574 },575 },576 ),577 }),578 },579 "^Config update for channel creation does not set application group version to 1,",580 },581 {582 "MissingWriteSetConsortiumValue",583 &cb.Payload{584 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},585 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{586 ConfigUpdate: protoutil.MarshalOrPanic(587 &cb.ConfigUpdate{588 WriteSet: &cb.ConfigGroup{589 Groups: map[string]*cb.ConfigGroup{590 channelconfig.ApplicationGroupKey: {591 Version: 1,592 },593 },594 Values: map[string]*cb.ConfigValue{},595 },596 },597 ),598 }),599 },600 "^Consortium config value missing$",601 },602 {603 "BadWriteSetConsortiumValueValue",604 &cb.Payload{605 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},606 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{607 ConfigUpdate: protoutil.MarshalOrPanic(608 &cb.ConfigUpdate{609 WriteSet: &cb.ConfigGroup{610 Groups: map[string]*cb.ConfigGroup{611 channelconfig.ApplicationGroupKey: {612 Version: 1,613 },614 },615 Values: map[string]*cb.ConfigValue{616 channelconfig.ConsortiumKey: {617 Value: []byte("bad consortium value"),618 },619 },620 },621 },622 ),623 }),624 },625 "^Error reading unmarshaling consortium name:",626 },627 {628 "UnknownConsortiumName",629 &cb.Payload{630 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},631 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{632 ConfigUpdate: protoutil.MarshalOrPanic(633 &cb.ConfigUpdate{634 WriteSet: &cb.ConfigGroup{635 Groups: map[string]*cb.ConfigGroup{636 channelconfig.ApplicationGroupKey: {637 Version: 1,638 },639 },640 Values: map[string]*cb.ConfigValue{641 channelconfig.ConsortiumKey: {642 Value: protoutil.MarshalOrPanic(643 &cb.Consortium{644 Name: "NotTheNameYouAreLookingFor",645 },646 ),647 },648 },649 },650 },651 ),652 }),653 },654 "^Unknown consortium name:",655 },656 {657 "Missing consortium members",658 &cb.Payload{659 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},660 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{661 ConfigUpdate: protoutil.MarshalOrPanic(662 &cb.ConfigUpdate{663 WriteSet: &cb.ConfigGroup{664 Groups: map[string]*cb.ConfigGroup{665 channelconfig.ApplicationGroupKey: {666 Version: 1,667 },668 },669 Values: map[string]*cb.ConfigValue{670 channelconfig.ConsortiumKey: {671 Value: protoutil.MarshalOrPanic(672 &cb.Consortium{673 Name: genesisconfig.SampleConsortiumName,674 },675 ),676 },677 },678 },679 },680 ),681 }),682 },683 "Proposed configuration has no application group members, but consortium contains members",684 },685 {686 "Member not in consortium",687 &cb.Payload{688 Header: &cb.Header{ChannelHeader: protoutil.MarshalOrPanic(protoutil.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, 0, "", epoch))},689 Data: protoutil.MarshalOrPanic(&cb.ConfigUpdateEnvelope{690 ConfigUpdate: protoutil.MarshalOrPanic(691 &cb.ConfigUpdate{692 WriteSet: &cb.ConfigGroup{693 Groups: map[string]*cb.ConfigGroup{694 channelconfig.ApplicationGroupKey: {695 Version: 1,696 Groups: map[string]*cb.ConfigGroup{697 "BadOrgName": {},698 },699 },700 },701 Values: map[string]*cb.ConfigValue{702 channelconfig.ConsortiumKey: {703 Value: protoutil.MarshalOrPanic(704 &cb.Consortium{705 Name: genesisconfig.SampleConsortiumName,...

Full Screen

Full Screen

configblock.go

Source:configblock.go Github

copy

Full Screen

...65 Expect(err).NotTo(HaveOccurred())66 // clone the config67 return configEnv.Config68}69// UpdateConfig computes, signs, and submits a configuration update and waits70// for the update to complete.71func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated *common.Config, getConfigBlockFromOrderer bool, submitter *Peer, additionalSigners ...*Peer) {72 tempDir, err := ioutil.TempDir("", "updateConfig")73 Expect(err).NotTo(HaveOccurred())74 defer os.RemoveAll(tempDir)75 // compute update76 configUpdate, err := update.Compute(current, updated)77 Expect(err).NotTo(HaveOccurred())78 configUpdate.ChannelId = channel79 signedEnvelope, err := protoutil.CreateSignedEnvelope(80 common.HeaderType_CONFIG_UPDATE,81 channel,82 nil, // local signer83 &common.ConfigUpdateEnvelope{ConfigUpdate: protoutil.MarshalOrPanic(configUpdate)},84 0, // message version85 0, // epoch86 )87 Expect(err).NotTo(HaveOccurred())88 Expect(signedEnvelope).NotTo(BeNil())89 updateFile := filepath.Join(tempDir, "update.pb")90 err = ioutil.WriteFile(updateFile, protoutil.MarshalOrPanic(signedEnvelope), 0600)91 Expect(err).NotTo(HaveOccurred())92 for _, signer := range additionalSigners {93 sess, err := n.PeerAdminSession(signer, commands.SignConfigTx{94 File: updateFile,95 ClientAuth: n.ClientAuthRequired,96 })97 Expect(err).NotTo(HaveOccurred())98 Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))99 }100 var currentBlockNumber uint64101 // get current configuration block number102 if getConfigBlockFromOrderer {103 currentBlockNumber = CurrentConfigBlockNumber(n, submitter, orderer, channel)104 } else {105 currentBlockNumber = CurrentConfigBlockNumber(n, submitter, nil, channel)106 }107 sess, err := n.PeerAdminSession(submitter, commands.ChannelUpdate{108 ChannelID: channel,109 Orderer: n.OrdererAddress(orderer, ListenPort),110 File: updateFile,111 ClientAuth: n.ClientAuthRequired,112 })113 Expect(err).NotTo(HaveOccurred())114 Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))115 Expect(sess.Err).To(gbytes.Say("Successfully submitted channel update"))116 if getConfigBlockFromOrderer {117 ccb := func() uint64 { return CurrentConfigBlockNumber(n, submitter, orderer, channel) }118 Eventually(ccb, n.EventuallyTimeout).Should(BeNumerically(">", currentBlockNumber))119 return120 }121 // wait for the block to be committed to all peers that122 // have joined the channel123 for _, peer := range n.PeersWithChannel(channel) {124 ccb := func() uint64 { return CurrentConfigBlockNumber(n, peer, nil, channel) }125 Eventually(ccb, n.EventuallyTimeout).Should(BeNumerically(">", currentBlockNumber))126 }127}128// CurrentConfigBlockNumber retrieves the block number from the header of the129// current config block. This can be used to detect when configuration change130// has completed. If an orderer is not provided, the current config block will131// be fetched from the peer.132func CurrentConfigBlockNumber(n *Network, peer *Peer, orderer *Orderer, channel string) uint64 {133 tempDir, err := ioutil.TempDir(n.RootDir, "currentConfigBlock")134 Expect(err).NotTo(HaveOccurred())135 defer os.RemoveAll(tempDir)136 // fetch the config block137 output := filepath.Join(tempDir, "config_block.pb")138 if orderer == nil {139 return CurrentConfigBlockNumberFromPeer(n, peer, channel, output)140 }141 FetchConfigBlock(n, peer, orderer, channel, output)142 // unmarshal the config block bytes143 configBlock := UnmarshalBlockFromFile(output)144 return configBlock.Header.Number145}146// CurrentConfigBlockNumberFromPeer retrieves the block number from the header147// of the peer's current config block.148func CurrentConfigBlockNumberFromPeer(n *Network, peer *Peer, channel, output string) uint64 {149 sess, err := n.PeerAdminSession(peer, commands.ChannelFetch{150 ChannelID: channel,151 Block: "config",152 OutputFile: output,153 ClientAuth: n.ClientAuthRequired,154 })155 Expect(err).NotTo(HaveOccurred())156 Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))157 Expect(sess.Err).To(gbytes.Say("Received block: "))158 configBlock := UnmarshalBlockFromFile(output)159 return configBlock.Header.Number160}161// UpdateOrdererConfig computes, signs, and submits a configuration update162// which requires orderers signature and waits for the update to complete.163func UpdateOrdererConfig(n *Network, orderer *Orderer, channel string, current, updated *common.Config, submitter *Peer, additionalSigners ...*Orderer) {164 tempDir, err := ioutil.TempDir(n.RootDir, "updateConfig")165 Expect(err).NotTo(HaveOccurred())166 updateFile := filepath.Join(tempDir, "update.pb")167 defer os.RemoveAll(tempDir)168 currentBlockNumber := CurrentConfigBlockNumber(n, submitter, orderer, channel)169 ComputeUpdateOrdererConfig(updateFile, n, channel, current, updated, submitter, additionalSigners...)170 Eventually(func() bool {171 sess, err := n.OrdererAdminSession(orderer, submitter, commands.ChannelUpdate{172 ChannelID: channel,173 Orderer: n.OrdererAddress(orderer, ListenPort),174 File: updateFile,175 ClientAuth: n.ClientAuthRequired,176 })177 Expect(err).NotTo(HaveOccurred())178 sess.Wait(n.EventuallyTimeout)179 if sess.ExitCode() != 0 {180 return false181 }182 return strings.Contains(string(sess.Err.Contents()), "Successfully submitted channel update")183 }, n.EventuallyTimeout).Should(BeTrue())184 // wait for the block to be committed185 ccb := func() uint64 { return CurrentConfigBlockNumber(n, submitter, orderer, channel) }186 Eventually(ccb, n.EventuallyTimeout).Should(BeNumerically(">", currentBlockNumber))187}188// UpdateOrdererConfigSession computes, signs, and submits a configuration189// update which requires orderer signatures. The caller should wait on the190// returned seession retrieve the exit code.191func UpdateOrdererConfigSession(n *Network, orderer *Orderer, channel string, current, updated *common.Config, submitter *Peer, additionalSigners ...*Orderer) *gexec.Session {192 tempDir, err := ioutil.TempDir(n.RootDir, "updateConfig")193 Expect(err).NotTo(HaveOccurred())194 updateFile := filepath.Join(tempDir, "update.pb")195 ComputeUpdateOrdererConfig(updateFile, n, channel, current, updated, submitter, additionalSigners...)196 // session should not return with a zero exit code nor with a success response197 sess, err := n.OrdererAdminSession(orderer, submitter, commands.ChannelUpdate{198 ChannelID: channel,199 Orderer: n.OrdererAddress(orderer, ListenPort),200 File: updateFile,201 ClientAuth: n.ClientAuthRequired,202 })203 Expect(err).NotTo(HaveOccurred())204 return sess205}206func ComputeUpdateOrdererConfig(updateFile string, n *Network, channel string, current, updated *common.Config, submitter *Peer, additionalSigners ...*Orderer) {207 // compute update208 configUpdate, err := update.Compute(current, updated)209 Expect(err).NotTo(HaveOccurred())210 configUpdate.ChannelId = channel211 signedEnvelope, err := protoutil.CreateSignedEnvelope(212 common.HeaderType_CONFIG_UPDATE,213 channel,214 nil, // local signer215 &common.ConfigUpdateEnvelope{ConfigUpdate: protoutil.MarshalOrPanic(configUpdate)},216 0, // message version217 0, // epoch218 )219 Expect(err).NotTo(HaveOccurred())220 Expect(signedEnvelope).NotTo(BeNil())221 err = ioutil.WriteFile(updateFile, protoutil.MarshalOrPanic(signedEnvelope), 0600)222 Expect(err).NotTo(HaveOccurred())223 for _, signer := range additionalSigners {224 sess, err := n.OrdererAdminSession(signer, submitter, commands.SignConfigTx{File: updateFile})225 Expect(err).NotTo(HaveOccurred())226 Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))227 }228}229// UnmarshalBlockFromFile unmarshals a proto encoded block from a file.230func UnmarshalBlockFromFile(blockFile string) *common.Block {231 blockBytes, err := ioutil.ReadFile(blockFile)232 Expect(err).NotTo(HaveOccurred())233 block, err := protoutil.UnmarshalBlock(blockBytes)234 Expect(err).NotTo(HaveOccurred())235 return block236}237// ConsensusMetadataMutator receives ConsensusType.Metadata and mutates it.238type ConsensusMetadataMutator func([]byte) []byte239// MSPMutator receives FabricMSPConfig and mutates it.240type MSPMutator func(config msp.FabricMSPConfig) msp.FabricMSPConfig241// UpdateConsensusMetadata executes a config update that updates the consensus242// metadata according to the given ConsensusMetadataMutator.243func UpdateConsensusMetadata(network *Network, peer *Peer, orderer *Orderer, channel string, mutateMetadata ConsensusMetadataMutator) {244 config := GetConfig(network, peer, orderer, channel)245 updatedConfig := proto.Clone(config).(*common.Config)246 consensusTypeConfigValue := updatedConfig.ChannelGroup.Groups["Orderer"].Values["ConsensusType"]247 consensusTypeValue := &protosorderer.ConsensusType{}248 err := proto.Unmarshal(consensusTypeConfigValue.Value, consensusTypeValue)249 Expect(err).NotTo(HaveOccurred())250 consensusTypeValue.Metadata = mutateMetadata(consensusTypeValue.Metadata)251 updatedConfig.ChannelGroup.Groups["Orderer"].Values["ConsensusType"] = &common.ConfigValue{252 ModPolicy: "Admins",253 Value: protoutil.MarshalOrPanic(consensusTypeValue),254 }255 UpdateOrdererConfig(network, orderer, channel, config, updatedConfig, peer, orderer)256}257func UpdateOrdererMSP(network *Network, peer *Peer, orderer *Orderer, channel, orgID string, mutateMSP MSPMutator) {258 config := GetConfig(network, peer, orderer, channel)259 updatedConfig := proto.Clone(config).(*common.Config)260 // Unpack the MSP config261 rawMSPConfig := updatedConfig.ChannelGroup.Groups["Orderer"].Groups[orgID].Values["MSP"]262 mspConfig := &msp.MSPConfig{}263 err := proto.Unmarshal(rawMSPConfig.Value, mspConfig)264 Expect(err).NotTo(HaveOccurred())265 fabricConfig := &msp.FabricMSPConfig{}266 err = proto.Unmarshal(mspConfig.Config, fabricConfig)267 Expect(err).NotTo(HaveOccurred())268 // Mutate it as we are asked269 *fabricConfig = mutateMSP(*fabricConfig)270 // Wrap it back into the config271 mspConfig.Config = protoutil.MarshalOrPanic(fabricConfig)272 rawMSPConfig.Value = protoutil.MarshalOrPanic(mspConfig)273 UpdateOrdererConfig(network, orderer, channel, config, updatedConfig, peer, orderer)274}...

Full Screen

Full Screen

util.go

Source:util.go Github

copy

Full Screen

...24 panic(err)25 }26 return result27}28// UnmarshalConfigUpdate attempts to unmarshal bytes to a *cb.ConfigUpdate29func UnmarshalConfigUpdate(data []byte) (*cb.ConfigUpdate, error) {30 configUpdate := &cb.ConfigUpdate{}31 err := proto.Unmarshal(data, configUpdate)32 if err != nil {33 return nil, err34 }35 return configUpdate, nil36}37// UnmarshalConfigUpdateOrPanic attempts to unmarshal bytes to a *cb.ConfigUpdate or panics on error38func UnmarshalConfigUpdateOrPanic(data []byte) *cb.ConfigUpdate {39 result, err := UnmarshalConfigUpdate(data)40 if err != nil {41 panic(err)42 }43 return result44}45// UnmarshalConfigUpdateEnvelope attempts to unmarshal bytes to a *cb.ConfigUpdate46func UnmarshalConfigUpdateEnvelope(data []byte) (*cb.ConfigUpdateEnvelope, error) {47 configUpdateEnvelope := &cb.ConfigUpdateEnvelope{}48 err := proto.Unmarshal(data, configUpdateEnvelope)49 if err != nil {50 return nil, err51 }52 return configUpdateEnvelope, nil53}54// UnmarshalConfigUpdateEnvelopeOrPanic attempts to unmarshal bytes to a *cb.ConfigUpdateEnvelope or panics on error55func UnmarshalConfigUpdateEnvelopeOrPanic(data []byte) *cb.ConfigUpdateEnvelope {56 result, err := UnmarshalConfigUpdateEnvelope(data)57 if err != nil {58 panic(err)59 }60 return result61}62// UnmarshalConfigEnvelope attempts to unmarshal bytes to a *cb.ConfigEnvelope63func UnmarshalConfigEnvelope(data []byte) (*cb.ConfigEnvelope, error) {64 configEnv := &cb.ConfigEnvelope{}65 err := proto.Unmarshal(data, configEnv)66 if err != nil {67 return nil, err68 }69 return configEnv, nil70}71// UnmarshalConfigEnvelopeOrPanic attempts to unmarshal bytes to a *cb.ConfigEnvelope or panics on error72func UnmarshalConfigEnvelopeOrPanic(data []byte) *cb.ConfigEnvelope {73 result, err := UnmarshalConfigEnvelope(data)74 if err != nil {75 panic(err)76 }77 return result78}79// UnmarshalConfigUpdateFromPayload unmarshals configuration update from given payload80func UnmarshalConfigUpdateFromPayload(payload *cb.Payload) (*cb.ConfigUpdate, error) {81 configEnv, err := UnmarshalConfigEnvelope(payload.Data)82 if err != nil {83 return nil, err84 }85 configUpdateEnv, err := protoutil.EnvelopeToConfigUpdate(configEnv.LastUpdate)86 if err != nil {87 return nil, err88 }89 return UnmarshalConfigUpdate(configUpdateEnv.ConfigUpdate)90}...

Full Screen

Full Screen

Update

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conf, err := config.NewConfig("ini", "conf/app.conf")4 if err != nil {5 fmt.Println(err)6 }7 conf.Set("appname", "beego")8 conf.Set("httpport", "8080")9 conf.SaveConfigFile("conf/app.conf")10}111.go:18: cannot use conf (type config.Configer) as type "github.com/astaxie/beego/config".Configer in argument to conf.Set:12 config.Configer does not implement "github.com/astaxie/beego/config".Configer (wrong type for Set method)13 have Set(string, string)14 want Set(string, interface {}) error151.go:18: cannot use conf (type config.Configer) as type "github.com/astaxie/beego/config".Configer in argument to conf.Set:16 config.Configer does not implement "github.com/astaxie/beego/config".Configer (wrong type for Set method)17 have Set(string, interface {})18 want Set(string, string) error191.go:18: cannot use conf (type config.Configer) as type "github.com/astaxie/beego/config".Configer in argument to conf.Set:20 config.Configer does not implement "github.com/astaxie/beego/config".Configer (wrong type for Set method)21 have Set(string, string)22 want Set(string, interface {}) error231.go:18: cannot use conf (type config.Configer) as type "github.com/astaxie/beego/config".Configer in argument to conf.Set:24 config.Configer does not implement "github.com/astaxie/beego/config".Configer (wrong type for Set method)25 have Set(string, interface {})26 want Set(string, string) error271.go:18: cannot use conf (

Full Screen

Full Screen

Update

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 viper.SetConfigType("yaml")4 viper.SetConfigName("config")5 viper.AddConfigPath(".")6 viper.AddConfigPath("./config")7 viper.AddConfigPath("../config")8 viper.AddConfigPath("../../config")9 viper.AddConfigPath("../../../config")10 viper.AddConfigPath("../../../../config")11 viper.AddConfigPath("../../../../../config")12 viper.AddConfigPath("../../../../../../config")13 viper.AddConfigPath("../../../../../../../config")14 viper.AddConfigPath("../../../../../../../../config")15 viper.AddConfigPath("../../../../../../../../../config")16 viper.AddConfigPath("../../../../../../../../../../config")17 viper.AddConfigPath("../../../../../../../../../../../config")18 viper.AddConfigPath("../../../../../../../../../../../../config")19 viper.AddConfigPath("../../../../../../../../../../../../../config")20 viper.AddConfigPath("../../../../../../../../../../../../../../config")21 viper.AddConfigPath("../../../../../../../../../../../../../../../config")22 viper.AddConfigPath("../../../../../../../../../../../../../../../../config")23 viper.AddConfigPath("../../../../../../../../../../../../../../../../../config")24 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../config")25 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../config")26 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../config")27 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../config")28 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../config")29 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../config")30 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../config")31 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../config")32 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../config")33 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../../config")34 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../../../config")35 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../../../../config")36 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../config")37 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../config")38 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../config")39 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../config")40 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../config")41 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../config")42 viper.AddConfigPath("../../../../../../../../../../../../../../../../../../../../../../../../../../

Full Screen

Full Screen

Update

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 dir, err := os.Getwd()4 if err != nil {5 log.Fatal(err)6 }7 viper.AddConfigPath(dir)8 viper.SetConfigName("config")9 viper.SetConfigType("yaml")10 err = viper.ReadInConfig()11 if err != nil {12 panic(fmt.Errorf("Fatal error config file: %s \n", err))13 }14 viper.Set("author", "John Doe")15 viper.WriteConfig()16 configFile := viper.ConfigFileUsed()17 fmt.Println("Config file used:", configFile)18 configFileName := filepath.Base(configFile)19 fmt.Println("Config file name:", configFileName)20}

Full Screen

Full Screen

Update

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := config.NewConfig()4 c.Update("foo", "bar")5 fmt.Println(c.Get("foo"))6 c.Delete("foo")7}8import (9func main() {10 c.Update("foo", "bar")11 fmt.Println(c.Get("foo"))12 c.Delete("foo")13}

Full Screen

Full Screen

Update

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "config"3func main() {4 config.Update("value")5}6import "fmt"7import "config"8func main() {9 config.Update("value")10}11import "fmt"12import "config"13func main() {14 config.Update("value")15}16import "fmt"17import "config"18func main() {19 config.Update("value")20}21import "fmt"22import "fmt"23import "fmt"24import "fmt"25import "fmt"26import "fmt"

Full Screen

Full Screen

Update

Using AI Code Generation

copy

Full Screen

1func main() {2 config := config.NewConfig()3 config.Update("config.json", "test", "test")4}5func main() {6 config := config.NewConfig()7 fmt.Println(config.Get("config.json", "test"))8}9func main() {10 config := config.NewConfig()11 fmt.Println(config.Get("config.json", "test"))12}13func main() {14 config := config.NewConfig()15 fmt.Println(config.Get("config.json", "test"))16}17func main() {18 config := config.NewConfig()19 fmt.Println(config.Get("config.json", "test"))20}21func main() {22 config := config.NewConfig()23 fmt.Println(config.Get("config.json", "test"))24}25func main() {26 config := config.NewConfig()27 fmt.Println(config.Get("config.json", "test"))28}29func main() {30 config := config.NewConfig()31 fmt.Println(config.Get("config.json", "test"))32}33func main() {34 config := config.NewConfig()35 fmt.Println(config.Get("config.json", "test"))36}37func main() {38 config := config.NewConfig()39 fmt.Println(config.Get("config.json", "test"))40}41func main() {42 config := config.NewConfig()43 fmt.Println(config.Get("config.json", "test"))

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful