generated_resource_test.go 948 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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.SetDatabase("database-val")
  13. res := rb.Emit()
  14. assert.Equal(t, 0, rb.Emit().Attributes().Len()) // Second call should return empty Resource
  15. switch test {
  16. case "default":
  17. assert.Equal(t, 1, res.Attributes().Len())
  18. case "all_set":
  19. assert.Equal(t, 1, res.Attributes().Len())
  20. case "none_set":
  21. assert.Equal(t, 0, res.Attributes().Len())
  22. return
  23. default:
  24. assert.Failf(t, "unexpected test case: %s", test)
  25. }
  26. val, ok := res.Attributes().Get("database")
  27. assert.True(t, ok)
  28. if ok {
  29. assert.EqualValues(t, "database-val", val.Str())
  30. }
  31. })
  32. }
  33. }