diff --git a/internal/utils/slices_test.go b/internal/utils/slices_test.go new file mode 100644 index 0000000..9f8cdc6 --- /dev/null +++ b/internal/utils/slices_test.go @@ -0,0 +1,60 @@ +package utils + +import ( + "reflect" + "testing" +) + +func TestGetOrDefault(t *testing.T) { + type args struct { + data map[string]any + key string + defaultVal any + } + tests := []struct { + name string + args args + want any + }{ + { + name: "Test 1: Nil map", + args: args{ + data: nil, + key: "key1", + defaultVal: "default", + }, + want: "default", + }, + { + name: "Test 2: Existing key", + args: args{ + data: map[string]interface{}{ + "key1": "value1", + "key2": "value2", + }, + key: "key1", + defaultVal: "default", + }, + want: "value1", + }, + { + name: "Test 3: Non-existing key", + args: args{ + data: map[string]interface{}{ + "key1": "value1", + "key2": "value2", + }, + key: "key3", + defaultVal: "default", + }, + want: "default", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetOrDefault(tt.args.data, tt.args.key, tt.args.defaultVal); !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetOrDefault() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index 7ce11d4..44654aa 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -40,6 +40,8 @@ func (p *postgresqlConnection) Connect(_ context.Context, config models.Database localSSL = "disable" } + p.debug = config.Debug + dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", config.Endpoint, config.Username, config.Password, config.Database, config.Port, localSSL, config.Timezone) var err error diff --git a/pkg/database/postgres_test.go b/pkg/database/postgres_test.go new file mode 100644 index 0000000..0249f43 --- /dev/null +++ b/pkg/database/postgres_test.go @@ -0,0 +1,26 @@ +package database + +import ( + "testing" +) + +func TestNewPostgresqlConnection(t *testing.T) { + // Test + tests := []struct { + name string + want OtterSpace + }{ + { + name: "Test 1: Create new postgresql connection", + want: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.want != NewPostgresqlConnection() { + } else { + t.Errorf("NewPostgresqlConnection() = %s", tt.want) + } + }) + } +} diff --git a/pkg/models/const_test.go b/pkg/models/const_test.go new file mode 100644 index 0000000..cba0f75 --- /dev/null +++ b/pkg/models/const_test.go @@ -0,0 +1,59 @@ +package models + +import ( + "reflect" + "testing" +) + +func TestRating_Convert(t *testing.T) { + type args struct { + e621Rating string + } + tests := []struct { + name string + r *Rating + args args + want Rating + }{ + { + name: "Test 1: NSFW Rating", + r: new(Rating), + args: args{ + e621Rating: "e", + }, + want: NSFW, + }, + { + name: "Test 2: Questionable Rating", + r: new(Rating), + args: args{ + e621Rating: "q", + }, + want: Questionable, + }, + { + name: "Test 3: SFW Rating", + r: new(Rating), + args: args{ + e621Rating: "s", + }, + want: SFW, + }, + { + name: "Test 4: Unknown Rating", + r: new(Rating), + args: args{ + e621Rating: "x", + }, + want: Unknown, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.r.Convert(tt.args.e621Rating) + if !reflect.DeepEqual(*tt.r, tt.want) { + t.Errorf("Convert() = %v, want %v", *tt.r, tt.want) + } + }) + } +}