package eureka import ( "reflect" "testing" ) func TestParseAPIResponse(t *testing.T) { f := func(data string, resultExpected *applications) { t.Helper() result, err := parseAPIResponse([]byte(data)) if err != nil { t.Fatalf("parseAPIResponse() error: %s", err) } if !reflect.DeepEqual(result, resultExpected) { t.Fatalf("unexpected result\ngot\n%v\nwant\n%v", result, resultExpected) } } // parse ok 1 app with instance data := ` 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 ` resultExpected := &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: "", }, }, }, }, } f(data, resultExpected) }