Skip to content

Instantly share code, notes, and snippets.

@stevendborrelli
Last active January 21, 2022 17:49
Show Gist options
  • Save stevendborrelli/d3e5e5621792acc4027ca6c85c349275 to your computer and use it in GitHub Desktop.
Save stevendborrelli/d3e5e5621792acc4027ca6c85c349275 to your computer and use it in GitHub Desktop.
package topic
import (
"fmt"
"testing"
"github.com/crossplane-contrib/provider-kafka/apis/topic/v1alpha1"
"github.com/google/go-cmp/cmp"
)
func TestGenerate(t *testing.T) {
type args struct {
name string
params *v1alpha1.TopicParameters
}
type want struct {
topic *Topic
}
cases := map[string]struct {
args args
want want
}{
"FirstTest": {
args: args{
name: "k23",
params: &v1alpha1.TopicParameters{
ReplicationFactor: 1,
Partitions: 1,
Config: nil,
},
},
want: want{
&Topic{
Name: "k23",
ReplicationFactor: 1,
Partitions: 1,
Config: nil,
},
},
},
"SecondTestShouldFAIL": {
args: args{
name: "Notk23",
params: &v1alpha1.TopicParameters{
ReplicationFactor: 1,
Partitions: 1,
Config: nil,
},
},
want: want{
&Topic{
Name: "k23",
ReplicationFactor: 1,
Partitions: 1,
Config: nil,
},
},
},
}
for name, tt := range cases {
t.Run(name, func(t *testing.T) {
topic := Generate(tt.args.name, tt.args.params)
if diff := cmp.Diff(tt.want.topic, topic); diff != "" {
t.Errorf("Generate() = -want, +got:\n%s", diff)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment