generated_resource_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Code generated by mdatagen. DO NOT EDIT.
  2. package metadata
  3. import (
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestResourceBuilder(t *testing.T) {
  8. for _, test := range []string{"default", "all_set", "none_set"} {
  9. t.Run(test, func(t *testing.T) {
  10. cfg := loadResourceAttributesConfig(t, test)
  11. rb := NewResourceBuilder(cfg)
  12. rb.SetRabbitmqNodeName("rabbitmq.node.name-val")
  13. rb.SetRabbitmqQueueName("rabbitmq.queue.name-val")
  14. rb.SetRabbitmqVhostName("rabbitmq.vhost.name-val")
  15. res := rb.Emit()
  16. assert.Equal(t, 0, rb.Emit().Attributes().Len()) // Second call should return empty Resource
  17. switch test {
  18. case "default":
  19. assert.Equal(t, 3, res.Attributes().Len())
  20. case "all_set":
  21. assert.Equal(t, 3, res.Attributes().Len())
  22. case "none_set":
  23. assert.Equal(t, 0, res.Attributes().Len())
  24. return
  25. default:
  26. assert.Failf(t, "unexpected test case: %s", test)
  27. }
  28. val, ok := res.Attributes().Get("rabbitmq.node.name")
  29. assert.True(t, ok)
  30. if ok {
  31. assert.EqualValues(t, "rabbitmq.node.name-val", val.Str())
  32. }
  33. val, ok = res.Attributes().Get("rabbitmq.queue.name")
  34. assert.True(t, ok)
  35. if ok {
  36. assert.EqualValues(t, "rabbitmq.queue.name-val", val.Str())
  37. }
  38. val, ok = res.Attributes().Get("rabbitmq.vhost.name")
  39. assert.True(t, ok)
  40. if ok {
  41. assert.EqualValues(t, "rabbitmq.vhost.name-val", val.Str())
  42. }
  43. })
  44. }
  45. }