From 54c22ee13bef0b062e2b15a3803bc7f4d1762756 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 18 Aug 2021 22:38:59 +0200 Subject: [PATCH] Add test for determining the container dumper type --- dump_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 dump_test.go diff --git a/dump_test.go b/dump_test.go new file mode 100644 index 0000000..288fad1 --- /dev/null +++ b/dump_test.go @@ -0,0 +1,40 @@ +package main + +import ( + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" + "reflect" + "testing" +) + +func TestNewDumperFromContainer(t *testing.T) { + tests := []struct { + name string + container *types.ContainerJSON + want string + }{ + { + name: "mysql", + container: &types.ContainerJSON{Config: &container.Config{Image: "mysql"}}, + want: "MysqlDumper", + }, + { + name: "mariadb", + container: &types.ContainerJSON{Config: &container.Config{Image: "mysql"}}, + want: "MysqlDumper", + }, + { + name: "postgres", + container: &types.ContainerJSON{Config: &container.Config{Image: "postgres"}}, + want: "PostgresDumper", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := NewDumperFromContainer(tt.container) + if reflect.TypeOf(got).Elem().Name() != tt.want { + t.Errorf("NewDumperFromContainer() is %s, want %s", got, tt.want) + } + }) + } +}