package repository_ddb

import (
	"context"
	"dataservices/commons/config"
	"dataservices/ddb"
	"dataservices/internal/entity"
	"testing"
)

func TestListUserClusterByIDs(t *testing.T) {
	type args struct {
		clusterIds []uint64
	}
	tests := []struct {
		name    string
		args    args
		want    []*entity.UserClusterInfo
		wantErr bool
	}{
		{
			"OK",
			args{
				clusterIds: []uint64{1},
			},
			[]*entity.UserClusterInfo{
				{
					ClusterId: 1,
				},
			},
			false,
		},
	}
	ctx := context.Background()
	client, err := ddb.NewDynamodbClient(ctx, "us-west-2")
	if err != nil {
		t.Errorf("NewDynamodbClient() error = %v", err)
		return
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := ListUserClusterByIDs(ctx, client, tt.args.clusterIds)
			if (err != nil) != tt.wantErr {
				t.Errorf("ListUserClusterByIDs() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if got[0].ClusterId != tt.want[0].ClusterId {
				t.Errorf("ListUserClusterByIDs() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestGetUserClusterInfo(t *testing.T) {
	config.Global().ServerConf.Env = "dev"
	type args struct {
		projectId uint64
		clusterId uint64
	}
	tests := []struct {
		name    string
		args    args
		wantErr bool
	}{
		{
			"OK",
			args{
				1,
				2,
			},
			false,
		},
	}
	ctx := context.Background()
	cli, err := ddb.NewDynamodbClient(ctx, "us-west-2")
	if err != nil {
		t.Errorf("new ddb client failed, err: %v", err)
		return
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			_, err := GetUserClusterInfo(ctx, cli, tt.args.projectId, tt.args.clusterId)
			if (err != nil) != tt.wantErr {
				t.Errorf("GetUserClusterInfo() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
		})
	}
}
