@@ -3,9 +3,11 @@ package store_test
33import (
44 "github.com/stretchr/testify/require"
55 "mokapi/engine/enginetest"
6+ "mokapi/kafka"
67 "mokapi/providers/asyncapi3"
78 "mokapi/providers/asyncapi3/asyncapi3test"
89 "mokapi/providers/asyncapi3/kafka/store"
10+ "mokapi/schema/json/schematest"
911 "testing"
1012)
1113
@@ -76,6 +78,60 @@ func TestStore(t *testing.T) {
7678 require .Error (t , err , "topic foo already exists" )
7779 },
7880 },
81+ {
82+ "update topic add partition" ,
83+ func (t * testing.T ) {
84+ s := store .New (asyncapi3test .NewConfig (asyncapi3test .WithChannel ("foo" , asyncapi3test .WithKafkaChannelBinding (asyncapi3.TopicBindings {Partitions : 1 }))), enginetest .NewEngine ())
85+ defer s .Close ()
86+
87+ s .Update (asyncapi3test .NewConfig (asyncapi3test .WithChannel ("foo" , asyncapi3test .WithKafkaChannelBinding (asyncapi3.TopicBindings {Partitions : 2 }))))
88+
89+ require .Len (t , s .Topic ("foo" ).Partitions , 2 )
90+ },
91+ },
92+ {
93+ "update topic remove partition" ,
94+ func (t * testing.T ) {
95+ s := store .New (asyncapi3test .NewConfig (asyncapi3test .WithChannel ("foo" , asyncapi3test .WithKafkaChannelBinding (asyncapi3.TopicBindings {Partitions : 2 }))), enginetest .NewEngine ())
96+ defer s .Close ()
97+
98+ s .Update (asyncapi3test .NewConfig (asyncapi3test .WithChannel ("foo" , asyncapi3test .WithKafkaChannelBinding (asyncapi3.TopicBindings {Partitions : 1 }))))
99+
100+ require .Len (t , s .Topic ("foo" ).Partitions , 1 )
101+ },
102+ },
103+ {
104+ "update topic change schema" ,
105+ func (t * testing.T ) {
106+ s := store .New (asyncapi3test .NewConfig (
107+ asyncapi3test .WithChannel ("foo" ,
108+ asyncapi3test .WithMessage ("foo" ,
109+ asyncapi3test .WithPayload (schematest .New ("integer" )),
110+ asyncapi3test .WithContentType ("application/json" ),
111+ ),
112+ )),
113+ enginetest .NewEngine ())
114+ defer s .Close ()
115+
116+ s .Update (asyncapi3test .NewConfig (
117+ asyncapi3test .WithChannel ("foo" ,
118+ asyncapi3test .WithMessage ("foo" ,
119+ asyncapi3test .WithPayload (schematest .New ("string" )),
120+ asyncapi3test .WithContentType ("application/json" ),
121+ ),
122+ ),
123+ ))
124+
125+ _ , _ , err := s .Topic ("foo" ).Partitions [0 ].Write (
126+ kafka.RecordBatch {Records : []* kafka.Record {
127+ {
128+ Value : kafka .NewBytes ([]byte ("123" )),
129+ },
130+ }},
131+ )
132+ require .EqualError (t , err , "validation error" )
133+ },
134+ },
79135 }
80136
81137 t .Parallel ()
0 commit comments