func TestReport(t *testing.T) {
	l, err := logger.New(context.Background(), "rtcserve_test")
	if err != nil {
		t.Errorf("Unable to initialize logger. %v", err)
	}
	r := &Reporter{
		sysVars: map[string]string{
			"hostname":  "host1",
			"public_ip": "1.1.1.1",
		},
		cfgs:       []rtcservice.Config{rtcservice.NewStub()},
		reportVars: []string{"public_ip"},
		groups:     []string{"Group 1"},
		l:          l,
	}

	if err := r.report(r.cfgs[0]); err != nil {
		t.Errorf("report(c) = %v, want nil.", err)
	}
	vars, err := r.cfgs[0].List()
	if err != nil {
		t.Fatalf("r.cfgs[0].List() returned error: Error %v", err)
	}
	if len(vars) != 1 {
		t.Fatalf("len(rtc.List()) = %v, want %v.", len(vars), 1)
	}
	v, err := r.cfgs[0].Val(vars[0])
	if err != nil {
		t.Fatalf("r.cfgs[0].Val(vars[0]) returned error: Error %v", err)
	}
	pb := &RtcTargetInfo{}
	if err := proto.Unmarshal(v, pb); err != nil {
		t.Fatalf("Got error unmarshaling protobuf: %v", err)
	}
	if pb.GetInstanceName() != "host1" {
		t.Errorf("pb.GetInstanceName() = %q, want \"host1\".", pb.GetInstanceName())
	}
	if diff := pretty.Compare([]string{"Group 1"}, pb.GetGroups()); diff != "" {
		t.Errorf("pb.GetGroups() got diff:\n%s", diff)
	}
	addrs := pb.GetAddresses()
	if len(addrs) != 1 {
		t.Fatalf("len(addrs) = %v, want 1.", len(addrs))
	}
	if addrs[0].GetTag() != "public_ip" {
		t.Errorf("a.GetTag() = %q, want \"public_ip\".", addrs[0].GetTag())
	}
	if addrs[0].GetAddress() != "1.1.1.1" {
		t.Errorf("a.GetAddress() = %q, want \"1.1.1.1\".", addrs[0].GetAddress())
	}
}
// TestReport only tests that report puts the correct protobuf into the RTC config.
TestReport only tests that report puts the correct protobuf into the RTC config.
// TestReport only tests that report puts the correct protobuf into the RTC config .
func TestReport(t *testing.T) {
	l, err := logger.New(context.Background(), "rtcserve_test")
	if err != nil {
		t.Errorf("Unable to initialize logger. %v", err)
	}
	r := &Reporter{
		sysVars: map[string]string{
			"hostname":  "host1",
			"public_ip": "1.1.1.1",
		},
		cfgs:       []rtcservice.Config{rtcservice.NewStub()},
		reportVars: []string{"public_ip"},
		groups:     []string{"Group 1"},
		l:          l,
	}
	if err := r.report(r.cfgs[0]); err != nil {
		t.Errorf("report(c) = %v, want nil.", err)
	}
	vars, err := r.cfgs[0].List()
	if err != nil {
		t.Fatalf("r.cfgs[0].List() returned error: Error %v", err)
	}
	if len(vars) != 1 {
		t.Fatalf("len(rtc.List()) = %v, want %v.", len(vars), 1)
	}
	v, err := r.cfgs[0].Val(vars[0])
	if err != nil {
		t.Fatalf("r.cfgs[0].Val(vars[0]) returned error: Error %v", err)
	}
	pb := &RtcTargetInfo{}
	if err := proto.Unmarshal(v, pb); err != nil {
		t.Fatalf("Got error unmarshaling protobuf: %v", err)
	}
	if pb.GetInstanceName() != "host1" {
		t.Errorf("pb.GetInstanceName() = %q, want \"host1\".", pb.GetInstanceName())
	}
	if diff := pretty.Compare([]string{"Group 1"}, pb.GetGroups()); diff != "" {
		t.Errorf("pb.GetGroups() got diff:\n%s", diff)
	}
	addrs := pb.GetAddresses()
	if len(addrs) != 1 {
		t.Fatalf("len(addrs) = %v, want 1.", len(addrs))
	}
	if addrs[0].GetTag() != "public_ip" {
		t.Errorf("a.GetTag() = %q, want \"public_ip\".", addrs[0].GetTag())
	}
	if addrs[0].GetAddress() != "1.1.1.1" {
		t.Errorf("a.GetAddress() = %q, want \"1.1.1.1\".", addrs[0].GetAddress())
	}
}
func TestReport ( t * testing . T ) { l , err := logger . New ( context . Background ( ) , " " ) if err != nil { t . Errorf ( " " , err ) } r := & Reporter { sysVars : map [ string ] string { " " : " " , " " : " " , } , cfgs : [ ] rtcservice . Config { rtcservice . NewStub ( ) } , reportVars : [ ] string { " " } , groups : [ ] string { " " } , l : l , } if err := r . report ( r . cfgs [ 0 ] ) ; err != nil { t . Errorf ( " " , err ) } vars , err := r . cfgs [ 0 ] . List ( ) if err != nil { t . Fatalf ( " " , err ) } if len ( vars ) != 1 { t . Fatalf ( " " , len ( vars ) , 1 ) } v , err := r . cfgs [ 0 ] . Val ( vars [ 0 ] ) if err != nil { t . Fatalf ( " " , err ) } pb := & RtcTargetInfo { } if err := proto . Unmarshal ( v , pb ) ; err != nil { t . Fatalf ( " " , err ) } if pb . GetInstanceName ( ) != " " { t . Errorf ( " \" \" " , pb . GetInstanceName ( ) ) } if diff := pretty . Compare ( [ ] string { " " } , pb . GetGroups ( ) ) ; diff != " " { t . Errorf ( " \n " , diff ) } addrs := pb . GetAddresses ( ) if len ( addrs ) != 1 { t . Fatalf ( " " , len ( addrs ) ) } if addrs [ 0 ] . GetTag ( ) != " " { t . Errorf ( " \" \" " , addrs [ 0 ] . GetTag ( ) ) } if addrs [ 0 ] . GetAddress ( ) != " " { t . Errorf ( " \" \" " , addrs [ 0 ] . GetAddress ( ) ) } }
TestReport only tests that report puts the correct protobuf into the RTC config.
TestReport only tests that report puts the correct protobuf into the RTC config .