Adding test case for no exported services scenario

pull/19821/head
Tauhid 12 months ago
parent f6c7fceafa
commit 6d956180fd

@ -6,7 +6,6 @@ package exportedservices
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"strings" "strings"
"testing" "testing"
@ -90,7 +89,7 @@ func TestExportedServicesCommand(t *testing.T) {
require.Contains(t, ui.ErrorWriter.String(), "No peering with name") require.Contains(t, ui.ErrorWriter.String(), "No peering with name")
}) })
t.Run("read with pretty print", func(t *testing.T) { t.Run("peering exist but no exported services", func(t *testing.T) {
// Generate token // Generate token
generateReq := api.PeeringGenerateTokenRequest{ generateReq := api.PeeringGenerateTokenRequest{
PeerName: "foo", PeerName: "foo",
@ -114,9 +113,42 @@ func TestExportedServicesCommand(t *testing.T) {
_, _, err = dialingClient.Peerings().Establish(context.Background(), establishReq, &api.WriteOptions{}) _, _, err = dialingClient.Peerings().Establish(context.Background(), establishReq, &api.WriteOptions{})
require.NoError(t, err, "Could not establish peering for \"bar\"") require.NoError(t, err, "Could not establish peering for \"bar\"")
resp, _, err := dialingClient.Peerings().Read(context.Background(), "bar", &api.QueryOptions{}) ui := cli.NewMockUi()
require.NoError(t, err) cmd := New(ui)
fmt.Println(resp)
args := []string{
"-http-addr=" + acceptor.HTTPAddr(),
"-name=foo",
}
code := cmd.Run(args)
require.Equal(t, 0, code)
require.Equal(t, ui.ErrorWriter.String(), "")
})
t.Run("exported-services with pretty print", func(t *testing.T) {
// Generate token
generateReq := api.PeeringGenerateTokenRequest{
PeerName: "foo",
Meta: map[string]string{
"env": "production",
},
}
res, _, err := acceptingClient.Peerings().GenerateToken(context.Background(), generateReq, &api.WriteOptions{})
require.NoError(t, err, "Could not generate peering token at acceptor for \"foo\"")
// Establish peering
establishReq := api.PeeringEstablishRequest{
PeerName: "bar",
PeeringToken: res.PeeringToken,
Meta: map[string]string{
"env": "production",
},
}
_, _, err = dialingClient.Peerings().Establish(context.Background(), establishReq, &api.WriteOptions{})
require.NoError(t, err, "Could not establish peering for \"bar\"")
_, _, err = acceptingClient.ConfigEntries().Set(&api.ExportedServicesConfigEntry{ _, _, err = acceptingClient.ConfigEntries().Set(&api.ExportedServicesConfigEntry{
Name: "default", Name: "default",
@ -153,7 +185,6 @@ func TestExportedServicesCommand(t *testing.T) {
code := cmd.Run(args) code := cmd.Run(args)
require.Equal(r, 0, code) require.Equal(r, 0, code)
output := ui.OutputWriter.String() output := ui.OutputWriter.String()
fmt.Println(output)
// Spot check some fields and values // Spot check some fields and values
require.Contains(r, output, "web") require.Contains(r, output, "web")
@ -161,7 +192,7 @@ func TestExportedServicesCommand(t *testing.T) {
}) })
}) })
t.Run("read with json", func(t *testing.T) { t.Run("exported-services with json", func(t *testing.T) {
ui := cli.NewMockUi() ui := cli.NewMockUi()
cmd := New(ui) cmd := New(ui)

Loading…
Cancel
Save