package ghpkg

import "testing"

func Test_getResourcePool(t *testing.T) {
	type args struct {
		pools       []ResourcePoolItem
		planPath    string
		currentPool string
	}
	tests := []struct {
		name    string
		args    args
		want    string
		wantErr bool
	}{
		{
			name: "case_1",
			args: args{
				pools:       []ResourcePoolItem{{"transaction/", "transaction", ""}},
				planPath:    "transaction/utf-go-pessimistic-lock.yaml",
				currentPool: "default",
			},
			want:    "transaction",
			wantErr: false,
		},
		{
			name: "case_2",
			args: args{
				pools:       []ResourcePoolItem{{Path: "transaction/", ResourcePool: "transaction"}, {Path: "transaction/utf", Action: "KEEP"}},
				planPath:    "transaction/utf-go-pessimistic-lock.yaml",
				currentPool: "default",
			},
			want:    "default",
			wantErr: false,
		},
		{
			name: "case_3",
			args: args{
				pools:       []ResourcePoolItem{{ResourcePool: "default"}, {Path: "transaction/utf-py", Action: "KEEP"}},
				planPath:    "transaction/utf-go-pessimistic-lock.yaml",
				currentPool: "test-store",
			},
			want:    "default",
			wantErr: false,
		},
		{
			name: "case_4",
			args: args{
				pools:       []ResourcePoolItem{{ResourcePool: "default"}, {Path: "transaction/", Action: "KEEP"}},
				planPath:    "transaction/utf-go-pessimistic-lock.yaml",
				currentPool: "test-store",
			},
			want:    "test-store",
			wantErr: false,
		},
		{
			name: "case_5",
			args: args{
				pools:       []ResourcePoolItem{{ResourcePool: "default"}, {Path: "transaction/", Action: "OTHER"}},
				planPath:    "transaction/utf-go-pessimistic-lock.yaml",
				currentPool: "test-store",
			},
			wantErr: true,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := GetResourcePool(tt.args.pools, tt.args.planPath, tt.args.currentPool)
			if (err != nil) != tt.wantErr {
				t.Errorf("getResourcePool() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if got != tt.want {
				t.Errorf("getResourcePool() got = %v, want %v", got, tt.want)
			}
		})
	}
}
