Skip to content

Commit

Permalink
add an example test (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
scorix authored Jul 13, 2023
1 parent f784f6c commit 4b6abb0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions oap_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package oap_test

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -253,3 +254,46 @@ func TestDecode_NestedWithNamespace(t *testing.T) {
err := oap.Decode(&config, client, make(map[string][]agollo.OpOption))
require.NoError(t, err)
}

func ExampleDecode() {
const (
appid = "SampleApp"
addr = "http://81.68.181.139:8080"
// http://81.68.181.139/app/access_key.html?#/appid=SampleApp
secret = ""
)

if secret == "" {
return
}

type FooConfig struct {
Foo string `apollo:"abc"`
}

config := struct {
FooConfig `apollo_namespace:"proper"`
}{}

client := agollo.NewClient(&agollo.Conf{
AppID: appid,
MetaAddr: addr,
AccesskeySecret: secret,
})
if err := client.Start(); err != nil {
panic(err)
}

if err := client.SubscribeToNamespaces("proper"); err != nil {
panic(err)
}

fmt.Println(client.GetAllKeys(agollo.WithNamespace("application")))
fmt.Println(client.GetAllKeys(agollo.WithNamespace("proper")))

if err := oap.Decode(&config, client, make(map[string][]agollo.OpOption)); err != nil {
panic(err)
}

fmt.Println(config.Foo)
}

0 comments on commit 4b6abb0

Please sign in to comment.