package eureka import ( "reflect" "testing" ) func Test_parseAPIResponse(t *testing.T) { type args struct { data []byte } tests := []struct { name string args args want *applications wantErr bool }{ { name: "parse ok 1 app with instance", args: args{ data: []byte(` 1 UP_1_ HELLO-NETFLIX-OSS 98de25ebef42 HELLO-NETFLIX-OSS 10.10.0.3 UP UNKNOWN 8080 443 1 MyOwn 30 90 1605757726477 1605759135484 0 1605757725913 UNKNOWN http://98de25ebef42:8080/ http://98de25ebef42:8080/Status http://98de25ebef42:8080/healthcheck HELLO-NETFLIX-OSS false 1605757726478 1605757725753 ADDED `), }, want: &applications{ Applications: []Application{ { Name: "HELLO-NETFLIX-OSS", Instances: []Instance{ { HostName: "98de25ebef42", HomePageURL: "http://98de25ebef42:8080/", StatusPageURL: "http://98de25ebef42:8080/Status", HealthCheckURL: "http://98de25ebef42:8080/healthcheck", App: "HELLO-NETFLIX-OSS", IPAddr: "10.10.0.3", VipAddress: "HELLO-NETFLIX-OSS", SecureVipAddress: "", Status: "UP", Port: Port{ Enabled: true, Port: 8080, }, SecurePort: Port{ Port: 443, }, DataCenterInfo: DataCenterInfo{ Name: "MyOwn", }, Metadata: MetaData{}, CountryID: 1, InstanceID: "", }, }, }, }, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := parseAPIResponse(tt.args.data) if (err != nil) != tt.wantErr { t.Errorf("parseAPIResponse() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { t.Errorf("unxpected response for parseAPIResponse() \ngot = %v, \nwant %v", got, tt.want) } }) } }