11package main
22
33import (
4+ "bytes"
45 "flag"
56 "io"
67 "os"
@@ -34,11 +35,6 @@ func TestAvroGen_RequiredFlags(t *testing.T) {
3435 args : []string {"avrogen" , "-o" , "some/file" , "schema.avsc" },
3536 wantErr : true ,
3637 },
37- {
38- name : "validates output file is set" ,
39- args : []string {"avrogen" , "-pkg" , "test" , "schema.avsc" },
40- wantErr : true ,
41- },
4238 {
4339 name : "validates tag format are valid" ,
4440 args : []string {"avrogen" , "-o" , "some/file" , "-pkg" , "test" , "-tags" , "snake" , "schema.avsc" },
@@ -59,7 +55,7 @@ func TestAvroGen_RequiredFlags(t *testing.T) {
5955 for _ , test := range tests {
6056 test := test
6157 t .Run (test .name , func (t * testing.T ) {
62- got := realMain (test .args , io .Discard )
58+ got := realMain (test .args , io .Discard , io . Discard )
6359
6460 if ! test .wantErr {
6561 assert .Equal (t , 0 , got )
@@ -71,14 +67,26 @@ func TestAvroGen_RequiredFlags(t *testing.T) {
7167 }
7268}
7369
70+ func TestAvroGen_GeneratesSchemaStdout (t * testing.T ) {
71+ var buf bytes.Buffer
72+
73+ args := []string {"avrogen" , "-pkg" , "testpkg" , "testdata/schema.avsc" }
74+ gotCode := realMain (args , io .Discard , & buf )
75+ require .Equal (t , 0 , gotCode )
76+
77+ want , err := os .ReadFile ("testdata/golden.go" )
78+ require .NoError (t , err )
79+ assert .Equal (t , want , buf .Bytes ())
80+ }
81+
7482func TestAvroGen_GeneratesSchema (t * testing.T ) {
7583 path , err := os .MkdirTemp ("./" , "avrogen" )
7684 require .NoError (t , err )
7785 t .Cleanup (func () { _ = os .RemoveAll (path ) })
7886
7987 file := filepath .Join (path , "test.go" )
8088 args := []string {"avrogen" , "-pkg" , "testpkg" , "-o" , file , "testdata/schema.avsc" }
81- gotCode := realMain (args , io .Discard )
89+ gotCode := realMain (args , io .Discard , io . Discard )
8290 require .Equal (t , 0 , gotCode )
8391
8492 got , err := os .ReadFile (file )
@@ -101,7 +109,7 @@ func TestAvroGen_GeneratesSchemaWithFullname(t *testing.T) {
101109
102110 file := filepath .Join (path , "test.go" )
103111 args := []string {"avrogen" , "-pkg" , "testpkg" , "-o" , file , "-fullname" , "testdata/schema.avsc" }
104- gotCode := realMain (args , io .Discard )
112+ gotCode := realMain (args , io .Discard , io . Discard )
105113 require .Equal (t , 0 , gotCode )
106114
107115 got , err := os .ReadFile (file )
@@ -124,7 +132,7 @@ func TestAvroGen_GeneratesSchemaWithEncoders(t *testing.T) {
124132
125133 file := filepath .Join (path , "test.go" )
126134 args := []string {"avrogen" , "-pkg" , "testpkg" , "-o" , file , "-encoders" , "testdata/schema.avsc" }
127- gotCode := realMain (args , io .Discard )
135+ gotCode := realMain (args , io .Discard , io . Discard )
128136 require .Equal (t , 0 , gotCode )
129137
130138 got , err := os .ReadFile (file )
0 commit comments