I have a compiled proto from another repo that I would like to have registered for an integration test.
I'm basically doing this:
payload := map[string]interface{}{
"schemaType": "PROTOBUF",
"schema": "",
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return -1, err
}
subjectWithValue := fmt.Sprintf("%s-value", subject)
resp, err := http.Post(fmt.Sprintf("%s/subjects/%s/versions", s.Cfg.RegistryAddress, subjectWithValue), "application/vnd.schemaregistry.v1+json", bytes.NewReader(payloadBytes))
if err != nil {
return -1, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return -1, errors.Errorf("Failed to register schema, status: %d, response: %s\n", resp.StatusCode, string(body))
}
var response map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
return -1, err
}
schemaID := int(response["id"].(float64))
s.Logger.Info("Registered schema with ID", zap.Int("schema_id", schemaID))
return schemaID, nil
but I don't know how to get the schema on line 3.
I've tried importing and deriving like so:
protoItem := &myPackage.MyProtoCompiledInGo{}
schema := string(protoItem.ProtoReflect().Descriptor())
I have integration tests where I produce and consume records using this proto. However, It seems to be failing, presumably because the schema isn't registered?