diff --git a/renderer/mock_generator_test.go b/renderer/mock_generator_test.go index ccf21814..5f084eee 100644 --- a/renderer/mock_generator_test.go +++ b/renderer/mock_generator_test.go @@ -412,11 +412,8 @@ properties: assert.Equal(t, "perhaps the best cyberpunk movie ever made.", m["description"].(string)) } -// Test schema rendering for property examples, regardless of whether the property -// is marked as required or not. -func TestMockGenerator_GenerateExamplesForAllProperties(t *testing.T) { - - yml := `type: object +func TestMockGenerator_GeneratePropertyExamples(t *testing.T) { + fake := createFakeMock(`type: object required: - id - name @@ -439,13 +436,40 @@ properties: items: type: string example: ["tag1", "tag2", "tag3"] -` +`, nil, nil) + + for name, tc := range map[string]struct { + mockGen func() *MockGenerator + expectedMock string + }{ + "All": { + mockGen: func() *MockGenerator { + mg := NewMockGenerator(JSON) + return mg + }, + expectedMock: `{"id":123,"name":"John Doe"}`, + }, + "OnlyRequired": { + mockGen: func() *MockGenerator { + mg := NewMockGenerator(JSON) - fake := createFakeMock(yml, nil, nil) - mg := NewMockGenerator(JSON) + // Test schema rendering for property examples, regardless of + // whether the property is marked as required or not. + mg.DisableRequiredCheck() - mock, err := mg.GenerateMock(fake, "") - require.NoError(t, err) + return mg + }, + expectedMock: `{"active":true,"balance":99.99,"id":123,"name":"John Doe","tags":["tag1","tag2","tag3"]}`, + }, + } { + tc := tc + t.Run(name, func(t *testing.T) { + t.Parallel() + + mock, err := tc.mockGen().GenerateMock(fake, "") + require.NoError(t, err) - assert.Equal(t, `{"active":true,"balance":99.99,"id":123,"name":"John Doe","tags":["tag1","tag2","tag3"]}`, string(mock)) + assert.Equal(t, tc.expectedMock, string(mock)) + }) + } }