MCPcopy
hub / github.com/nats-io/nats.go / TestNewWithDomain

Function TestNewWithDomain

jetstream/test/jetstream_test.go:139–205  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

137}
138
139func TestNewWithDomain(t *testing.T) {
140 t.Run("jetstream account with domain", func(t *testing.T) {
141 conf := createConfFile(t, []byte(`
142 listen: 127.0.0.1:-1
143 jetstream: { domain: ABC }
144 `))
145 defer os.Remove(conf)
146 srv, _ := RunServerWithConfig(conf)
147 defer shutdownJSServerAndRemoveStorage(t, srv)
148 nc, err := nats.Connect(srv.ClientURL(), nats.UserInfo("main", "foo"))
149 if err != nil {
150 t.Fatalf("Unexpected error: %v", err)
151 }
152 defer nc.Close()
153
154 ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
155 defer cancel()
156 js, err := jetstream.NewWithDomain(nc, "ABC")
157 if err != nil {
158 t.Fatalf("Unexpected error: %v", err)
159 }
160
161 accInfo, err := js.AccountInfo(ctx)
162 if err != nil {
163 t.Fatalf("Unexpected error: %v", err)
164 }
165 if accInfo.Domain != "ABC" {
166 t.Errorf("Invalid domain; want %v, got: %v", "ABC", accInfo.Domain)
167 }
168
169 opts := js.Options()
170 if opts.APIPrefix != "" {
171 t.Fatalf("Invalid API prefix; want: %v, got: %v", "", opts.APIPrefix)
172 }
173 if opts.Domain != "ABC" {
174 t.Fatalf("Invalid domain; want: %v, got: %v", "ABC", opts.Domain)
175 }
176
177 _, err = js.CreateStream(ctx, jetstream.StreamConfig{
178 Name: "TEST",
179 Subjects: []string{"foo"},
180 })
181 if err != nil {
182 t.Fatalf("Unexpected error: %v", err)
183 }
184
185 _, err = js.Publish(ctx, "foo", []byte("msg"))
186 if err != nil {
187 t.Fatalf("Unexpected error: %v", err)
188 }
189 })
190
191 t.Run("empty domain", func(t *testing.T) {
192 srv := RunBasicJetStreamServer()
193 defer shutdownJSServerAndRemoveStorage(t, srv)
194 nc, err := nats.Connect(srv.ClientURL())
195 if err != nil {
196 t.Fatalf("Unexpected error: %v", err)

Callers

nothing calls this directly

Calls 14

NewWithDomainFunction · 0.92
ConnectMethod · 0.80
FatalfMethod · 0.80
ErrorfMethod · 0.80
createConfFileFunction · 0.70
RunServerWithConfigFunction · 0.70
RunBasicJetStreamServerFunction · 0.70
AccountInfoMethod · 0.65
OptionsMethod · 0.65
CreateStreamMethod · 0.65
PublishMethod · 0.65

Tested by

no test coverage detected